Skip to content

Commit 0861407

Browse files
torvaldsTreehugger Robot
authored andcommitted
UPSTREAM: proc: proc_skip_spaces() shouldn't think it is working on C strings
commit bce9332220bd677d83b19d21502776ad555a0e73 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. Bug: 261488859 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> Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: Idda5e84344778ff8794bc21c981ba3da01e6a63b
1 parent 3cf3060 commit 0861407

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

kernel/sysctl.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,14 @@ int proc_dostring(struct ctl_table *table, int write,
379379
ppos);
380380
}
381381

382-
static size_t proc_skip_spaces(char **buf)
382+
static void proc_skip_spaces(char **buf, size_t *size)
383383
{
384-
size_t ret;
385-
char *tmp = skip_spaces(*buf);
386-
ret = tmp - *buf;
387-
*buf = tmp;
388-
return ret;
384+
while (*size) {
385+
if (!isspace(**buf))
386+
break;
387+
(*size)--;
388+
(*buf)++;
389+
}
389390
}
390391

391392
static void proc_skip_char(char **buf, size_t *size, const char v)
@@ -633,7 +634,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
633634
bool neg;
634635

635636
if (write) {
636-
left -= proc_skip_spaces(&p);
637+
proc_skip_spaces(&p, &left);
637638

638639
if (!left)
639640
break;
@@ -660,7 +661,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
660661
if (!write && !first && left && !err)
661662
proc_put_char(&buffer, &left, '\n');
662663
if (write && !err && left)
663-
left -= proc_skip_spaces(&p);
664+
proc_skip_spaces(&p, &left);
664665
if (write && first)
665666
return err ? : -EINVAL;
666667
*lenp -= left;
@@ -702,7 +703,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
702703
if (left > PAGE_SIZE - 1)
703704
left = PAGE_SIZE - 1;
704705

705-
left -= proc_skip_spaces(&p);
706+
proc_skip_spaces(&p, &left);
706707
if (!left) {
707708
err = -EINVAL;
708709
goto out_free;
@@ -722,7 +723,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
722723
}
723724

724725
if (!err && left)
725-
left -= proc_skip_spaces(&p);
726+
proc_skip_spaces(&p, &left);
726727

727728
out_free:
728729
if (err)
@@ -1259,7 +1260,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
12591260
if (write) {
12601261
bool neg;
12611262

1262-
left -= proc_skip_spaces(&p);
1263+
proc_skip_spaces(&p, &left);
12631264
if (!left)
12641265
break;
12651266

@@ -1287,7 +1288,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
12871288
if (!write && !first && left && !err)
12881289
proc_put_char(&buffer, &left, '\n');
12891290
if (write && !err)
1290-
left -= proc_skip_spaces(&p);
1291+
proc_skip_spaces(&p, &left);
12911292
if (write && first)
12921293
return err ? : -EINVAL;
12931294
*lenp -= left;

0 commit comments

Comments
 (0)