linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* mpol_to_str revisited.
@ 2012-10-08 15:09 Dave Jones
  2012-10-08 15:15 ` Dave Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 59+ messages in thread
From: Dave Jones @ 2012-10-08 15:09 UTC (permalink / raw)
  To: Linux Kernel; +Cc: bhutchings, linux-mm, Linus Torvalds, Andrew Morton

Last month I sent in 80de7c3138ee9fd86a98696fd2cf7ad89b995d0a to remove
a user triggerable BUG in mempolicy.

Ben Hutchings pointed out to me that my change introduced a potential leak
of stack contents to userspace, because none of the callers check the return value.

This patch adds the missing return checking, and also clears the buffer beforehand.

Reported-by: Ben Hutchings <bhutchings@solarflare.com>
Cc: stable@kernel.org
Signed-off-by: Dave Jones <davej@redhat.com>

--- 
unanswered question: why are the buffer sizes here different ? which is correct?


diff -durpN '--exclude-from=/home/davej/.exclude' src/git-trees/kernel/linux/fs/proc/task_mmu.c linux-dj/fs/proc/task_mmu.c
--- src/git-trees/kernel/linux/fs/proc/task_mmu.c	2012-05-31 22:32:46.778150675 -0400
+++ linux-dj/fs/proc/task_mmu.c	2012-10-04 19:31:41.269988984 -0400
@@ -1162,6 +1162,7 @@ static int show_numa_map(struct seq_file
 	struct mm_walk walk = {};
 	struct mempolicy *pol;
 	int n;
+	int ret;
 	char buffer[50];
 
 	if (!mm)
@@ -1178,7 +1179,11 @@ static int show_numa_map(struct seq_file
 	walk.mm = mm;
 
 	pol = get_vma_policy(proc_priv->task, vma, vma->vm_start);
-	mpol_to_str(buffer, sizeof(buffer), pol, 0);
+	memset(buffer, 0, sizeof(buffer));
+	ret = mpol_to_str(buffer, sizeof(buffer), pol, 0);
+	if (ret < 0)
+		return 0;
+
 	mpol_cond_put(pol);
 
 	seq_printf(m, "%08lx %s", vma->vm_start, buffer);
diff -durpN '--exclude-from=/home/davej/.exclude' src/git-trees/kernel/linux/mm/shmem.c linux-dj/mm/shmem.c
--- src/git-trees/kernel/linux/mm/shmem.c	2012-10-02 15:49:51.977277944 -0400
+++ linux-dj/mm/shmem.c	2012-10-04 19:32:28.862949907 -0400
@@ -885,13 +885,15 @@ redirty:
 static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol)
 {
 	char buffer[64];
+	int ret;
 
 	if (!mpol || mpol->mode == MPOL_DEFAULT)
 		return;		/* show nothing */
 
-	mpol_to_str(buffer, sizeof(buffer), mpol, 1);
-
-	seq_printf(seq, ",mpol=%s", buffer);
+	memset(buffer, 0, sizeof(buffer));
+	ret = mpol_to_str(buffer, sizeof(buffer), mpol, 1);
+	if (ret > 0)
+		seq_printf(seq, ",mpol=%s", buffer);
 }
 
 static struct mempolicy *shmem_get_sbmpol(struct shmem_sb_info *sbinfo)

^ permalink raw reply	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2012-11-21  1:00 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-08 15:09 mpol_to_str revisited Dave Jones
2012-10-08 15:15 ` Dave Jones
2012-10-08 20:46   ` David Rientjes
2012-10-08 20:35 ` David Rientjes
2012-10-08 20:52   ` Dave Jones
2012-10-16  0:48     ` David Rientjes
2012-10-09  0:33 ` Ben Hutchings
2012-10-16  2:34 ` KOSAKI Motohiro
2012-10-16  3:58   ` David Rientjes
2012-10-16  5:10     ` KOSAKI Motohiro
2012-10-16  6:10       ` David Rientjes
2012-10-16 23:39         ` KOSAKI Motohiro
2012-10-17  0:12           ` David Rientjes
2012-10-17  0:31             ` [patch for-3.7] mm, mempolicy: fix printing stack contents in numa_maps David Rientjes
2012-10-17  1:38               ` KOSAKI Motohiro
2012-10-17  1:49                 ` David Rientjes
2012-10-17  1:53                   ` KOSAKI Motohiro
2012-10-17  4:05               ` Dave Jones
2012-10-17  5:24                 ` David Rientjes
2012-10-17  5:42                   ` Kamezawa Hiroyuki
2012-10-17  8:49                     ` KOSAKI Motohiro
2012-10-17 19:50                       ` David Rientjes
2012-10-17 21:05                         ` KOSAKI Motohiro
2012-10-17 21:27                           ` David Rientjes
2012-10-17 18:14                   ` Dave Jones
2012-10-17 19:21                     ` David Rientjes
2012-10-17 19:32                       ` Dave Jones
2012-10-17 19:38                         ` David Rientjes
2012-10-17 19:45                           ` Dave Jones
2012-10-17 20:28                             ` [patch for-3.7] mm, mempolicy: avoid taking mutex inside spinlock when reading numa_maps David Rientjes
2012-10-17 21:31                               ` [patch for-3.7 v2] " David Rientjes
2012-10-18  4:06                                 ` Kamezawa Hiroyuki
2012-10-18  4:14                                   ` Linus Torvalds
2012-10-18  4:41                                     ` Kamezawa Hiroyuki
2012-10-18  4:34                                   ` Kamezawa Hiroyuki
2012-10-18 20:03                                     ` David Rientjes
2012-10-19  8:35                                       ` [patch for-3.7 v3] mm, mempolicy: hold task->mempolicy refcount while " Kamezawa Hiroyuki
2012-10-19  9:28                                         ` David Rientjes
2012-10-22  2:47                                           ` Kamezawa Hiroyuki
2012-10-22 20:55                                             ` Andrew Morton
2012-10-22 20:56                                             ` David Rientjes
2012-10-19 19:15                                         ` KOSAKI Motohiro
2012-10-19  6:51                                     ` [patch for-3.7 v2] mm, mempolicy: avoid taking mutex inside spinlock when " KOSAKI Motohiro
2012-10-18  4:35                                   ` David Rientjes
2012-10-24 23:30                   ` [patch for-3.7] mm, mempolicy: fix printing stack contents in numa_maps Sasha Levin
2012-10-24 23:34                     ` David Rientjes
2012-10-24 23:37                       ` Sasha Levin
2012-10-25  0:08                         ` David Rientjes
2012-10-25  0:54                           ` KOSAKI Motohiro
2012-10-25  1:15                             ` David Rientjes
2012-10-25 12:19                           ` Peter Zijlstra
2012-10-25 14:39                             ` Peter Zijlstra
2012-10-25 17:23                               ` Sasha Levin
2012-10-25 20:22                               ` David Rientjes
2012-10-25 23:09                               ` Linus Torvalds
2012-10-26  8:48                                 ` Peter Zijlstra
2012-10-31 18:29                                   ` Sasha Levin
2012-11-21  0:59                                     ` Sasha Levin
2012-10-17  1:33             ` mpol_to_str revisited KOSAKI Motohiro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).