Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2691759ybl; Thu, 29 Aug 2019 11:32:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmo6+ZxRWtQCFh8MVL6k3D/D+KDoAT6/5Jt6MUAkEL/ZFE+BB6E7B0u0irix3lHc/nVdzs X-Received: by 2002:a17:902:ab8e:: with SMTP id f14mr11649754plr.6.1567103550957; Thu, 29 Aug 2019 11:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103550; cv=none; d=google.com; s=arc-20160816; b=GAE5SxiqoH4c2/9ZQwCh8Th+6MWzyK4CIAblbSKjHXHyVmWQ3J//zV/ZvGW2VoxJL4 rPPFWEvRS0otHlXUTSw720DHH0a0UMWvvJ/UiHx6SkZ0M4pT6hyerYY7yEdE0dFTMOGL k47/cDgWAbWIkxbRJCD5YtPjAel1+DtfHaBYDFetddfyXg2X20oA5yOfzHQ9NmQhAwb7 hB7ZuEmflxUGeXND3fN0KsFgS2vIX7EPWXac85zqE2Sq5JQZ18h7b2zIa2noIxv2swxp VccsBRKLyou2Zb0JSYYEx/2xNTV6CCP95uA1GaXDpqj6/QO6nbkleLFCZxy6PWxITKND HONA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=jvGP2TrNsFuNA9yRgCig66wYEb0OdRa20DUvPoL1XLo=; b=XchXh9nGfBDW1NTuvXx1rC8E1DjL+3f5guA1twf0kIJIADnCKoSVkMyolGgqTcp19H pWYhkIofWsw75D1ukCN0sjdFNsBw5BjxRAtSNmLVCdgxfef2cU4rEzj141VfSZIO+ejG kJvNBEsjudHl1epYVGUxK6Qhyr53hIG/aZJkIlFQiiTiP+IUF6OS387CnZtAGRbUJJ1q VHgUmDYM1Pd/a9Qs6QmdtX19g8cwbSFw0j8kosLuFOF/B8VD23Z0pXyU8BtzSonCKNLj dzdXeaQ16oxqXKkWgXS/ikUytSLeTBuYWa+Y/9cim0r7kdH7FQxbxSb/p3txjZoEaEAJ qwlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9si2635015pgp.181.2019.08.29.11.32.15; Thu, 29 Aug 2019 11:32:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729835AbfH2Sb1 (ORCPT + 99 others); Thu, 29 Aug 2019 14:31:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49906 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728972AbfH2SbY (ORCPT ); Thu, 29 Aug 2019 14:31:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 189C8308212A; Thu, 29 Aug 2019 18:31:24 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-255.rdu2.redhat.com [10.10.120.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C76F600CD; Thu, 29 Aug 2019 18:31:21 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 10/11] selinux: Implement the watch_key security hook [ver #6] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, Casey Schaufler , Stephen Smalley , Greg Kroah-Hartman , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , dhowells@redhat.com, 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-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 29 Aug 2019 19:31:20 +0100 Message-ID: <156710348066.10009.17986469867635955040.stgit@warthog.procyon.org.uk> In-Reply-To: <156710338860.10009.12524626894838499011.stgit@warthog.procyon.org.uk> References: <156710338860.10009.12524626894838499011.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 29 Aug 2019 18:31:24 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement the watch_key security hook to make sure that a key grants the caller View permission in order to set a watch on a key. For the moment, the watch_devices security hook is left unimplemented as it's not obvious what the object should be since the queue is global and didn't previously exist. Signed-off-by: David Howells --- security/selinux/hooks.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 74dd46de01b6..371f2ebc879b 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6533,6 +6533,20 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) *_buffer = context; return rc; } + +#ifdef CONFIG_KEY_NOTIFICATIONS +static int selinux_watch_key(struct watch *watch, struct key *key) +{ + struct key_security_struct *ksec; + u32 sid; + + sid = cred_sid(watch->cred); + ksec = key->security; + + return avc_has_perm(&selinux_state, + sid, ksec->sid, SECCLASS_KEY, KEY_NEED_VIEW, NULL); +} +#endif #endif #ifdef CONFIG_SECURITY_INFINIBAND @@ -6965,6 +6979,9 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(key_free, selinux_key_free), LSM_HOOK_INIT(key_permission, selinux_key_permission), LSM_HOOK_INIT(key_getsecurity, selinux_key_getsecurity), +#ifdef CONFIG_KEY_NOTIFICATIONS + LSM_HOOK_INIT(watch_key, selinux_watch_key), +#endif #endif #ifdef CONFIG_AUDIT