aboutsummaryrefslogtreecommitdiffstats
path: root/mm/shmem.c
diff options
context:
space:
mode:
authorGreg Thelen <gthelen@google.com>2013-02-22 19:36:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-23 20:50:23 -0500
commit5f00110f7273f9ff04ac69a5f85bb535a4fd0987 (patch)
tree766ec74663d4e184d824dde7201d9d5265fb943f /mm/shmem.c
parent67d46b296a1ba1477c0df8ff3bc5e0167a0b0732 (diff)
tmpfs: fix use-after-free of mempolicy object
The tmpfs remount logic preserves filesystem mempolicy if the mpol=M option is not specified in the remount request. A new policy can be specified if mpol=M is given. Before this patch remounting an mpol bound tmpfs without specifying mpol= mount option in the remount request would set the filesystem's mempolicy object to a freed mempolicy object. To reproduce the problem boot a DEBUG_PAGEALLOC kernel and run: # mkdir /tmp/x # mount -t tmpfs -o size=100M,mpol=interleave nodev /tmp/x # grep /tmp/x /proc/mounts nodev /tmp/x tmpfs rw,relatime,size=102400k,mpol=interleave:0-3 0 0 # mount -o remount,size=200M nodev /tmp/x # grep /tmp/x /proc/mounts nodev /tmp/x tmpfs rw,relatime,size=204800k,mpol=??? 0 0 # note ? garbage in mpol=... output above # dd if=/dev/zero of=/tmp/x/f count=1 # panic here Panic: BUG: unable to handle kernel NULL pointer dereference at (null) IP: [< (null)>] (null) [...] Oops: 0010 [#1] SMP DEBUG_PAGEALLOC Call Trace: mpol_shared_policy_init+0xa5/0x160 shmem_get_inode+0x209/0x270 shmem_mknod+0x3e/0xf0 shmem_create+0x18/0x20 vfs_create+0xb5/0x130 do_last+0x9a1/0xea0 path_openat+0xb3/0x4d0 do_filp_open+0x42/0xa0 do_sys_open+0xfe/0x1e0 compat_sys_open+0x1b/0x20 cstar_dispatch+0x7/0x1f Non-debug kernels will not crash immediately because referencing the dangling mpol will not cause a fault. Instead the filesystem will reference a freed mempolicy object, which will cause unpredictable behavior. The problem boils down to a dropped mpol reference below if shmem_parse_options() does not allocate a new mpol: config = *sbinfo shmem_parse_options(data, &config, true) mpol_put(sbinfo->mpol) sbinfo->mpol = config.mpol /* BUG: saves unreferenced mpol */ This patch avoids the crash by not releasing the mempolicy if shmem_parse_options() doesn't create a new mpol. How far back does this issue go? I see it in both 2.6.36 and 3.3. I did not look back further. Signed-off-by: Greg Thelen <gthelen@google.com> Acked-by: Hugh Dickins <hughd@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/shmem.c')
-rw-r--r--mm/shmem.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index 7162c58355b1..5e2ff592e3b8 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2486,6 +2486,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
2486 unsigned long inodes; 2486 unsigned long inodes;
2487 int error = -EINVAL; 2487 int error = -EINVAL;
2488 2488
2489 config.mpol = NULL;
2489 if (shmem_parse_options(data, &config, true)) 2490 if (shmem_parse_options(data, &config, true))
2490 return error; 2491 return error;
2491 2492
@@ -2510,8 +2511,13 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
2510 sbinfo->max_inodes = config.max_inodes; 2511 sbinfo->max_inodes = config.max_inodes;
2511 sbinfo->free_inodes = config.max_inodes - inodes; 2512 sbinfo->free_inodes = config.max_inodes - inodes;
2512 2513
2513 mpol_put(sbinfo->mpol); 2514 /*
2514 sbinfo->mpol = config.mpol; /* transfers initial ref */ 2515 * Preserve previous mempolicy unless mpol remount option was specified.
2516 */
2517 if (config.mpol) {
2518 mpol_put(sbinfo->mpol);
2519 sbinfo->mpol = config.mpol; /* transfers initial ref */
2520 }
2515out: 2521out:
2516 spin_unlock(&sbinfo->stat_lock); 2522 spin_unlock(&sbinfo->stat_lock);
2517 return error; 2523 return error;