Skip to content

Commit

Permalink
proc: proc_skip_spaces() shouldn't think it is working on C strings
Browse files Browse the repository at this point in the history
commit bce9332 upstream.

proc_skip_spaces() seems to think it is working on C strings, and ends
up being just a wrapper around skip_spaces() with a really odd calling
convention.

Instead of basing it on skip_spaces(), it should have looked more like
proc_skip_char(), which really is the exact same function (except it
skips a particular character, rather than whitespace).  So use that as
inspiration, odd coding and all.

Now the calling convention actually makes sense and works for the
intended purpose.

Reported-and-tested-by: Kyle Zeng <zengyhkyle@gmail.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Linus Torvalds authored and Greg Kroah-Hartman committed Dec 8, 2022
1 parent 3264621 commit 6e3644a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2041,13 +2041,14 @@ int proc_dostring(struct ctl_table *table, int write,
(char __user *)buffer, lenp, ppos);
}

static size_t proc_skip_spaces(char **buf)
static void proc_skip_spaces(char **buf, size_t *size)
{
size_t ret;
char *tmp = skip_spaces(*buf);
ret = tmp - *buf;
*buf = tmp;
return ret;
while (*size) {
if (!isspace(**buf))
break;
(*size)--;
(*buf)++;
}
}

static void proc_skip_char(char **buf, size_t *size, const char v)
Expand Down Expand Up @@ -2260,7 +2261,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
bool neg;

if (write) {
left -= proc_skip_spaces(&p);
proc_skip_spaces(&p, &left);

if (!left)
break;
Expand Down Expand Up @@ -2291,7 +2292,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
if (!write && !first && left && !err)
err = proc_put_char(&buffer, &left, '\n');
if (write && !err && left)
left -= proc_skip_spaces(&p);
proc_skip_spaces(&p, &left);
if (write) {
kfree(kbuf);
if (first)
Expand Down Expand Up @@ -2543,7 +2544,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
if (write) {
bool neg;

left -= proc_skip_spaces(&p);
proc_skip_spaces(&p, &left);
if (!left)
break;

Expand Down Expand Up @@ -2576,7 +2577,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
if (!write && !first && left && !err)
err = proc_put_char(&buffer, &left, '\n');
if (write && !err)
left -= proc_skip_spaces(&p);
proc_skip_spaces(&p, &left);
if (write) {
kfree(kbuf);
if (first)
Expand Down

0 comments on commit 6e3644a

Please sign in to comment.