Skip to contentSkip to conversation

scsi: lpfc: Terminate string in lpfc_debugfs_nvmeio_trc_write()

PATCH Applied Dan Carpenter 4 participants 6 messages Dec 14, 2021 – Jan 7, 2022

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

PATCH 1/1 scsi: lpfc: Terminate string in lpfc_debugfs_nvmeio_trc_write()

The "mybuf" string comes from the user, so we need to ensure that it is NUL terminated.

Fixes bd2cdd5e400f ("scsi: lpfc: NVME Initiator: Add debugfs support")
---
 drivers/scsi/lpfc/lpfc_debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_debugfs.c +2 -2
index 21152c9a96ef..30fac2f6fb06 100644
@@ -2954,8 +2954,8 @@ lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
 	char mybuf[64];
 	char *pbuf;
 
-	if (nbytes > 64)
-		nbytes = 64;
+	if (nbytes > 63)
+		nbytes = 63;
 
 	memset(mybuf, 0, sizeof(mybuf));
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

The "mybuf" string comes from the user, so we need to ensure that it is NUL terminated.

Fixes bd2cdd5e400f ("scsi: lpfc: NVME Initiator: Add debugfs support")
---
  drivers/scsi/lpfc/lpfc_debugfs.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks Dan. Looks Good.

-- james

#4 lore raw
In reply to Dan Carpenter
Quoted 16 lines · Dan Carpenter

The "mybuf" string comes from the user, so we need to ensure that it is NUL terminated.

Fixes bd2cdd5e400f ("scsi: lpfc: NVME Initiator: Add debugfs

support")

---
 drivers/scsi/lpfc/lpfc_debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_debugfs.c +0 -0
index 21152c9a96ef..30fac2f6fb06 100644

drivers/scsi/lpfc/lpfc_debugfs.c lpfc_debugfs_nvmeio_trc_write(struct file · line 2959

Quoted 8 lines
drivers/scsi/lpfc/lpfc_debugfs.c +2 -2
@@ -2954,8 +2954,8 @@ lpfc_debugfs_nvmeio_trc_write(struct file
 *file, const char __user *buf,
 	char mybuf[64];
 	char *pbuf;
 
-	if (nbytes > 64)
-		nbytes = 64;
+	if (nbytes > 63)
+		nbytes = 63;

Just for future reference, next time could we do

if (nbytes > sizeof(mybuf) - 1)

        nbytes = sizeof(mybuf) - 1;

just so we minimize the possibility of screw ups in the unlikely event that someone reduces the size of the mybuf array?

James

#5 lore raw
Quoted 28 lines · James Bottomley
Quoted 16 lines · Dan Carpenter

The "mybuf" string comes from the user, so we need to ensure that it is NUL terminated.

Fixes bd2cdd5e400f ("scsi: lpfc: NVME Initiator: Add debugfs

support")

---
 drivers/scsi/lpfc/lpfc_debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_debugfs.c +0 -0
index 21152c9a96ef..30fac2f6fb06 100644

drivers/scsi/lpfc/lpfc_debugfs.c lpfc_debugfs_nvmeio_trc_write(struct file · line 2959

Quoted 8 lines
drivers/scsi/lpfc/lpfc_debugfs.c +2 -2
@@ -2954,8 +2954,8 @@ lpfc_debugfs_nvmeio_trc_write(struct file
 *file, const char __user *buf,
 	char mybuf[64];
 	char *pbuf;
 
-	if (nbytes > 64)
-		nbytes = 64;
+	if (nbytes > 63)
+		nbytes = 63;

Just for future reference, next time could we do

Quoted 5 lines

if (nbytes > sizeof(mybuf) - 1)

        nbytes = sizeof(mybuf) - 1;

just so we minimize the possibility of screw ups in the unlikely event that someone reduces the size of the mybuf array?

Yeah. Good point. Will do that next time.

regards,
dan carpenter