Skip to contentSkip to conversation

proc: Report file name on detected read_proc overflow

PATCH Superseded Jan Kiszka 3 participants 5 messages Apr 1, 2010 – Apr 6, 2010 Proc filesystem

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 proc: Report file name on detected read_proc overflow

This can help identifying the buggy read_proc handler.

---
 fs/proc/generic.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
fs/proc/generic.c +9 -3
index 08f4d71..cc7e671 100644
@@ -132,7 +132,9 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
 		if (start == NULL) {
 			if (n > PAGE_SIZE) {
 				printk(KERN_ERR
-				       "proc_file_read: Apparent buffer overflow!\n");
+				       "proc_file_read: Apparent buffer "
+				       "overflow reading \"%s\"!\n",
+				       file->f_path.dentry->d_name.name);
 				n = PAGE_SIZE;
 			}
 			n -= *ppos;
@@ -144,7 +146,9 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
 		} else if (start < page) {
 			if (n > PAGE_SIZE) {
 				printk(KERN_ERR
-				       "proc_file_read: Apparent buffer overflow!\n");
+				       "proc_file_read: Apparent buffer "
+				       "overflow reading \"%s\"!\n",
+				       file->f_path.dentry->d_name.name);
 				n = PAGE_SIZE;
 			}
 			if (n > count) {
@@ -159,7 +163,9 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
 			unsigned long startoff = (unsigned long)(start - page);
 			if (n > (PAGE_SIZE - startoff)) {
 				printk(KERN_ERR
-				       "proc_file_read: Apparent buffer overflow!\n");
+				       "proc_file_read: Apparent buffer "
+				       "overflow reading \"%s\"!\n",
+				       file->f_path.dentry->d_name.name);
 				n = PAGE_SIZE - startoff;
 			}
 			if (n > count)
#1 lore raw

fs/proc/generic.c __proc_file_read(struct file *file, char __user *buf, size_t nbytes, · line 137

Quoted 4 lines · Jan Kiszka
fs/proc/generic.c +3 -1
-                                      "proc_file_read: Apparent buffer overflow!\n");
+                                      "proc_file_read: Apparent buffer "
+                                      "overflow reading \"%s\"!\n",
+                                      file->f_path.dentry->d_name.name);

I think it would be good to keep "overflow" on the first line as that may be what people will grep the source for. And maybe use single quotes around the file name. So:

+                                      "proc_file_read: Apparent buffer overflow "
+                                      "reading '%s'!\n",
+                                      file->f_path.dentry->d_name.name);

Cheers,
FJP

author
#2 lore raw

PATCH v2 1/1 proc: Report file name on detected read_proc overflow

This can help identifying the buggy read_proc handler.

---
 fs/proc/generic.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

changes in v2:
- keep "Apparent buffer overflow" in the same source code line
- quote the file name with ''

(Thanks, Frans!)

fs/proc/generic.c +9 -3
index 08f4d71..ce14eca 100644
@@ -132,7 +132,9 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
 		if (start == NULL) {
 			if (n > PAGE_SIZE) {
 				printk(KERN_ERR
-				       "proc_file_read: Apparent buffer overflow!\n");
+				       "proc_file_read: Apparent buffer overflow"
+				       " reading '%s'!\n",
+				       file->f_path.dentry->d_name.name);
 				n = PAGE_SIZE;
 			}
 			n -= *ppos;
@@ -144,7 +146,9 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
 		} else if (start < page) {
 			if (n > PAGE_SIZE) {
 				printk(KERN_ERR
-				       "proc_file_read: Apparent buffer overflow!\n");
+				       "proc_file_read: Apparent buffer overflow"
+				       " reading '%s'!\n",
+				       file->f_path.dentry->d_name.name);
 				n = PAGE_SIZE;
 			}
 			if (n > count) {
@@ -159,7 +163,9 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
 			unsigned long startoff = (unsigned long)(start - page);
 			if (n > (PAGE_SIZE - startoff)) {
 				printk(KERN_ERR
-				       "proc_file_read: Apparent buffer overflow!\n");
+				       "proc_file_read: Apparent buffer overflow"
+				       " reading '%s'!\n",
+				       file->f_path.dentry->d_name.name);
 				n = PAGE_SIZE - startoff;
 			}
 			if (n > count)
#3 lore raw
In reply to Jan Kiszka
Quoted 1 line · Jan Kiszka

This can help identifying the buggy read_proc handler.

->read_proc is going to be removed, so there is no point.

Quoted 4 lines

-                                      "proc_file_read: Apparent buffer overflow!\n");
+                                      "proc_file_read: Apparent buffer "
+                                      "overflow reading \"%s\"!\n",
+                                      file->f_path.dentry->d_name.name);

author
#4 lore raw
Quoted 4 lines · Alexey Dobriyan
Quoted 1 line · Jan Kiszka

This can help identifying the buggy read_proc handler.

->read_proc is going to be removed, so there is no point.

OK. What is the planned kernel release or date?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux