linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: viro@zeniv.linux.org.uk
Cc: eparis@redhat.com, linux-audit@redhat.com,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 01/10] vfs: allocate page instead of names_cache buffer in mount_block_root
Date: Fri,  7 Sep 2012 09:37:56 -0400	[thread overview]
Message-ID: <1347025085-20285-2-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1347025085-20285-1-git-send-email-jlayton@redhat.com>

First, it's incorrect to call putname() after __getname_gfp() since the
bare __getname_gfp() call skips the auditing code, while putname()
doesn't.

mount_block_root allocates a PATH_MAX buffer via __getname_gfp, and then
calls get_fs_names to fill the buffer. That function can call
get_filesystem_list which assumes that that buffer is a full page in
size. On arches where PAGE_SIZE != 4k, then this could potentially
overrun.

In practice, it's hard to imagine the list of filesystem names even
approaching 4k, but it's best to be safe. Just allocate a page for this
purpose instead.

With this, we can also remove the __getname_gfp() definition since there
are no more callers.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 include/linux/fs.h | 3 +--
 init/do_mounts.c   | 7 ++++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index aa11047..69513a7 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2221,8 +2221,7 @@ extern void __init vfs_caches_init(unsigned long);
 
 extern struct kmem_cache *names_cachep;
 
-#define __getname_gfp(gfp)	kmem_cache_alloc(names_cachep, (gfp))
-#define __getname()		__getname_gfp(GFP_KERNEL)
+#define __getname()		kmem_cache_alloc(names_cachep, GFP_KERNEL)
 #define __putname(name)		kmem_cache_free(names_cachep, (void *)(name))
 #ifndef CONFIG_AUDITSYSCALL
 #define putname(name)   __putname(name)
diff --git a/init/do_mounts.c b/init/do_mounts.c
index d3f0aee..f8a6642 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -353,8 +353,9 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data)
 
 void __init mount_block_root(char *name, int flags)
 {
-	char *fs_names = __getname_gfp(GFP_KERNEL
-		| __GFP_NOTRACK_FALSE_POSITIVE);
+	struct page *page = alloc_page(GFP_KERNEL |
+					__GFP_NOTRACK_FALSE_POSITIVE);
+	char *fs_names = page_address(page);
 	char *p;
 #ifdef CONFIG_BLOCK
 	char b[BDEVNAME_SIZE];
@@ -406,7 +407,7 @@ retry:
 #endif
 	panic("VFS: Unable to mount root fs on %s", b);
 out:
-	putname(fs_names);
+	put_page(page);
 }
  
 #ifdef CONFIG_ROOT_NFS
-- 
1.7.11.4


  reply	other threads:[~2012-09-07 13:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 13:37 [PATCH v1 00/10] vfs: getname/putname overhaul Jeff Layton
2012-09-07 13:37 ` Jeff Layton [this message]
2012-09-07 13:37 ` [PATCH v1 02/10] vfs: make dir_name arg to do_mount a const char * Jeff Layton
2012-09-07 13:37 ` [PATCH v1 03/10] acct: constify the name arg to acct_on Jeff Layton
2012-09-07 13:37 ` [PATCH v1 04/10] vfs: define getname_info struct and have getname() return it Jeff Layton
2012-09-07 13:38 ` [PATCH v1 05/10] audit: allow audit code to satisfy getname requests from its names_list Jeff Layton
2012-09-07 13:38 ` [PATCH v1 06/10] vfs: turn do_path_lookup into wrapper around getname_info variant Jeff Layton
2012-09-07 13:38 ` [PATCH v1 07/10] vfs: make path_openat take a getname_info pointer Jeff Layton
2012-09-07 13:38 ` [PATCH v1 08/10] audit: make audit_inode take getname_info Jeff Layton
2012-09-07 13:38 ` [PATCH v1 09/10] vfs: embed getname_info inside of names_cache allocation if possible Jeff Layton
2012-09-07 13:38 ` [PATCH v1 10/10] vfs: unexport getname and putname symbols Jeff Layton
2012-09-07 21:26 ` [PATCH v1 00/10] vfs: getname/putname overhaul Andi Kleen
2012-09-08  0:54   ` Jeff Layton
2012-09-08  3:08     ` Andi Kleen
2012-09-08 11:24       ` Jeff Layton
2012-09-08 15:38         ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347025085-20285-2-git-send-email-jlayton@redhat.com \
    --to=jlayton@redhat.com \
    --cc=eparis@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).