1 ext4: fix #11321: create /proc/ext4/*/stats more carefully
3 From: Alexey Dobriyan <adobriyan@gmail.com>
5 ext4 creates per-suberblock directory in /proc/ext4/ . Name used as
6 basis is taken from bdevname, which, surprise, can contain slash.
8 However, proc while allowing to use proc_create("a/b", parent) form of
9 PDE creation, assumes that parent/a was already created.
11 bdevname in question is 'cciss/c0d0p9', directory is not created and all
12 this stuff goes directly into /proc (which is real bug).
14 Warning comes when _second_ partition is mounted.
16 http://bugzilla.kernel.org/show_bug.cgi?id=11321
18 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
19 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
20 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
21 index c7b0dea..af48548 100644
22 --- a/fs/ext4/mballoc.c
23 +++ b/fs/ext4/mballoc.c
24 @@ -2786,14 +2786,20 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
25 mode_t mode = S_IFREG | S_IRUGO | S_IWUSR;
26 struct ext4_sb_info *sbi = EXT4_SB(sb);
27 struct proc_dir_entry *proc;
29 + char devname[BDEVNAME_SIZE], *p;
31 if (proc_root_ext4 == NULL) {
32 sbi->s_mb_proc = NULL;
35 bdevname(sb->s_bdev, devname);
37 + while ((p = strchr(p, '/')))
40 sbi->s_mb_proc = proc_mkdir(devname, proc_root_ext4);
41 + if (!sbi->s_mb_proc)
42 + goto err_create_dir;
44 MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats);
45 MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan);
46 @@ -2805,7 +2811,6 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
50 - printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
51 remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
52 remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
53 remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);
54 @@ -2814,6 +2819,8 @@ err_out:
55 remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
56 remove_proc_entry(devname, proc_root_ext4);
57 sbi->s_mb_proc = NULL;
59 + printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
63 @@ -2821,12 +2828,15 @@ err_out:
64 static int ext4_mb_destroy_per_dev_proc(struct super_block *sb)
66 struct ext4_sb_info *sbi = EXT4_SB(sb);
68 + char devname[BDEVNAME_SIZE], *p;
70 if (sbi->s_mb_proc == NULL)
73 bdevname(sb->s_bdev, devname);
75 + while ((p = strchr(p, '/')))
77 remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
78 remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
79 remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);