BACKPORT: Smack: fix a NULL dereference in wrong smack_import_entry() usage
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Tue, 25 Aug 2015 10:39:46 +0000 (12:39 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Fri, 12 Aug 2016 16:00:05 +0000 (18:00 +0200)
'commit e774ad683f42 ("smack: pass error code through pointers")'
made this function return proper error codes instead of NULL. Reflect that.

This is a fix for a NULL dereference introduced in
'commit 21abb1ec414c ("Smack: IPv6 host labeling")'

echo "$SOME_IPV6_ADDR \"test" > /smack/ipv6host
  (this should return EINVAL, it doesn't)
cat /smack/ipv6host
  (derefences 0x000a)

Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
(cherry-picked from upstream 5f2bfe2f1de8b745dc294acaf2ca2ad68e09b374)

security/smack/smackfs.c

index 6b3d03df1d9a08ebde9b21540597ef1b5be4473c..80a8039be79a27f7c140fea8f568295f4a376b8b 100644 (file)
@@ -1501,8 +1501,8 @@ static ssize_t smk_write_net6addr(struct file *file, const char __user *buf,
         */
        if (smack[0] != '-') {
                skp = smk_import_entry(smack, 0);
-               if (skp == NULL) {
-                       rc = -EINVAL;
+               if (IS_ERR(skp)) {
+                       rc = PTR_ERR(skp);
                        goto free_out;
                }
        } else {