Skip to contentSkip to conversation

vfio: ccw: fix bad ptr math for TIC cda translation

PATCH Applied Dong Jia Shi 2 participants 2 messages Jul 21, 2017 – Jul 24, 2017 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vfio: ccw: fix bad ptr math for TIC cda translation

From: "Jason J. Herne" <[email protected]>

When we are translating channel data addresses from guest to host address space for TIC instructions we are getting incorrect addresses because of a pointer arithmetic error.

We currently calculate the offset of the TIC's cda from the start of the channel program chain (ccw->cda - ccw_head). We then add that to the address of the ccw chain in host memory (iter->ch_ccw). The problem is that iter->ch_ccw is a pointer to struct ccw1 so when we increment it we are actually incrementing by the size of struct ccw1 which is 8 bytes. The intent was to increment by n-bytes, not n*8.

The fix: cast iter->ch_ccw to char* so it will be incremented by n*1.

---
 drivers/s390/cio/vfio_ccw_cp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/cio/vfio_ccw_cp.c +1 -1
index ba6ac83a6c25..5ccfdc80d0ec 100644
@@ -481,7 +481,7 @@ static int ccwchain_fetch_tic(struct ccwchain *chain,
 		ccw_tail = ccw_head + (iter->ch_len - 1) * sizeof(struct ccw1);
 
 		if ((ccw_head <= ccw->cda) && (ccw->cda <= ccw_tail)) {
-			ccw->cda = (__u32) (addr_t) (iter->ch_ccw +
+			ccw->cda = (__u32) (addr_t) (((char *)iter->ch_ccw) +
 						     (ccw->cda - ccw_head));
 			return 0;
 		}
Signature · 1 line
2.11.2
#2 lore raw
In reply to a message not in the archive
Quoted 35 lines · On Mon, 24 Jul 2017 15:10:53 +0800 Dong Jia Shi <[email protected]>…

* Dong Jia Shi <[email protected]> [2017-07-21 03:14:36 +0200]:

As Halil requested, add him into the loop.

Quoted 31 lines

From: "Jason J. Herne" <[email protected]>

When we are translating channel data addresses from guest to host address space for TIC instructions we are getting incorrect addresses because of a pointer arithmetic error.

We currently calculate the offset of the TIC's cda from the start of the channel program chain (ccw->cda - ccw_head). We then add that to the address of the ccw chain in host memory (iter->ch_ccw). The problem is that iter->ch_ccw is a pointer to struct ccw1 so when we increment it we are actually incrementing by the size of struct ccw1 which is 8 bytes. The intent was to increment by n-bytes, not n*8.

The fix: cast iter->ch_ccw to char* so it will be incremented by n*1.

---
 drivers/s390/cio/vfio_ccw_cp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/cio/vfio_ccw_cp.c +0 -0
index ba6ac83a6c25..5ccfdc80d0ec 100644
@@ -481,7 +481,7 @@ static int ccwchain_fetch_tic(struct ccwchain *chain,
 		ccw_tail = ccw_head + (iter->ch_len - 1) * sizeof(struct ccw1);
 
Quoted 6 lines

drivers/s390/cio/vfio_ccw_cp.c static int ccwchain_fetch_tic(struct ccwchain *chain, · line 487

Quoted 6 lines
drivers/s390/cio/vfio_ccw_cp.c +1 -1
 		if ((ccw_head <= ccw->cda) && (ccw->cda <= ccw_tail)) {
-			ccw->cda = (__u32) (addr_t) (iter->ch_ccw +
+			ccw->cda = (__u32) (addr_t) (((char *)iter->ch_ccw) +
 						     (ccw->cda - ccw_head));
 			return 0;
 		}

Thanks, applied.