Skip to content

Commit 13d0cec

Browse files
minhbq-99martinkpetersen
authored andcommitted
scsi: bfa: Ensure the copied buf is NUL terminated
Currently, we allocate a nbytes-sized kernel buffer and copy nbytes from userspace to that buffer. Later, we use sscanf on this buffer but we don't ensure that the string is terminated inside the buffer, this can lead to OOB read when using sscanf. Fix this issue by using memdup_user_nul instead of memdup_user. Fixes: 9f30b67 ("bfa: replace 2 kzalloc/copy_from_user by memdup_user") Signed-off-by: Bui Quang Minh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent aca0617 commit 13d0cec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/scsi/bfa/bfad_debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
250250
unsigned long flags;
251251
void *kern_buf;
252252

253-
kern_buf = memdup_user(buf, nbytes);
253+
kern_buf = memdup_user_nul(buf, nbytes);
254254
if (IS_ERR(kern_buf))
255255
return PTR_ERR(kern_buf);
256256

@@ -317,7 +317,7 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
317317
unsigned long flags;
318318
void *kern_buf;
319319

320-
kern_buf = memdup_user(buf, nbytes);
320+
kern_buf = memdup_user_nul(buf, nbytes);
321321
if (IS_ERR(kern_buf))
322322
return PTR_ERR(kern_buf);
323323

0 commit comments

Comments
 (0)