diff mbox series

[1/2] Smack: fix another vsscanf out of bounds

Message ID 20200723152219.GA302005@mwanda (mailing list archive)
State New, archived
Headers show
Series [1/2] Smack: fix another vsscanf out of bounds | expand

Commit Message

Dan Carpenter July 23, 2020, 3:22 p.m. UTC
This is similar to commit 84e99e58e8d1 ("Smack: slab-out-of-bounds in
vsscanf") where we added a bounds check on "rule".

Reported-by: syzbot+a22c6092d003d6fe1122@syzkaller.appspotmail.com
Fixes: f7112e6c9abf ("Smack: allow for significantly longer Smack labels v4")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This check is very straight forward and should fix the bug.  But if you
look at the fixes tag we used to rely on the check:

	if (count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))

and now that has been changed to:

	if (format == SMK_FIXED24_FMT &&
	    count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
                goto out;

so it doesn't apply for every format.

 security/smack/smackfs.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Casey Schaufler July 23, 2020, 4:38 p.m. UTC | #1
On 7/23/2020 8:22 AM, Dan Carpenter wrote:
> This is similar to commit 84e99e58e8d1 ("Smack: slab-out-of-bounds in
> vsscanf") where we added a bounds check on "rule".
>
> Reported-by: syzbot+a22c6092d003d6fe1122@syzkaller.appspotmail.com
> Fixes: f7112e6c9abf ("Smack: allow for significantly longer Smack labels v4")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks. I'll be testing these and take them assuming they pass.

> ---
> This check is very straight forward and should fix the bug.  But if you
> look at the fixes tag we used to rely on the check:
>
> 	if (count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
>
> and now that has been changed to:
>
> 	if (format == SMK_FIXED24_FMT &&
> 	    count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
>                 goto out;
>
> so it doesn't apply for every format.
>
>  security/smack/smackfs.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
> index c21b656b3263..81c6ceeaa4f9 100644
> --- a/security/smack/smackfs.c
> +++ b/security/smack/smackfs.c
> @@ -905,6 +905,10 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
>  
>  	for (i = 0; i < catlen; i++) {
>  		rule += SMK_DIGITLEN;
> +		if (rule > data + count) {
> +			rc = -EOVERFLOW;
> +			goto out;
> +		}
>  		ret = sscanf(rule, "%u", &cat);
>  		if (ret != 1 || cat > SMACK_CIPSO_MAXCATNUM)
>  			goto out;
diff mbox series

Patch

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index c21b656b3263..81c6ceeaa4f9 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -905,6 +905,10 @@  static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
 
 	for (i = 0; i < catlen; i++) {
 		rule += SMK_DIGITLEN;
+		if (rule > data + count) {
+			rc = -EOVERFLOW;
+			goto out;
+		}
 		ret = sscanf(rule, "%u", &cat);
 		if (ret != 1 || cat > SMACK_CIPSO_MAXCATNUM)
 			goto out;