Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cffda199 authored by Linus Torvalds's avatar Linus Torvalds Committed by Lee Jones
Browse files

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: default avatarKyle Zeng <zengyhkyle@gmail.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarLee Jones <joneslee@google.com>
Change-Id: Ie21bf20f3b92b78c5f31093b354a77b4133810e7
Signed-off-by: default avatarLee Jones <joneslee@google.com>
parent e418b27c
Loading
Loading
Loading
Loading
+13 −12
Original line number Original line Diff line number Diff line
@@ -2165,13 +2165,14 @@ int proc_dostring(struct ctl_table *table, int write,
			       (char __user *)buffer, lenp, ppos);
			       (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;
	while (*size) {
	char *tmp = skip_spaces(*buf);
		if (!isspace(**buf))
	ret = tmp - *buf;
			break;
	*buf = tmp;
		(*size)--;
	return ret;
		(*buf)++;
	}
}
}


static void proc_skip_char(char **buf, size_t *size, const char v)
static void proc_skip_char(char **buf, size_t *size, const char v)
@@ -2409,7 +2410,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
		bool neg;
		bool neg;


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


			if (!left)
			if (!left)
				break;
				break;
@@ -2440,7 +2441,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
	if (!write && !first && left && !err)
	if (!write && !first && left && !err)
		err = proc_put_char(&buffer, &left, '\n');
		err = proc_put_char(&buffer, &left, '\n');
	if (write && !err && left)
	if (write && !err && left)
		left -= proc_skip_spaces(&p);
		proc_skip_spaces(&p, &left);
	if (write) {
	if (write) {
		kfree(kbuf);
		kfree(kbuf);
		if (first)
		if (first)
@@ -2489,7 +2490,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
	if (IS_ERR(kbuf))
	if (IS_ERR(kbuf))
		return -EINVAL;
		return -EINVAL;


	left -= proc_skip_spaces(&p);
	proc_skip_spaces(&p, &left);
	if (!left) {
	if (!left) {
		err = -EINVAL;
		err = -EINVAL;
		goto out_free;
		goto out_free;
@@ -2509,7 +2510,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
	}
	}


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


out_free:
out_free:
	kfree(kbuf);
	kfree(kbuf);
@@ -2923,7 +2924,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
		if (write) {
		if (write) {
			bool neg;
			bool neg;


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


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