Subject: [PATCH 5/10] Fix leaking of kernel heap addresses in net/

From: Dan Rosenberg <[email-masked]>
Date: Thu, 11 Nov 2010 20:07:09 -0500

diff --git a/net/key/af_key.c b/net/key/af_key.c
index d87c22d..977481a 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3643,14 +3643,25 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
 	if (v == SEQ_START_TOKEN)
 		seq_printf(f ,"sk       RefCnt Rmem   Wmem   User   Inode\n");
 	else
-		seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
-			       s,
-			       atomic_read(&s->sk_refcnt),
-			       sk_rmem_alloc_get(s),
-			       sk_wmem_alloc_get(s),
-			       sock_i_uid(s),
-			       sock_i_ino(s)
-			       );
+		/* Only expose kernel addresses to privileged readers */
+		if (capable(CAP_NET_ADMIN))
+			seq_printf(f, "%p %-6d %-6u %-6u %-6u %-6lu\n",
+				s,
+				atomic_read(&s->sk_refcnt),
+				sk_rmem_alloc_get(s),
+				sk_wmem_alloc_get(s),
+				sock_i_uid(s),
+				sock_i_ino(s)
+				);
+		else
+			seq_printf(f, "%d %-6d %-6u %-6u %-6u %-6lu\n",
+				0,
+				atomic_read(&s->sk_refcnt),
+				sk_rmem_alloc_get(s),
+				sk_wmem_alloc_get(s),
+				sock_i_uid(s),
+				sock_i_ino(s)
+				);
 	return 0;
 }