Re: 2.6.13-mm3 [OOPS] vfs, page_owner, full reproductively, badness in vsnprintf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrew Morton napisał(a):
Michal Piotrowski <[email protected]> wrote:

Hi,

Thanks, patch solved problem.


Thanks.


Here is version, that clean apply on 2.6.13-mm3. Can you review it?


That patch is all wordwrapped.

Ups, sorry. This should be good.

How doe sit differe from Alex's patch?



Alex's patch doesn't apply clean on 2.6.13-mm3.

Regards,
Michal Piotrowski

diff -uprN -X linux-mm-clean/Documentation/dontdiff linux-mm-clean/fs/proc/proc_misc.c linux-mm/fs/proc/proc_misc.c
--- linux-mm-clean/fs/proc/proc_misc.c	2005-09-12 23:02:10.000000000 +0200
+++ linux-mm/fs/proc/proc_misc.c	2005-09-12 22:52:51.000000000 +0200
@@ -567,6 +567,7 @@ read_page_owner(struct file *file, char
 	char namebuf[128];
 	unsigned long offset = 0, symsize;
 	int i;
+	ssize_t num_written = 0;

 	pfn = min_low_pfn + *ppos;
 	page = pfn_to_page(pfn);
@@ -587,23 +588,41 @@ read_page_owner(struct file *file, char
 	kbuf = kmalloc(count, GFP_KERNEL);
 	if (!kbuf)
 		return -ENOMEM;
+ ret = snprintf(kbuf, count, "Page allocated via order %d, mask 0x%x\n", page->order, page->gfp_mask);
+        if (ret >= count) {
+                ret = -ENOMEM;
+                goto out;
+        }
+
+        num_written = ret;

-	ret = snprintf(kbuf, 1024, "Page allocated via order %d, mask 0x%x\n",
-			page->order, page->gfp_mask);

 	for (i = 0; i < 8; i++) {
 		if (!page->trace[i])
 			break;
symname = kallsyms_lookup(page->trace[i], &symsize, &offset, &modname, namebuf);
-		ret += snprintf(kbuf + ret, count - ret, "[0x%lx] %s+%lu\n",
+ ret = snprintf(kbuf + num_written, count - num_written, "[0x%lx] %s+%lu\n",
 			page->trace[i], namebuf, offset);
+                if (ret >= count - num_written) {
+                        ret = -ENOMEM;
+                        goto out;
+                }
+                num_written += ret;
+
 	}
+        ret = snprintf(kbuf + num_written, count - num_written, "\n");
+        if (ret >= count - num_written) {
+                ret = -ENOMEM;
+                goto out;
+        }

-	ret += snprintf(kbuf + ret, count -ret, "\n");
+        num_written += ret;
+        ret = num_written;

 	if (copy_to_user(buf, kbuf, ret))
 		ret = -EFAULT;

+out:
 	kfree(kbuf);
 	return ret;
 }
diff -uprN -X linux-mm-clean/Documentation/dontdiff linux-mm-clean/fs/proc/proc_misc.c linux-mm/fs/proc/proc_misc.c
--- linux-mm-clean/fs/proc/proc_misc.c	2005-09-12 23:02:10.000000000 +0200
+++ linux-mm/fs/proc/proc_misc.c	2005-09-12 22:52:51.000000000 +0200
@@ -567,6 +567,7 @@ read_page_owner(struct file *file, char 
 	char namebuf[128];
 	unsigned long offset = 0, symsize;
 	int i;
+	ssize_t num_written = 0;
 
 	pfn = min_low_pfn + *ppos;
 	page = pfn_to_page(pfn);
@@ -587,23 +588,41 @@ read_page_owner(struct file *file, char 
 	kbuf = kmalloc(count, GFP_KERNEL);
 	if (!kbuf)
 		return -ENOMEM;
+        ret = snprintf(kbuf, count, "Page allocated via order %d, mask 0x%x\n",                        page->order, page->gfp_mask);
+        if (ret >= count) {
+                ret = -ENOMEM;
+                goto out;
+        }
+
+        num_written = ret;
 
-	ret = snprintf(kbuf, 1024, "Page allocated via order %d, mask 0x%x\n",
-			page->order, page->gfp_mask);
 
 	for (i = 0; i < 8; i++) {
 		if (!page->trace[i])
 			break;
 		symname = kallsyms_lookup(page->trace[i], &symsize, &offset, &modname, namebuf);
-		ret += snprintf(kbuf + ret, count - ret, "[0x%lx] %s+%lu\n",
+                ret = snprintf(kbuf + num_written, count - num_written, "[0x%lx] %s+%lu\n",
 			page->trace[i], namebuf, offset);
+                if (ret >= count - num_written) {
+                        ret = -ENOMEM;
+                        goto out;
+                }
+                num_written += ret;
+
 	}
+        ret = snprintf(kbuf + num_written, count - num_written, "\n");
+        if (ret >= count - num_written) {
+                ret = -ENOMEM;
+                goto out;
+        }
 
-	ret += snprintf(kbuf + ret, count -ret, "\n");
+        num_written += ret;
+        ret = num_written;
 
 	if (copy_to_user(buf, kbuf, ret))
 		ret = -EFAULT;
 
+out:
 	kfree(kbuf);
 	return ret;
 }

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux