Commit a608ca21f58ee44df5a71ba140e98498f3ebc2cd

Authored by Jeff Layton
Committed by Al Viro
1 parent 4fa6b5ecbf

vfs: allocate page instead of names_cache buffer in mount_block_root

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>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 2 changed files with 5 additions and 5 deletions Side-by-side Diff

... ... @@ -2228,8 +2228,7 @@
2228 2228  
2229 2229 extern struct kmem_cache *names_cachep;
2230 2230  
2231   -#define __getname_gfp(gfp) kmem_cache_alloc(names_cachep, (gfp))
2232   -#define __getname() __getname_gfp(GFP_KERNEL)
  2231 +#define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
2233 2232 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
2234 2233 #ifndef CONFIG_AUDITSYSCALL
2235 2234 #define putname(name) __putname(name)
... ... @@ -353,8 +353,9 @@
353 353  
354 354 void __init mount_block_root(char *name, int flags)
355 355 {
356   - char *fs_names = __getname_gfp(GFP_KERNEL
357   - | __GFP_NOTRACK_FALSE_POSITIVE);
  356 + struct page *page = alloc_page(GFP_KERNEL |
  357 + __GFP_NOTRACK_FALSE_POSITIVE);
  358 + char *fs_names = page_address(page);
358 359 char *p;
359 360 #ifdef CONFIG_BLOCK
360 361 char b[BDEVNAME_SIZE];
... ... @@ -406,7 +407,7 @@
406 407 #endif
407 408 panic("VFS: Unable to mount root fs on %s", b);
408 409 out:
409   - putname(fs_names);
  410 + put_page(page);
410 411 }
411 412  
412 413 #ifdef CONFIG_ROOT_NFS