Skip to contentSkip to conversation

s390/dasd: fix out of bound access and other fixes

PATCH Applied Stefan Haberland 2 participants 6 messages Nov 23, 2022

Subsystems (3)
lore
Share & tools
lore

Stefan Haberland

author maintainer
#0 lore raw

cover s390/dasd: fix out of bound access and other fixes

Hi Jens,

please apply the following patches that:

- fix an out of bound access
- fix a possible IO error on non-IBM storage
- fix a typo
- improve debug data for error scenarios

regards,
Stefan

Colin Ian King (1):
s390/dasd: Fix spelling mistake "Ivalid" -> "Invalid"

Stefan Haberland (3):
s390/dasd: increase printing of debug data payload s390/dasd: fix no record found for raw_track_access s390/dasd: fix possible buffer overflow in copy_pair_show

 drivers/s390/block/dasd_devmap.c |  2 +-
 drivers/s390/block/dasd_eckd.c   | 43 ++++++++++++++++----------------
 drivers/s390/block/dasd_ioctl.c  |  2 +-
 3 files changed, 23 insertions(+), 24 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/4 s390/dasd: Fix spelling mistake "Ivalid" -> "Invalid"

From: Colin Ian King <[email protected]>

There is a spelling mistake in a pr_warn message. Fix it.

---
 drivers/s390/block/dasd_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/block/dasd_ioctl.c +1 -1
index d0ddf2cc9786..9327dcdd6e5e 100644
@@ -401,7 +401,7 @@ dasd_ioctl_copy_pair_swap(struct block_device *bdev, void __user *argp)
 		return -EFAULT;
 	}
 	if (memchr_inv(data.reserved, 0, sizeof(data.reserved))) {
-		pr_warn("%s: Ivalid swap data specified.\n",
+		pr_warn("%s: Invalid swap data specified\n",
 			dev_name(&device->cdev->dev));
 		dasd_put_device(device);
 		return DASD_COPYPAIRSWAP_INVALID;
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/4 s390/dasd: increase printing of debug data payload

In reply to Stefan Haberland

32 byte are to less for important data from prefix or other commands.
Print up to 128 byte data. This is enough for the largest CCW data we have.

Since printk can only print up to 1024 byte at once, print the different parts of the CCW dumps separately.

---
 drivers/s390/block/dasd_eckd.c | 37 +++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/s390/block/dasd_eckd.c +19 -18
index 662730f3b027..85bf045c2ff9 100644
@@ -5500,7 +5500,7 @@ dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
  * Dump the range of CCWs into 'page' buffer
  * and return number of printed chars.
  */
-static int
+static void
 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
 {
 	int len, count;
@@ -5518,16 +5518,21 @@ dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
 		else
 			datap = (char *) ((addr_t) from->cda);
 
-		/* dump data (max 32 bytes) */
-		for (count = 0; count < from->count && count < 32; count++) {
-			if (count % 8 == 0) len += sprintf(page + len, " ");
-			if (count % 4 == 0) len += sprintf(page + len, " ");
+		/* dump data (max 128 bytes) */
+		for (count = 0; count < from->count && count < 128; count++) {
+			if (count % 32 == 0)
+				len += sprintf(page + len, "\n");
+			if (count % 8 == 0)
+				len += sprintf(page + len, " ");
+			if (count % 4 == 0)
+				len += sprintf(page + len, " ");
 			len += sprintf(page + len, "%02x", datap[count]);
 		}
 		len += sprintf(page + len, "\n");
 		from++;
 	}
-	return len;
+	if (len > 0)
+		printk(KERN_ERR "%s", page);
 }
 
 static void
@@ -5619,37 +5624,33 @@ static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
 	if (req) {
 		/* req == NULL for unsolicited interrupts */
 		/* dump the Channel Program (max 140 Bytes per line) */
-		/* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
+		/* Count CCW and print first CCWs (maximum 7) */
 		first = req->cpaddr;
 		for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
 		to = min(first + 6, last);
-		len = sprintf(page, PRINTK_HEADER
-			      " Related CP in req: %p\n", req);
-		dasd_eckd_dump_ccw_range(first, to, page + len);
-		printk(KERN_ERR "%s", page);
+		printk(KERN_ERR PRINTK_HEADER " Related CP in req: %p\n", req);
+		dasd_eckd_dump_ccw_range(first, to, page);
 
 		/* print failing CCW area (maximum 4) */
 		/* scsw->cda is either valid or zero  */
-		len = 0;
 		from = ++to;
 		fail = (struct ccw1 *)(addr_t)
 				irb->scsw.cmd.cpa; /* failing CCW */
 		if (from <  fail - 2) {
 			from = fail - 2;     /* there is a gap - print header */
-			len += sprintf(page, PRINTK_HEADER "......\n");
+			printk(KERN_ERR PRINTK_HEADER "......\n");
 		}
 		to = min(fail + 1, last);
-		len += dasd_eckd_dump_ccw_range(from, to, page + len);
+		dasd_eckd_dump_ccw_range(from, to, page + len);
 
 		/* print last CCWs (maximum 2) */
+		len = 0;
 		from = max(from, ++to);
 		if (from < last - 1) {
 			from = last - 1;     /* there is a gap - print header */
-			len += sprintf(page + len, PRINTK_HEADER "......\n");
+			printk(KERN_ERR PRINTK_HEADER "......\n");
 		}
-		len += dasd_eckd_dump_ccw_range(from, last, page + len);
-		if (len > 0)
-			printk(KERN_ERR "%s", page);
+		dasd_eckd_dump_ccw_range(from, last, page + len);
 	}
 	free_page((unsigned long) page);
 }
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/4 s390/dasd: fix no record found for raw_track_access

In reply to Stefan Haberland

For DASD devices in raw_track_access mode only full track images are read and written.
For this purpose it is not necessary to do search operation in the locate record extended function. The documentation even states that this might fail if the searched record is not found on a track.

Currently the driver sets a value of 1 in the search field for the first record after record zero. This is the default for disks not in raw_track_access mode but record 1 might be missing on a completely empty track.

There has not been any problem with this on IBM storage servers but it might lead to errors with DASD devices on other vendors storage servers.

Fix this by setting the search field to 0. Record zero is always available even on a completely empty track.

Fixes e4dbb0f2b5dd ("[S390] dasd: Add support for raw ECKD access.")
---
 drivers/s390/block/dasd_eckd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/s390/block/dasd_eckd.c +2 -4
index 85bf045c2ff9..5d0b9991e91a 100644
@@ -4722,7 +4722,6 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_raw(struct dasd_device *startdev,
 	struct dasd_device *basedev;
 	struct req_iterator iter;
 	struct dasd_ccw_req *cqr;
-	unsigned int first_offs;
 	unsigned int trkcount;
 	unsigned long *idaws;
 	unsigned int size;
@@ -4756,7 +4755,6 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_raw(struct dasd_device *startdev,
 	last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
 		DASD_RAW_SECTORS_PER_TRACK;
 	trkcount = last_trk - first_trk + 1;
-	first_offs = 0;
 
 	if (rq_data_dir(req) == READ)
 		cmd = DASD_ECKD_CCW_READ_TRACK;
@@ -4800,13 +4798,13 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_raw(struct dasd_device *startdev,
 
 	if (use_prefix) {
 		prefix_LRE(ccw++, data, first_trk, last_trk, cmd, basedev,
-			   startdev, 1, first_offs + 1, trkcount, 0, 0);
+			   startdev, 1, 0, trkcount, 0, 0);
 	} else {
 		define_extent(ccw++, data, first_trk, last_trk, cmd, basedev, 0);
 		ccw[-1].flags |= CCW_FLAG_CC;
 
 		data += sizeof(struct DE_eckd_data);
-		locate_record_ext(ccw++, data, first_trk, first_offs + 1,
+		locate_record_ext(ccw++, data, first_trk, 0,
 				  trkcount, cmd, basedev, 0, 0);
 	}
 
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 4/4 s390/dasd: fix possible buffer overflow in copy_pair_show

In reply to Stefan Haberland

dasd_copy_relation->entry[] array might be accessed out of bounds if the loop does not break.

Fixes a91ff09d39f9 ("s390/dasd: add copy pair setup")
---
 drivers/s390/block/dasd_devmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/block/dasd_devmap.c +1 -1
index cb83f81da416..df17f0f9cb0f 100644
@@ -1954,7 +1954,7 @@ dasd_copy_pair_show(struct device *dev,
 			break;
 		}
 	}
-	if (!copy->entry[i].primary)
+	if (i == DASD_CP_ENTRIES)
 		goto out;
 
 	/* print all secondary */
Signature · 1 line
2.34.1
maintainer Applied
#5 lore raw
In reply to Stefan Haberland
Quoted 8 lines · Stefan Haberland

please apply the following patches that:

- fix an out of bound access
- fix a possible IO error on non-IBM storage
- fix a typo
- improve debug data for error scenarios

[...]

Applied, thanks!

[1/4] s390/dasd: Fix spelling mistake "Ivalid" -> "Invalid"

      commit: 4ba5f0c36cfdda68347269c02961cd90f8443ace
[2/4] s390/dasd: increase printing of debug data payload
      commit: b49e648fcca7e420c4ad670a548e19f0e8531c30
[3/4] s390/dasd: fix no record found for raw_track_access
      commit: 590ce6d96d6a224b470a3862c33a483d5022bfdb
[4/4] s390/dasd: fix possible buffer overflow in copy_pair_show
      commit: 7e8a05b47ba7200f333eefd19979eeb4d273ceec

Best regards,

Signature · 1 line
Jens Axboe