Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6907547ybp; Wed, 16 Oct 2019 00:25:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYS0HNzrG7tJY02U2ZLQ8vAweNTmXxoTY5nHba11cO95v6kqRdFl6KdutbtsTZkSgII6YT X-Received: by 2002:a17:906:6a09:: with SMTP id o9mr37898924ejr.289.1571210707471; Wed, 16 Oct 2019 00:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571210707; cv=none; d=google.com; s=arc-20160816; b=Xwg1/1x7Hwr4+DCBLOzR9KcJpPiOr9/MnkewTZcnGPT+c3tG+8fbj9ZIlzEFhig9/O 3q8WmZP+MdA2AKidowOey5i65VU579xxjUrul9Py5DKA5feFzgjWqqSFIh0xgC4IBPlI VcMN/eQ/jTBIL96vHKMgkZwPxd6OEtMkRnmeICz9lMpOSizGpHk1KESCf1rPo87bRd7V zSGRQA/TVdEdpu246Av4b32FiUmJTStV2z99X/C0aEMXQFefIkCd+pb8vOF9kmmd5CbU 7ZNvD78D+QgWpsicuSK9yvbOGmyrzo8lGglDJ7Gspi+w+kHx/SX0cdOwZdlDsHduG52g xs7A== 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=Lnz1KY2/ZOZJOeLM7DMa+Pa+WaKbkKTv2bGj+olVUKM=; b=OEIxtPhojLyj+U7UF/iSh/VXzl/9z/ATbolfDTWIryBYPZYEjF3CI8/RxkA8HdPbH5 cCFKFkA9eASR7AFHrQ6kCP6LuNMxUkF3PngXZBJTHwGKCwCsy7Oh2G+bVf0EGlGoUkkK rIr+cjpUNI+WDwqzjXjxEvoTGvWtx/LvWLj7ZT1S8mUNpZEi3u0M+JDFRYyGiQ1WUxoo BLfBxXtTnxisxTADfHyM0eV1NxDKrTGnRkb67YyHEsClCHNn5DoPZmKshHCOxbi9SWoD n6koehsRoB1odnqf20O5dtHeKqVs89MJeUM706qBCEme4R+4u2bENmLHiJu6eZMVfxQP 5WyA== 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 d13si14804315edx.156.2019.10.16.00.24.44; Wed, 16 Oct 2019 00:25:07 -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 S2389038AbfJOVuy (ORCPT + 99 others); Tue, 15 Oct 2019 17:50:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51832 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732397AbfJOVux (ORCPT ); Tue, 15 Oct 2019 17:50:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E466680167C; Tue, 15 Oct 2019 21:50:52 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-84.rdu2.redhat.com [10.10.121.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B80C5C231; Tue, 15 Oct 2019 21:50:50 +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: [RFC PATCH 20/21] selinux: Implement the watch_key security hook From: David Howells To: torvalds@linux-foundation.org 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-block@vger.kernel.org, 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: Tue, 15 Oct 2019 22:50:49 +0100 Message-ID: <157117624933.15019.15041421460029750023.stgit@warthog.procyon.org.uk> In-Reply-To: <157117606853.15019.15459271147790470307.stgit@warthog.procyon.org.uk> References: <157117606853.15019.15459271147790470307.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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 15 Oct 2019 21:50:53 +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 9625b99e677f..53637dccee00 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6579,6 +6579,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 @@ -7012,6 +7023,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