Skip to content

Commit 8a23c9e

Browse files
committed
selinux,smack: properly reference the LSM blob in security_watch_key()
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. Fixes: 5f8d28f ("lsm: infrastructure management of the key security blob") Reported-by: [email protected] Tested-by: [email protected] Reviewed-by: Casey Schaufler <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent ea7e2d5 commit 8a23c9e

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

security/selinux/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6720,7 +6720,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
67206720
#ifdef CONFIG_KEY_NOTIFICATIONS
67216721
static int selinux_watch_key(struct key *key)
67226722
{
6723-
struct key_security_struct *ksec = key->security;
6723+
struct key_security_struct *ksec = selinux_key(key);
67246724
u32 sid = current_sid();
67256725

67266726
return avc_has_perm(sid, ksec->sid, SECCLASS_KEY, KEY__VIEW, NULL);

security/smack/smack_lsm.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,16 +4629,9 @@ static int smack_watch_key(struct key *key)
46294629
{
46304630
struct smk_audit_info ad;
46314631
struct smack_known *tkp = smk_of_current();
4632+
struct smack_known **blob = smack_key(key);
46324633
int rc;
46334634

4634-
if (key == NULL)
4635-
return -EINVAL;
4636-
/*
4637-
* If the key hasn't been initialized give it access so that
4638-
* it may do so.
4639-
*/
4640-
if (key->security == NULL)
4641-
return 0;
46424635
/*
46434636
* This should not occur
46444637
*/
@@ -4653,8 +4646,8 @@ static int smack_watch_key(struct key *key)
46534646
ad.a.u.key_struct.key = key->serial;
46544647
ad.a.u.key_struct.key_desc = key->description;
46554648
#endif
4656-
rc = smk_access(tkp, key->security, MAY_READ, &ad);
4657-
rc = smk_bu_note("key watch", tkp, key->security, MAY_READ, rc);
4649+
rc = smk_access(tkp, *blob, MAY_READ, &ad);
4650+
rc = smk_bu_note("key watch", tkp, *blob, MAY_READ, rc);
46584651
return rc;
46594652
}
46604653
#endif /* CONFIG_KEY_NOTIFICATIONS */

0 commit comments

Comments
 (0)