smackfs: Prevent underflow in smk_set_cipso()
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 6 Jul 2023 05:52:39 +0000 (08:52 +0300)
committerCasey Schaufler <casey@schaufler-ca.com>
Mon, 7 Aug 2023 21:09:23 +0000 (14:09 -0700)
There is a upper bound to "catlen" but no lower bound to prevent
negatives.  I don't see that this necessarily causes a problem but we
may as well be safe.

Fixes: e114e473771c ("Smack: Simplified Mandatory Access Control Kernel")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
security/smack/smackfs.c

index 2b79c30..e22aad7 100644 (file)
@@ -896,7 +896,7 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
        }
 
        ret = sscanf(rule, "%d", &catlen);
-       if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
+       if (ret != 1 || catlen < 0 || catlen > SMACK_CIPSO_MAXCATNUM)
                goto out;
 
        if (format == SMK_FIXED24_FMT &&