mirror of
https://github.com/torvalds/linux.git
synced 2024-12-01 16:41:39 +00:00
Merge branch 'ensure-the-copied-buf-is-nul-terminated'
Bui Quang Minh says: ==================== Ensure the copied buf is NUL terminated (part) I found that some drivers contains an out-of-bound read pattern like this kern_buf = memdup_user(user_buf, count); ... sscanf(kern_buf, ...); The sscanf can be replaced by some other string-related functions. This pattern can lead to out-of-bound read of kern_buf in string-related functions. This series fix the above issue by replacing memdup_user with memdup_user_nul. v1: https://lore.kernel.org/r/20240422-fix-oob-read-v1-0-e02854c30174@gmail.com ==================== Link: https://lore.kernel.org/r/20240424-fix-oob-read-v2-0-f1f1b53a10f4@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
a5b1051ad5
@ -312,7 +312,7 @@ bnad_debugfs_write_regrd(struct file *file, const char __user *buf,
|
||||
void *kern_buf;
|
||||
|
||||
/* Copy the user space buf */
|
||||
kern_buf = memdup_user(buf, nbytes);
|
||||
kern_buf = memdup_user_nul(buf, nbytes);
|
||||
if (IS_ERR(kern_buf))
|
||||
return PTR_ERR(kern_buf);
|
||||
|
||||
@ -372,7 +372,7 @@ bnad_debugfs_write_regwr(struct file *file, const char __user *buf,
|
||||
void *kern_buf;
|
||||
|
||||
/* Copy the user space buf */
|
||||
kern_buf = memdup_user(buf, nbytes);
|
||||
kern_buf = memdup_user_nul(buf, nbytes);
|
||||
if (IS_ERR(kern_buf))
|
||||
return PTR_ERR(kern_buf);
|
||||
|
||||
|
@ -171,7 +171,7 @@ ice_debugfs_module_write(struct file *filp, const char __user *buf,
|
||||
if (*ppos != 0 || count > 8)
|
||||
return -EINVAL;
|
||||
|
||||
cmd_buf = memdup_user(buf, count);
|
||||
cmd_buf = memdup_user_nul(buf, count);
|
||||
if (IS_ERR(cmd_buf))
|
||||
return PTR_ERR(cmd_buf);
|
||||
|
||||
@ -257,7 +257,7 @@ ice_debugfs_nr_messages_write(struct file *filp, const char __user *buf,
|
||||
if (*ppos != 0 || count > 4)
|
||||
return -EINVAL;
|
||||
|
||||
cmd_buf = memdup_user(buf, count);
|
||||
cmd_buf = memdup_user_nul(buf, count);
|
||||
if (IS_ERR(cmd_buf))
|
||||
return PTR_ERR(cmd_buf);
|
||||
|
||||
@ -332,7 +332,7 @@ ice_debugfs_enable_write(struct file *filp, const char __user *buf,
|
||||
if (*ppos != 0 || count > 2)
|
||||
return -EINVAL;
|
||||
|
||||
cmd_buf = memdup_user(buf, count);
|
||||
cmd_buf = memdup_user_nul(buf, count);
|
||||
if (IS_ERR(cmd_buf))
|
||||
return PTR_ERR(cmd_buf);
|
||||
|
||||
@ -428,7 +428,7 @@ ice_debugfs_log_size_write(struct file *filp, const char __user *buf,
|
||||
if (*ppos != 0 || count > 5)
|
||||
return -EINVAL;
|
||||
|
||||
cmd_buf = memdup_user(buf, count);
|
||||
cmd_buf = memdup_user_nul(buf, count);
|
||||
if (IS_ERR(cmd_buf))
|
||||
return PTR_ERR(cmd_buf);
|
||||
|
||||
|
@ -999,12 +999,10 @@ static ssize_t rvu_dbg_qsize_write(struct file *filp,
|
||||
u16 pcifunc;
|
||||
int ret, lf;
|
||||
|
||||
cmd_buf = memdup_user(buffer, count + 1);
|
||||
cmd_buf = memdup_user_nul(buffer, count);
|
||||
if (IS_ERR(cmd_buf))
|
||||
return -ENOMEM;
|
||||
|
||||
cmd_buf[count] = '\0';
|
||||
|
||||
cmd_buf_tmp = strchr(cmd_buf, '\n');
|
||||
if (cmd_buf_tmp) {
|
||||
*cmd_buf_tmp = '\0';
|
||||
|
Loading…
Reference in New Issue
Block a user