Smack: slab-out-of-bounds in vsscanf
authorCasey Schaufler <casey@schaufler-ca.com>
Thu, 9 Apr 2020 23:35:28 +0000 (16:35 -0700)
committerCasey Schaufler <casey@schaufler-ca.com>
Wed, 6 May 2020 21:46:26 +0000 (14:46 -0700)
Add barrier to soob. Return -EOVERFLOW if the buffer
is exceeded.

Suggested-by: Hillf Danton <hdanton@sina.com>
Reported-by: syzbot+bfdd4a2f07be52351350@syzkaller.appspotmail.com
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
security/smack/smackfs.c

index e3e05c0..c21b656 100644 (file)
@@ -878,11 +878,21 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
        else
                rule += strlen(skp->smk_known) + 1;
 
+       if (rule > data + count) {
+               rc = -EOVERFLOW;
+               goto out;
+       }
+
        ret = sscanf(rule, "%d", &maplevel);
        if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
                goto out;
 
        rule += SMK_DIGITLEN;
+       if (rule > data + count) {
+               rc = -EOVERFLOW;
+               goto out;
+       }
+
        ret = sscanf(rule, "%d", &catlen);
        if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
                goto out;