Skip to content

Commit 8c34096

Browse files
minhbq-99kuba-moo
authored andcommitted
bna: 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: 7afc5db ("bna: Add debugfs interface.") Signed-off-by: Bui Quang Minh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 666854e commit 8c34096

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/ethernet/brocade/bna/bnad_debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ bnad_debugfs_write_regrd(struct file *file, const char __user *buf,
312312
void *kern_buf;
313313

314314
/* Copy the user space buf */
315-
kern_buf = memdup_user(buf, nbytes);
315+
kern_buf = memdup_user_nul(buf, nbytes);
316316
if (IS_ERR(kern_buf))
317317
return PTR_ERR(kern_buf);
318318

@@ -372,7 +372,7 @@ bnad_debugfs_write_regwr(struct file *file, const char __user *buf,
372372
void *kern_buf;
373373

374374
/* Copy the user space buf */
375-
kern_buf = memdup_user(buf, nbytes);
375+
kern_buf = memdup_user_nul(buf, nbytes);
376376
if (IS_ERR(kern_buf))
377377
return PTR_ERR(kern_buf);
378378

0 commit comments

Comments
 (0)