| Message ID | 20261104-work-procfs-fs-v2-23-319e0f9a8aae@kernel.org |
|---|---|
| State | New |
| Headers | show |
| Series | [RESEND,v2,01/30] jbd2: let procfs own the seq_file of the info file | expand |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dyndbg: split declaration and assignment of __free() in ddebug_proc_write() -- commit 1bfaabab91de2989a4d10ae03eef349ab77809d6 Author: Christian Brauner <brauner@kernel.org> dyndbg: let procfs copy in writes to /proc/dynamic_debug/control This commit factors the query execution logic out of ddebug_proc_write() into ddebug_proc_write_buf() and switches proc_fops to use .proc_write_buf and .proc_write_size so procfs copies in the user buffer before pinning the entry. > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c > index 64a2112908725..1d6012c9eb41f 100644 > --- a/lib/dynamic_debug.c > +++ b/lib/dynamic_debug.c > @@ -1002,11 +1002,28 @@ __setup("dyndbg=", dyndbg_setup); [ ... ] > static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, > size_t len, loff_t *offp) > { > - char *tmpbuf; > - int ret; > + char *tmpbuf __free(kfree) = NULL; > > if (len == 0) > return 0; > @@ -1017,15 +1034,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, > tmpbuf = memdup_user_nul(ubuf, len); > if (IS_ERR(tmpbuf)) > return PTR_ERR(tmpbuf); > - v2pr_info("read %zu bytes from userspace\n", len); > - > - ret = ddebug_exec_queries(tmpbuf, NULL); > - kfree(tmpbuf); > - if (ret < 0) > - return ret; > - > - *offp += len; > - return len; > + return ddebug_proc_write_buf(file, tmpbuf, len, offp); > } [Severity: Low] In ddebug_proc_write(), tmpbuf is declared with __free(kfree) = NULL at the top of the function before the early length checks and then assigned later via memdup_user_nul(). Per the cleanup.h guidelines, could tmpbuf be defined and initialized in a single statement at the allocation site instead: char *tmpbuf __free(kfree) = memdup_user_nul(ubuf, len);
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 64a211290872..1d6012c9eb41 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -1002,11 +1002,28 @@ __setup("dyndbg=", dyndbg_setup); * command text from userspace, parses and executes it. */ #define USER_BUF_PAGE 4096 + +static ssize_t ddebug_proc_write_buf(struct file *file, char *buf, size_t len, + loff_t *offp) +{ + int ret; + + if (len == 0) + return 0; + v2pr_info("read %zu bytes from userspace\n", len); + + ret = ddebug_exec_queries(buf, NULL); + if (ret < 0) + return ret; + + *offp += len; + return len; +} + static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, size_t len, loff_t *offp) { - char *tmpbuf; - int ret; + char *tmpbuf __free(kfree) = NULL; if (len == 0) return 0; @@ -1017,15 +1034,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, tmpbuf = memdup_user_nul(ubuf, len); if (IS_ERR(tmpbuf)) return PTR_ERR(tmpbuf); - v2pr_info("read %zu bytes from userspace\n", len); - - ret = ddebug_exec_queries(tmpbuf, NULL); - kfree(tmpbuf); - if (ret < 0) - return ret; - - *offp += len; - return len; + return ddebug_proc_write_buf(file, tmpbuf, len, offp); } /* @@ -1196,7 +1205,8 @@ static const struct file_operations ddebug_proc_fops = { static const struct proc_ops proc_fops = { .proc_seq_ops = &ddebug_proc_seqops, .proc_state_size = sizeof(struct ddebug_iter), - .proc_write = ddebug_proc_write + .proc_write_buf = ddebug_proc_write_buf, + .proc_write_size = USER_BUF_PAGE - 1, }; static void ddebug_attach_module_classes(struct ddebug_table *dt,
Move the parsing into ddebug_proc_write_buf() and implement ->proc_write_buf() with it so procfs copies in what is written before it pins the entry. The debugfs file keeps copying in itself. Writes larger than USER_BUF_PAGE - 1 bytes to the procfs file now fail with -EINVAL from procfs instead of -E2BIG, and without the "expected <4096 bytes into control" warning. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org> --- lib/dynamic_debug.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)