Skip to contentSkip to conversation

proc_dointvec() and write

PATCH In review J. R. Okajima 4 participants 8 messages May 24, 2010 – May 30, 2010 Proc sysctl

lore
Share & tools
lore
#0 lore raw

The commit 00b7c3395aec3df43de5bd02a3c5a099ca51169f "sysctl: refactor integer handling proc code" modified the behaviour of writing to /proc.

Before the commit, write("1\n") to /proc/sys/kernel/printk succeeded. But now it returns EINVAL. Is this intended change? If not, how about this patch?

J. R. Okajima

kernel/sysctl.c +3 -1
index 4c93486..5058e12 100644
@@ -2262,6 +2272,8 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
 		if (write) {
 			left -= proc_skip_spaces(&kbuf);
 
+			if (!left)
+				break;
 			err = proc_get_long(&kbuf, &left, &lval, &neg,
 					     proc_wspace_sep,
 					     sizeof(proc_wspace_sep), NULL);
@@ -2288,7 +2306,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)
+	if (write && !err && left)
 		left -= proc_skip_spaces(&kbuf);
 free:
 	if (write) {
#1 lore raw
Quoted 8 lines · J. R. Okajima

The commit 00b7c3395aec3df43de5bd02a3c5a099ca51169f "sysctl: refactor integer handling proc code" modified the behaviour of writing to /proc.

Before the commit, write("1\n") to /proc/sys/kernel/printk succeeded. But now it returns EINVAL. Is this intended change? If not, how about this patch?

Hmm, odd, I tested other proc files, I see no problem. I am wondering why /proc/sys/kernel/printk is special here.

I will be back later.

Quoted 26 lines

J. R. Okajima

kernel/sysctl.c +3 -1
index 4c93486..5058e12 100644
@@ -2262,6 +2272,8 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  		if (write) {
  			left -= proc_skip_spaces(&kbuf);
 
+			if (!left)
+				break;
  			err = proc_get_long(&kbuf,&left,&lval,&neg,
  					     proc_wspace_sep,
  					     sizeof(proc_wspace_sep), NULL);
@@ -2288,7 +2306,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)
+	if (write&&  !err&&  left)
  		left -= proc_skip_spaces(&kbuf);
  free:
  	if (write) {
#2 lore raw

Cong Wang:

Quoted 2 lines

Hmm, odd, I tested other proc files, I see no problem. I am wondering why /proc/sys/kernel/printk is special here.

The condition is,
- the entry has multiple values, .maxlen = N * sizeof(foo)
- the entry is writable, .mode = 0644 (or something)

In sysctl.c, only "printk" and "acct" match.

J. R. Okajima

#3 lore raw
Quoted 9 lines · J. R. Okajima

Cong Wang:

Quoted 2 lines

Hmm, odd, I tested other proc files, I see no problem. I am wondering why /proc/sys/kernel/printk is special here.

The condition is,
- the entry has multiple values, .maxlen = N * sizeof(foo)
- the entry is writable, .mode = 0644 (or something)

In sysctl.c, only "printk" and "acct" match.

Hmm, right, I missed this case during testing.

Your patch looks correct for me. Would you mind to send your patch again with your Signed-off-by?

Thank you!

#4 lore raw

PATCH 1/1 proc_dointvec, write a single value

The commit 00b7c3395aec3df43de5bd02a3c5a099ca51169f
"sysctl: refactor integer handling proc code"
modified the behaviour of writing to /proc.
Before the commit, write("1\n") to /proc/sys/kernel/printk succeeded. But now it returns EINVAL.

This commit supports writing a single value to a multi-valued entry.

---
 kernel/sysctl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
kernel/sysctl.c +3 -1
index 4c93486..78ac3fb 100644
@@ -2262,6 +2262,8 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
 		if (write) {
 			left -= proc_skip_spaces(&kbuf);
 
+			if (!left)
+				break;
 			err = proc_get_long(&kbuf, &left, &lval, &neg,
 					     proc_wspace_sep,
 					     sizeof(proc_wspace_sep), NULL);
@@ -2288,7 +2290,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)
+	if (write && !err && left)
 		left -= proc_skip_spaces(&kbuf);
 free:
 	if (write) {
Signature · 1 line
1.6.6.1
#5 lore raw

Re: [PATCH] proc_dointvec, write a single value

Quoted 9 lines · J. R. Okajima

The commit 00b7c3395aec3df43de5bd02a3c5a099ca51169f
"sysctl: refactor integer handling proc code"
modified the behaviour of writing to /proc.
Before the commit, write("1\n") to /proc/sys/kernel/printk succeeded. But now it returns EINVAL.

This commit supports writing a single value to a multi-valued entry.

Reviewed-and-tested-by WANG Cong <[email protected]>

Thanks a lot!

Quoted 26 lines
---
  kernel/sysctl.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
kernel/sysctl.c +3 -1
index 4c93486..78ac3fb 100644
@@ -2262,6 +2262,8 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  		if (write) {
  			left -= proc_skip_spaces(&kbuf);
 
+			if (!left)
+				break;
  			err = proc_get_long(&kbuf,&left,&lval,&neg,
  					     proc_wspace_sep,
  					     sizeof(proc_wspace_sep), NULL);
@@ -2288,7 +2290,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)
+	if (write&&  !err&&  left)
  		left -= proc_skip_spaces(&kbuf);
  free:
  	if (write) {
#6 lore raw

Re: [PATCH] proc_dointvec, write a single value

From: Cong Wang <[email protected]>
Date: Tue, 25 May 2010 20:23:47 +0800

Quoted 8 lines · J. R. Okajima
Quoted 7 lines

The commit 00b7c3395aec3df43de5bd02a3c5a099ca51169f "sysctl: refactor integer handling proc code" modified the behaviour of writing to /proc. Before the commit, write("1\n") to /proc/sys/kernel/printk succeeded. But
now it returns EINVAL.

Quoted 5 lines
Quoted 3 lines

This commit supports writing a single value to a multi-valued entry.

Reviewed-and-tested-by WANG Cong <[email protected]>

Since the regression causing change came in via the net tree I'll integrate this fix too, applied, thanks!

#7 lore raw

Re: [PATCH] proc_dointvec, write a single value

Quoted 11 lines · David Miller

From: Cong Wang <[email protected]>
Date: Tue, 25 May 2010 20:23:47 +0800

Quoted 8 lines · J. R. Okajima
Quoted 7 lines

The commit 00b7c3395aec3df43de5bd02a3c5a099ca51169f "sysctl: refactor integer handling proc code" modified the behaviour of writing to /proc. Before the commit, write("1\n") to /proc/sys/kernel/printk succeeded. But
now it returns EINVAL.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

This commit supports writing a single value to a multi-valued entry.

Reviewed-and-tested-by WANG Cong <[email protected]>

Since the regression causing change came in via the net tree I'll integrate this fix too, applied, thanks!

Thanks, guys for fixing this.

I hate to see my review comments show up like this in practice. I had really hoped those unnecessary changes to proc would have been dropped from that patchset. Oh well.

Eric