Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp69621ybe; Wed, 4 Sep 2019 15:19:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwt8We2861tg7F6R5TirY1+bnwP/gz9FgMCps9+TlCEzIK+ClALutdyXtB7N5G4HjlRs0pf X-Received: by 2002:a63:de4c:: with SMTP id y12mr359246pgi.264.1567635541141; Wed, 04 Sep 2019 15:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567635541; cv=none; d=google.com; s=arc-20160816; b=AwXNIcqQIqqu2XSXbs2NzizVZnBU33NSB6qNiQGze91w3xDSmVvLP7E5xFgixEceh3 OB58K8U/XOY5BSXWEeQ1ZbK/0vDhLGFj8SDBsUcun+ZkfZkpD0nSo5vdixbCS8Pxq1wr W5NlevRkSE0+y72GjJvjNRf4u7b4URvSrTp67vBrfLd+kTy55D1zaN/UpHdszHRDPTK3 kZwHMSBcBiVooJxfzvr0xzhyajClGWmWqYCpt70TTZbkjrTmAAL50PjJryZNmJSo61Wj /EZN+gqzlc8bHu0VPU1/hHZdKpR2hunHBSIsdp4GhMPtWczKhlyZ2V9FsmjCWbXKPUFG gs0g== 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=oT1vj86yTl+qQUp+PqnQygz/zHHx3jKffzTSBUY2yfA=; b=Zh/65+sGR2M0HupgnTczNx9I+bREBGRe4nm6KTb6NIwgZbvE5V5qPQfizA7jhQv2F+ DBFCKdGiWscLFRG7PGcrz0X4952mBlyUPdTpu1Or1n7mqZNaExaGBCv8DMdZyhe/rcgt +stt/L3Z1ko1IgB2GRTOylP67PkawDND07NpHW4ja56oOs6/FzioiWGDJRl7CGx8w4RB nDbc+1PmLnuEP9Pb+SD+FANVa7r0P04ynIGv6rpHa43CN/IFr2y6PGI4kOL65K+z0aFR W9eD9puvZWA5OmDhr1/s3KucLjx5IwAOWJJneGPh73CP/j9XkflYIXH1lk84xBAJMrE8 qZWQ== 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 x131si68505pfd.116.2019.09.04.15.18.36; Wed, 04 Sep 2019 15:19:01 -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 S1731006AbfIDWRU (ORCPT + 99 others); Wed, 4 Sep 2019 18:17:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59146 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730140AbfIDWRT (ORCPT ); Wed, 4 Sep 2019 18:17:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD0EB3084050; Wed, 4 Sep 2019 22:17:18 +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 A19AA5D6D0; Wed, 4 Sep 2019 22:17:15 +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 #8] From: David Howells To: keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-block@vger.kernel.org Cc: dhowells@redhat.com, torvalds@linux-foundation.org, Casey Schaufler , Stephen Smalley , Greg Kroah-Hartman , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , dhowells@redhat.com, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 04 Sep 2019 23:17:14 +0100 Message-ID: <156763543468.18676.2518876207052977804.stgit@warthog.procyon.org.uk> In-Reply-To: <156763534546.18676.3530557439501101639.stgit@warthog.procyon.org.uk> References: <156763534546.18676.3530557439501101639.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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 04 Sep 2019 22:17:19 +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 Acked-by: Stephen Smalley --- security/selinux/hooks.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 74dd46de01b6..88df06969bed 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6533,6 +6533,17 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) *_buffer = context; return rc; } + +#ifdef CONFIG_KEY_NOTIFICATIONS +static int selinux_watch_key(struct key *key) +{ + struct key_security_struct *ksec = key->security; + u32 sid = current_sid(); + + return avc_has_perm(&selinux_state, + sid, ksec->sid, SECCLASS_KEY, KEY_NEED_VIEW, NULL); +} +#endif #endif #ifdef CONFIG_SECURITY_INFINIBAND @@ -6965,6 +6976,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