sdcardfs: limit stacking depth
authorAndrew Chant <achant@google.com>
Wed, 8 Feb 2017 23:33:48 +0000 (15:33 -0800)
committerStricted <info@stricted.net>
Thu, 11 Oct 2018 16:03:25 +0000 (18:03 +0200)
Limit filesystem stacking to prevent stack overflow.

Bug: 32761463
Change-Id: I8b1462b9c0d6c7f00cf110724ffb17e7f307c51e
Signed-off-by: Andrew Chant <achant@google.com>
fs/sdcardfs/main.c

index 8d16e4d16d96da5a7792f97a1e8f8c797a64bd18..fb9dd5dea2b8ce8ca672b1f58dc25b81fafca210 100644 (file)
@@ -284,6 +284,13 @@ static int sdcardfs_read_super(struct vfsmount *mnt, struct super_block *sb,
        atomic_inc(&lower_sb->s_active);
        sdcardfs_set_lower_super(sb, lower_sb);
 
+       sb->s_stack_depth = lower_sb->s_stack_depth + 1;
+       if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
+               pr_err("sdcardfs: maximum fs stacking depth exceeded\n");
+               err = -EINVAL;
+               goto out_sput;
+       }
+
        /* inherit maxbytes from lower file system */
        sb->s_maxbytes = lower_sb->s_maxbytes;