From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6741C3A5A8 for ; Tue, 3 Sep 2019 15:20:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E72F2339D for ; Tue, 3 Sep 2019 15:20:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="hmAa8yTg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729539AbfICPU5 (ORCPT ); Tue, 3 Sep 2019 11:20:57 -0400 Received: from sonic311-22.consmr.mail.bf2.yahoo.com ([74.6.131.196]:33756 "EHLO sonic311-22.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729537AbfICPUy (ORCPT ); Tue, 3 Sep 2019 11:20:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1567524052; bh=TMtiGR6eRY4JXVQE6K2FOJLCSh0SN/dUnRdFJ4kOeVo=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=hmAa8yTgiOPbZrVPgL9JwC1XL0sxZm7aAOmTe0qLday0oV9rzjFHHJZH5ow68g17xI9eWDJ/aXpwH3zMCKWRhoUW4IsBUTqC28r9TrLDmLDbx16PpFhRSFPreRBc53VAGbcwO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CKQIWyCPvm7xecw1v.qS7yhhPpKluyq7mTu1jgnPPMiFd6dES iL0pPdjhyNUit56plUfd5_o0n4tB2jEHrQcrUSw44k5aq6D.MJxo2n_YOr6Y1Al8jU2Dcfd4Nsvk 6jpjDj0p15ArKg7OL08_TNkPc8x3icb0RiM4XvvSqwhKkpysi9PE0mKHMQg18ntd4EosWN9DXzro imN9jTjWyJZ3v2U7NEBCrdxPtzhJCDPYd6FfZfTR2rcJqAs2IuNQjvwSQVBtsaxb35mVmbS9xn37 Us8NfZLKvoXhLLrsrhDQJVSke_SCxkO8IW72DNl.w4_ithkCKJGk5.xMJoHl0ujcAYve0F7MK2TL M_u0K4W8QMk56aPCeNdB1AEzuMWtk2TVL3glEA8dngC53gWpLl3foLa4J8yUFVZ0Q_8_HL3MurK6 ryrHGo7kqVfELnDyRs5MvKmG5vYOgOtqISUITzsT.HFSuJIN. Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Tue, 3 Sep 2019 15:20:52 +0000 Received: by smtp403.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 37155d70885c019b8dadd518967841e9; Tue, 03 Sep 2019 15:20:49 +0000 (UTC) Subject: Re: [PATCH 11/11] smack: Implement the watch_key and post_notification hooks [untested] [ver #7] To: David Howells , viro@zeniv.linux.org.uk Cc: Stephen Smalley , Greg Kroah-Hartman , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, casey@schaufler-ca.com References: <156717343223.2204.15875738850129174524.stgit@warthog.procyon.org.uk> <156717352917.2204.17206219813087348132.stgit@warthog.procyon.org.uk> From: Casey Schaufler Openpgp: preference=signencrypt Autocrypt: addr=casey@schaufler-ca.com; keydata= mQINBFzV9HABEAC/mmv3jeJyF7lR7Qh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ZPPJXuBokrFH8kqnEQ9W2QgrjDX3et2WwZFLOoOCItWxT0/1QO4ikcef/E7HXQf/ij Dxf9HG2o5hOlMIAkJq/uLNMvABEBAAGJAjwEGAEIACYWIQQL720fVjJTAhDNQh44pRV8jEPI EQUCXNX0cAIbDAUJEswDAAAKCRA4pRV8jEPIEWkzEACKFUnpp+wIVHpckMfBqN8BE5dUbWJc GyQ7wXWajLtlPdw1nNw0Wrv+ob2RCT7qQlUo6GRLcvj9Fn5tR4hBvR6D3m8aR0AGHbcC62cq I7LjaSDP5j/em4oVL2SMgNTrXgE2w33JMGjAx9oBzkxmKUqprhJomPwmfDHMJ0t7y39Da724 oLPTkQDpJL1kuraM9TC5NyLe1+MyIxqM/8NujoJbWeQUgGjn9uxQAil7o/xSCjrWCP3kZDID vd5ZaHpdl8e1mTExQoKr4EWgaMjmD/a3hZ/j3KfTVNpM2cLfD/QwTMaC2fkK8ExMsz+rUl1H icmcmpptCwOSgwSpPY1Zfio6HvEJp7gmDwMgozMfwQuT9oxyFTxn1X3rn1IoYQF3P8gsziY5 qtTxy2RrgqQFm/hr8gM78RhP54UPltIE96VywviFzDZehMvuwzW//fxysIoK97Y/KBZZOQs+ /T+Bw80Pwk/dqQ8UmIt2ffHEgwCTbkSm711BejapWCfklxkMZDp16mkxSt2qZovboVjXnfuq wQ1QL4o4t1hviM7LyoflsCLnQFJh6RSBhBpKQinMJl/z0A6NYDkQi6vEGMDBWX/M2vk9Jvwa v0cEBfY3Z5oFgkh7BUORsu1V+Hn0fR/Lqq/Pyq+nTR26WzGDkolLsDr3IH0TiAVH5ZuPxyz6 abzjfg== Message-ID: Date: Tue, 3 Sep 2019 08:20:46 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <156717352917.2204.17206219813087348132.stgit@warthog.procyon.org.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On 8/30/2019 6:58 AM, David Howells wrote: > Implement the watch_key security hook in Smack to make sure that a key > grants the caller Read permission in order to set a watch on a key. > > Also implement the post_notification security hook to make sure that th= e > notification source is granted Write permission by the watch queue. > > For the moment, the watch_devices security hook is left unimplemented a= s > it's not obvious what the object should be since the queue is global an= d > didn't previously exist. > > Signed-off-by: David Howells I tried running your key tests and they fail in "keyctl/move/valid", with 11 FAILED messages, finally hanging after "UNLINK KEY FROM SESSION".= It's possible that my Fedora26 system is somehow incompatible with the tests. I don't see anything in your code that would cause this, as the Smack policy on the system shouldn't restrict any access. > --- > > include/linux/lsm_audit.h | 1 + > security/smack/smack_lsm.c | 82 ++++++++++++++++++++++++++++++++++++= +++++++- > 2 files changed, 82 insertions(+), 1 deletion(-) > > diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h > index 915330abf6e5..734d67889826 100644 > --- a/include/linux/lsm_audit.h > +++ b/include/linux/lsm_audit.h > @@ -74,6 +74,7 @@ struct common_audit_data { > #define LSM_AUDIT_DATA_FILE 12 > #define LSM_AUDIT_DATA_IBPKEY 13 > #define LSM_AUDIT_DATA_IBENDPORT 14 > +#define LSM_AUDIT_DATA_NOTIFICATION 15 > union { > struct path path; > struct dentry *dentry; > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c > index 4c5e5a438f8b..1c2a908c6446 100644 > --- a/security/smack/smack_lsm.c > +++ b/security/smack/smack_lsm.c > @@ -4274,7 +4274,7 @@ static int smack_key_permission(key_ref_t key_ref= , > if (tkp =3D=3D NULL) > return -EACCES; > =20 > - if (smack_privileged_cred(CAP_MAC_OVERRIDE, cred)) > + if (smack_privileged(CAP_MAC_OVERRIDE)) > return 0; > =20 > #ifdef CONFIG_AUDIT > @@ -4320,8 +4320,81 @@ static int smack_key_getsecurity(struct key *key= , char **_buffer) > return length; > } > =20 > + > +#ifdef CONFIG_KEY_NOTIFICATIONS > +/** > + * smack_watch_key - Smack access to watch a key for notifications. > + * @key: The key to be watched > + * > + * Return 0 if the @watch->cred has permission to read from the key ob= ject and > + * an error otherwise. > + */ > +static int smack_watch_key(struct key *key) > +{ > + struct smk_audit_info ad; > + struct smack_known *tkp =3D smk_of_current(); > + int rc; > + > + if (key =3D=3D NULL) > + return -EINVAL; > + /* > + * If the key hasn't been initialized give it access so that > + * it may do so. > + */ > + if (key->security =3D=3D NULL) > + return 0; > + /* > + * This should not occur > + */ > + if (tkp =3D=3D NULL) > + return -EACCES; > + > + if (smack_privileged_cred(CAP_MAC_OVERRIDE, current_cred())) > + return 0; > + > +#ifdef CONFIG_AUDIT > + smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY); > + ad.a.u.key_struct.key =3D key->serial; > + ad.a.u.key_struct.key_desc =3D key->description; > +#endif > + rc =3D smk_access(tkp, key->security, MAY_READ, &ad); > + rc =3D smk_bu_note("key watch", tkp, key->security, MAY_READ, rc); > + return rc; > +} > +#endif /* CONFIG_KEY_NOTIFICATIONS */ > #endif /* CONFIG_KEYS */ > =20 > +#ifdef CONFIG_WATCH_QUEUE > +/** > + * smack_post_notification - Smack access to post a notification to a = queue > + * @w_cred: The credentials of the watcher. > + * @cred: The credentials of the event source (may be NULL). > + * @n: The notification message to be posted. > + */ > +static int smack_post_notification(const struct cred *w_cred, > + const struct cred *cred, > + struct watch_notification *n) > +{ > + struct smk_audit_info ad; > + struct smack_known *subj, *obj; > + int rc; > + > + /* Always let maintenance notifications through. */ > + if (n->type =3D=3D WATCH_TYPE_META) > + return 0; > + > + if (!cred) > + return 0; > + subj =3D smk_of_task(smack_cred(cred)); > + obj =3D smk_of_task(smack_cred(w_cred)); > + > + smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NOTIFICATION); > + rc =3D smk_access(subj, obj, MAY_WRITE, &ad); > + rc =3D smk_bu_note("notification", subj, obj, MAY_WRITE, rc); > + return rc; > +} > +#endif /* CONFIG_WATCH_QUEUE */ > + > /* > * Smack Audit hooks > * > @@ -4710,8 +4783,15 @@ static struct security_hook_list smack_hooks[] _= _lsm_ro_after_init =3D { > LSM_HOOK_INIT(key_free, smack_key_free), > LSM_HOOK_INIT(key_permission, smack_key_permission), > LSM_HOOK_INIT(key_getsecurity, smack_key_getsecurity), > +#ifdef CONFIG_KEY_NOTIFICATIONS > + LSM_HOOK_INIT(watch_key, smack_watch_key), > +#endif > #endif /* CONFIG_KEYS */ > =20 > +#ifdef CONFIG_WATCH_QUEUE > + LSM_HOOK_INIT(post_notification, smack_post_notification), > +#endif > + > /* Audit hooks */ > #ifdef CONFIG_AUDIT > LSM_HOOK_INIT(audit_rule_init, smack_audit_rule_init), >