Commit 49cd0a5c authored by Greg Thelen's avatar Greg Thelen Committed by Linus Torvalds

tmpfs: fix mempolicy object leaks

Fix several mempolicy leaks in the tmpfs mount logic.  These leaks are
slow - on the order of one object leaked per mount attempt.

Leak 1 (umount doesn't free mpol allocated in mount):
    while true; do
        mount -t tmpfs -o mpol=interleave,size=100M nodev /mnt
        umount /mnt
    done

Leak 2 (errors parsing remount options will leak mpol):
    mount -t tmpfs -o size=100M nodev /mnt
    while true; do
        mount -o remount,mpol=interleave,size=x /mnt 2> /dev/null
    done
    umount /mnt

Leak 3 (multiple mpol per mount leak mpol):
    while true; do
        mount -t tmpfs -o mpol=interleave,mpol=interleave,size=100M nodev /mnt
        umount /mnt
    done

This patch fixes all of the above.  I could have broken the patch into
three pieces but is seemed easier to review as one.

[akpm@linux-foundation.org: fix handling of mpol_parse_str() errors, per Hugh]
Signed-off-by: default avatarGreg Thelen <gthelen@google.com>
Acked-by: default avatarHugh Dickins <hughd@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5f00110f
...@@ -2385,6 +2385,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, ...@@ -2385,6 +2385,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
bool remount) bool remount)
{ {
char *this_char, *value, *rest; char *this_char, *value, *rest;
struct mempolicy *mpol = NULL;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
...@@ -2413,7 +2414,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, ...@@ -2413,7 +2414,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
printk(KERN_ERR printk(KERN_ERR
"tmpfs: No value for mount option '%s'\n", "tmpfs: No value for mount option '%s'\n",
this_char); this_char);
return 1; goto error;
} }
if (!strcmp(this_char,"size")) { if (!strcmp(this_char,"size")) {
...@@ -2462,19 +2463,24 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, ...@@ -2462,19 +2463,24 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
if (!gid_valid(sbinfo->gid)) if (!gid_valid(sbinfo->gid))
goto bad_val; goto bad_val;
} else if (!strcmp(this_char,"mpol")) { } else if (!strcmp(this_char,"mpol")) {
if (mpol_parse_str(value, &sbinfo->mpol)) mpol_put(mpol);
mpol = NULL;
if (mpol_parse_str(value, &mpol))
goto bad_val; goto bad_val;
} else { } else {
printk(KERN_ERR "tmpfs: Bad mount option %s\n", printk(KERN_ERR "tmpfs: Bad mount option %s\n",
this_char); this_char);
return 1; goto error;
} }
} }
sbinfo->mpol = mpol;
return 0; return 0;
bad_val: bad_val:
printk(KERN_ERR "tmpfs: Bad value '%s' for mount option '%s'\n", printk(KERN_ERR "tmpfs: Bad value '%s' for mount option '%s'\n",
value, this_char); value, this_char);
error:
mpol_put(mpol);
return 1; return 1;
} }
...@@ -2550,6 +2556,7 @@ static void shmem_put_super(struct super_block *sb) ...@@ -2550,6 +2556,7 @@ static void shmem_put_super(struct super_block *sb)
struct shmem_sb_info *sbinfo = SHMEM_SB(sb); struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
percpu_counter_destroy(&sbinfo->used_blocks); percpu_counter_destroy(&sbinfo->used_blocks);
mpol_put(sbinfo->mpol);
kfree(sbinfo); kfree(sbinfo);
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment