Skip to content

Commit 860c3d0

Browse files
Dan Carpentermartinkpetersen
authored andcommitted
scsi: scsi_debug: Fix some bugs in sdebug_error_write()
There are two bug in this code: 1) If count is zero, then it will lead to a NULL dereference. The kmalloc() will successfully allocate zero bytes and the test for "if (buf[0] == '-')" will read beyond the end of the zero size buffer and Oops. 2) The code does not ensure that the user's string is properly NUL terminated which could lead to a read overflow. Fixes: a9996d7 ("scsi: scsi_debug: Add interface to manage error injection for a single device") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/7733643d-e102-4581-8d29-769472011c97@moroto.mountain Reviewed-by: Wenchao Hao <haowenchao2@huawei.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 27900d7 commit 860c3d0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf,
10191019
struct sdebug_err_inject *inject;
10201020
struct scsi_device *sdev = (struct scsi_device *)file->f_inode->i_private;
10211021

1022-
buf = kmalloc(count, GFP_KERNEL);
1022+
buf = kzalloc(count + 1, GFP_KERNEL);
10231023
if (!buf)
10241024
return -ENOMEM;
10251025

0 commit comments

Comments
 (0)