On Thu, Sep 19, 2024 at 9:23 AM syzbot
<[email protected]> wrote:
>
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit:    bdf56c7580d2 Merge tag 'slab-for-6.12' of git://git.kernel..
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=12584b00580000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=4540f5bcdd31e3de
> dashboard link: https://syzkaller.appspot.com/bug?extid=044fdf24e96093584232
> compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 
> 2.40
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=155cffc7980000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=16ad24a9980000
>
> Downloadable assets:
> disk image: 
> https://storage.googleapis.com/syzbot-assets/cec9f3c675f1/disk-bdf56c75.raw.xz
> vmlinux: 
> https://storage.googleapis.com/syzbot-assets/21e06ae5b159/vmlinux-bdf56c75.xz
> kernel image: 
> https://storage.googleapis.com/syzbot-assets/1e936c954b8b/bzImage-bdf56c75.xz
>
> The issue was bisected to:
>
> commit 5f8d28f6d7d568dbbc8c5bce94894474c07afd4f
> Author: Casey Schaufler <[email protected]>
> Date:   Wed Jul 10 21:32:26 2024 +0000
>
>     lsm: infrastructure management of the key security blob
>
> bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=1124d69f980000
> final oops:     https://syzkaller.appspot.com/x/report.txt?x=1324d69f980000
> console output: https://syzkaller.appspot.com/x/log.txt?x=1524d69f980000

I just posted a patch which I believe should fix the problem, but I'd
like to get Casey's ACK on it before submitting upstream as it does
touch Smack code; lore link below:

https://lore.kernel.org/linux-security-module/[email protected]

... in the meantime, I'm attaching the patch here so syzbot can verify
that it solves the problem.

#syz test

-- 
paul-moore.com
selinux,smack: properly reference the LSM blob in security_watch_key()

From: Paul Moore <[email protected]>

Unfortunately when we migrated the lifecycle management of the key LSM
blob to the LSM framework we forgot to convert the security_watch_key()
callbacks for SELinux and Smack.  This patch corrects this by making use
of the selinux_key() and smack_key() helper functions respectively.

This patch also removes some input checking in the Smack callback as it
is no longer needed.

Reported-by: [email protected]
Fixes: 5f8d28f6d7d5 ("lsm: infrastructure management of the key security blob")
Signed-off-by: Paul Moore <[email protected]>
---
 security/selinux/hooks.c   |    2 +-
 security/smack/smack_lsm.c |   13 +++----------
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 81fbfa5b80d4..67baa487cf7a 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -6720,7 +6720,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
 #ifdef CONFIG_KEY_NOTIFICATIONS
 static int selinux_watch_key(struct key *key)
 {
-	struct key_security_struct *ksec = key->security;
+	struct key_security_struct *ksec = selinux_key(key);
 	u32 sid = current_sid();
 
 	return avc_has_perm(sid, ksec->sid, SECCLASS_KEY, KEY__VIEW, NULL);
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index da0c2bffbd08..563fb404f659 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4629,16 +4629,9 @@ static int smack_watch_key(struct key *key)
 {
 	struct smk_audit_info ad;
 	struct smack_known *tkp = smk_of_current();
+	struct smack_known **blob = smack_key(key);
 	int rc;
 
-	if (key == NULL)
-		return -EINVAL;
-	/*
-	 * If the key hasn't been initialized give it access so that
-	 * it may do so.
-	 */
-	if (key->security == NULL)
-		return 0;
 	/*
 	 * This should not occur
 	 */
@@ -4653,8 +4646,8 @@ static int smack_watch_key(struct key *key)
 	ad.a.u.key_struct.key = key->serial;
 	ad.a.u.key_struct.key_desc = key->description;
 #endif
-	rc = smk_access(tkp, key->security, MAY_READ, &ad);
-	rc = smk_bu_note("key watch", tkp, key->security, MAY_READ, rc);
+	rc = smk_access(tkp, *blob, MAY_READ, &ad);
+	rc = smk_bu_note("key watch", tkp, *blob, MAY_READ, rc);
 	return rc;
 }
 #endif /* CONFIG_KEY_NOTIFICATIONS */

Reply via email to