Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6486668ybl; Wed, 15 Jan 2020 05:32:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzq91XY+JBcWizPlTl5P9nITbGJ/SO0FoBzreZ6OHeozvh/+5IzT9d5heQfMyLQnoo7Z+kT X-Received: by 2002:a05:6830:114f:: with SMTP id x15mr2624811otq.291.1579095167411; Wed, 15 Jan 2020 05:32:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579095167; cv=none; d=google.com; s=arc-20160816; b=epemEFu+fAFVtduqEQx4XBA2z3ShC35xIEdcNweCgB3/OqiLp1RkzBtGfupyzxk8GW UFF4xn97YOpKNv1uL2UsaceVvA8VpezNL6mi1rTqZxe/UCMEQB5rM4KrVf0jbm/GnYf1 chG2pv856uG3jAGCs2YzwsTde1c4DTywlPkKSmIRQQoo+7q6STySbzvAr+0RRoeUmmPE 2aew7zxu4L8ilTubm0/2b/aC0Z5SIlWXuFMniL2kUa0SXhzt53Mu0llsgI/TGvpY7HWD kcMpHHDsPBqOvMfdQ/tmVCnkXZjZDTpBeNrU9uAS3Qru5xQNfeoZvEBOQBOz4iBfBL76 C2rA== 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=sdalmPdPxMEBu8xBz15QUCyI0CxOdrt6XvQLFxdky0s=; b=k+/3omJqDYlRgYv5GtryXRZRwbAR+eKR/3GIGv7Vypv2AeSMB+bBwfudljNQdbwX3G nyt6+UPVoNfvriW5EAch1F5azuLlP7MFLC+U1ipIct0VmrTDJNOY/OwdE2MGHslWJYwg c3W+cg+ZBKDLDCt4ys6CiMQWRpDxRQLaY5WsfZUBufpeJt1QWELuwXHL4feoKvS1RcLa BM/WZMrzN+980Dj5Y05x5dN7Nq/hcdO6G+PxTOlhCY2XL2IpfUVDM+tZdgxDxt624cR0 k0HNN0P/I192cWNFH+rQd2FfM7x7/R+tATrXGxc1uRiqlu0/UVFcVuc7nougA0yb1ydK YbWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OsONOqID; 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 f204si8223829oia.43.2020.01.15.05.32.34; Wed, 15 Jan 2020 05:32:47 -0800 (PST) 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=OsONOqID; 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 S1729107AbgAONbN (ORCPT + 99 others); Wed, 15 Jan 2020 08:31:13 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:30063 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729095AbgAONbM (ORCPT ); Wed, 15 Jan 2020 08:31:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579095071; 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=sdalmPdPxMEBu8xBz15QUCyI0CxOdrt6XvQLFxdky0s=; b=OsONOqIDZTdYFqaX+17sm8ixk8pijfsB76/YG9h7+4oTN1txRa85sf8VHGZ6cZGC2Vc3GI QFblUz8GmHrUHNmvdTkz5HUfWEkrAIdWvmS+V3mwwFtsTRn1SQnBi9YUIDpKPfphHahFUb CZw1TJ8g01IBtz7ofz5NTVguCdJK2+E= 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-273-u2-HHscHNP6QHwUvOgoOFg-1; Wed, 15 Jan 2020 08:31:10 -0500 X-MC-Unique: u2-HHscHNP6QHwUvOgoOFg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B15D71005516; Wed, 15 Jan 2020 13:31:06 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-52.rdu2.redhat.com [10.10.120.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66C0910372F3; Wed, 15 Jan 2020 13:31:03 +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 03/14] security: Add a hook for the point of notification insertion [ver #3] From: David Howells To: torvalds@linux-foundation.org Cc: dhowells@redhat.com, Greg Kroah-Hartman , Casey Schaufler , Stephen Smalley , 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: Wed, 15 Jan 2020 13:31:02 +0000 Message-ID: <157909506262.20155.1543413154684187380.stgit@warthog.procyon.org.uk> In-Reply-To: <157909503552.20155.3030058841911628518.stgit@warthog.procyon.org.uk> References: <157909503552.20155.3030058841911628518.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.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a security hook that allows an LSM to rule on whether a notification message is allowed to be inserted into a particular watch queue. The hook is given the following information: (1) The credentials of the triggerer (which may be init_cred for a system notification, eg. a hardware error). (2) The credentials of the whoever set the watch. (3) The notification message. Signed-off-by: David Howells cc: Casey Schaufler cc: Stephen Smalley cc: linux-security-module@vger.kernel.org --- include/linux/lsm_hooks.h | 14 ++++++++++++++ include/linux/security.h | 14 ++++++++++++++ security/security.c | 9 +++++++++ 3 files changed, 37 insertions(+) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 79d7c73676d7..16530255dc11 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1427,6 +1427,12 @@ * Check to see if a process is allowed to watch for event notifications * from devices (as a global set). * + * @post_notification: + * Check to see if a watch notification can be posted to a particular + * queue. + * @w_cred: The credentials of the whoever set the watch. + * @cred: The event-triggerer's credentials + * @n: The notification being posted * * Security hooks for using the eBPF maps and programs functionalities through * eBPF syscalls. @@ -1716,6 +1722,11 @@ union security_list_options { #ifdef CONFIG_DEVICE_NOTIFICATIONS int (*watch_devices)(void); #endif +#ifdef CONFIG_WATCH_QUEUE + int (*post_notification)(const struct cred *w_cred, + const struct cred *cred, + struct watch_notification *n); +#endif #ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect)(struct sock *sock, struct sock *other, @@ -2009,6 +2020,9 @@ struct security_hook_heads { #ifdef CONFIG_DEVICE_NOTIFICATIONS struct hlist_head watch_devices; #endif +#ifdef CONFIG_WATCH_QUEUE + struct hlist_head post_notification; +#endif /* CONFIG_WATCH_QUEUE */ #ifdef CONFIG_SECURITY_NETWORK struct hlist_head unix_stream_connect; struct hlist_head unix_may_send; diff --git a/include/linux/security.h b/include/linux/security.h index 8f2fa100d128..e03ee1164268 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -57,6 +57,8 @@ struct mm_struct; struct fs_context; struct fs_parameter; enum fs_value_type; +struct watch; +struct watch_notification; /* Default (no) options for the capable function */ #define CAP_OPT_NONE 0x0 @@ -1290,6 +1292,18 @@ static inline int security_watch_devices(void) return 0; } #endif +#if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE) +int security_post_notification(const struct cred *w_cred, + const struct cred *cred, + struct watch_notification *n); +#else +static inline int security_post_notification(const struct cred *w_cred, + const struct cred *cred, + struct watch_notification *n) +{ + return 0; +} +#endif #ifdef CONFIG_SECURITY_NETWORK diff --git a/security/security.c b/security/security.c index 578863f230a6..9c1878a7fadf 100644 --- a/security/security.c +++ b/security/security.c @@ -1956,6 +1956,15 @@ int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) } EXPORT_SYMBOL(security_inode_getsecctx); +#ifdef CONFIG_WATCH_QUEUE +int security_post_notification(const struct cred *w_cred, + const struct cred *cred, + struct watch_notification *n) +{ + return call_int_hook(post_notification, 0, w_cred, cred, n); +} +#endif /* CONFIG_WATCH_QUEUE */ + #ifdef CONFIG_KEY_NOTIFICATIONS int security_watch_key(struct key *key) {