Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp729149ybh; Wed, 18 Mar 2020 08:06:19 -0700 (PDT) X-Google-Smtp-Source: ADFU+vud+CKqgNJRSm+Yhq9IZCFCYzl9KP+JxPBCVKONndDcm8jFGqBNzKyivdmFYRmlUL+BmM0q X-Received: by 2002:a05:6830:1498:: with SMTP id s24mr4064672otq.242.1584543978903; Wed, 18 Mar 2020 08:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584543978; cv=none; d=google.com; s=arc-20160816; b=oxHxPFNLgrOAK3M4/PsTA2I9xF3RHSzglaV9bUBP0hDybD8CrbHNvkAGqNNDemwEXa /ZqftJj407g/IuQeykcfp/pYz4pDDB8mzO7kAbNwpzSfKVHuHx8ekLxHrI+lHIQ4eUJm 5zPzZAIMR0cnx7lkLQWGPQ+kC2WlSdTeo6bNOiJ555TzySNRlG2/hpVivyT56XA7S1HT VS48BVYdQZ+uyMqv523+DBp8QEQ8H6Z3kimpwbtw+BM2ZQ/ywabhEFDoMEHtU0mgYxZw BWqmYRGE0NAXdTpwpMUhKfpKbBUU2pdz6dL4iGm/vGdgKePi9P4cTiCAjZD+l94saTQo LFXg== 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:dkim-signature; bh=GYqs55E1Ag/7cWCZRLCD3SOlOYIsSxXI9S5iSV593oI=; b=gZ9Zpp0QIUDTu6/cV7xru0EzcxJP+6DfM8jq6fqugELB58QZu1kFeVEM+NkGQHXa62 13gSqqyr+reKTnKFYoISnKsuagMQCJbgnPL7E7uiZMr2JCb/PzpZic8mEAwOXk0zKmL9 wBajR5EZ0elaO4YMW8AfmB6LwnplqLUBVjvxzBx4fI+Z4EOEdG1xSP/5hjnpZP9AllYd Y0IznMo6ChxT08DDTTI3WvW2RKJ/BDaTR4Fa3o2+mK7TlYFyVLp2LeIEJcDr+gWP8FHr 4P1GgRSYN/hn2wM5nSYKOjHrLPXWKacE4ekmeVddDJZp6yCj7bSXoBeOJ6VQ+rDKxxJt XDEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GpesNmLm; 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=pass (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 m4si4077845otn.175.2020.03.18.08.06.01; Wed, 18 Mar 2020 08:06:18 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GpesNmLm; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727291AbgCRPE4 (ORCPT + 99 others); Wed, 18 Mar 2020 11:04:56 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:50531 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727280AbgCRPEz (ORCPT ); Wed, 18 Mar 2020 11:04:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584543894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GYqs55E1Ag/7cWCZRLCD3SOlOYIsSxXI9S5iSV593oI=; b=GpesNmLmqhRyb8zyTtMWsV+6jADGYj2sX5Clb6PPn3RCiIfhz1ggD88uDhql7PdoAiuDDs JETa+yKuOIdtGcxbQTZXhE1JxPaHaHEggeH51j+oTXmE/1r3y486/lN67N2GlaBgb+GgON 1brhMiwDTPjycSUgxmIr1VL16h8I8cY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-8--qGXNCO2NCm-jRDcZi9q9A-1; Wed, 18 Mar 2020 11:04:51 -0400 X-MC-Unique: -qGXNCO2NCm-jRDcZi9q9A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3BA7107ACC7; Wed, 18 Mar 2020 15:04:49 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-113-126.rdu2.redhat.com [10.10.113.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 150B960BEC; Wed, 18 Mar 2020 15:04:46 +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/17] selinux: Implement the watch_key security hook [ver #5] From: David Howells To: torvalds@linux-foundation.org, viro@zeniv.linux.org.uk Cc: Stephen Smalley , dhowells@redhat.com, casey@schaufler-ca.com, sds@tycho.nsa.gov, nicolas.dichtel@6wind.com, raven@themaw.net, christian@brauner.io, andres@anarazel.de, jlayton@redhat.com, dray@redhat.com, kzak@redhat.com, keyrings@vger.kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 18 Mar 2020 15:04:46 +0000 Message-ID: <158454388633.2863966.17799427202351674141.stgit@warthog.procyon.org.uk> In-Reply-To: <158454378820.2863966.10496767254293183123.stgit@warthog.procyon.org.uk> References: <158454378820.2863966.10496767254293183123.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.21 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.12 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 1659b59fb5d7..2c19ac4d7894 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6563,6 +6563,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 @@ -7078,6 +7089,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