Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3691279pxb; Mon, 9 Nov 2020 19:14:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+JfoMWR2CYo/9zq57fsNXi1wH5OH2Rxazm0U25WfSoL02X/Htzp+eaj6r6aFSUrtKbPxM X-Received: by 2002:a50:cf82:: with SMTP id h2mr13173810edk.142.1604978076838; Mon, 09 Nov 2020 19:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604978076; cv=none; d=google.com; s=arc-20160816; b=w1uV4kGQocQdvlMwNimJ3qpIICY2sXm7DF8axtyIa91BPCPmwddVUApWORVJVd74ye 4lCivdsEV3tO7x+1F8muYEL2vtggUU+HhZVllnH9lQX8zusqaWMUAyoPfuM91/tQJN5B 9ISFOrce8Zr+OIU12KqYudtxLrsP1iDCISFNXoTkWDTALFNKaofoGKx3WJncEgpt2Hhk LAa6tO7I/MwvX+7QhB19vrSeoO7mvHWu0qwUAcCrFFyUocHtPNA6xcPMWaLy0Oo810o/ 3LgK1zHUtkcdhEOAy6frhXDrErx6g5AB4cHKyI/NGfgOtPCmMSbStv/CKIqRxda38BBN NDaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xzmJsWC6dWZQj1XvWO6xJYEz8vIsIxpieR4F7Jap3XY=; b=WF7CWGSmRybEY3E5exU7Bn5CJ1UzeH6i/xUpHc1yHngFP56+uWH3natz5HerKuQZxM /FTvlJVyf27lq8YZ70ZRzVpjk+dNcVhthGw1sFDbPuyO36tYxOZn5JL5JC/PBH5erCPf tFkOTV88xeA5imyO53PBjPzRsCDjyObWTR/bdInCaYF/7zi4tZEb8vbf08SDoMWT4ZXE 3XO1OR+bV83dQdR9uhevoF8Vf/x+HpNpjfU37lT270gplpFGyiT1vlkIbkDUlu/ON+aV AJrQO3nfHfIA1p9fuwL0kffDcqW3V+lAMSw2kxbs0y+HX6DPPip3wA+GKD/DnwXiYShO e7QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=dxZP5Lur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp1si9215783ejc.167.2020.11.09.19.14.13; Mon, 09 Nov 2020 19:14:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=dxZP5Lur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730581AbgKJDMu (ORCPT + 99 others); Mon, 9 Nov 2020 22:12:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729454AbgKJDMs (ORCPT ); Mon, 9 Nov 2020 22:12:48 -0500 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBBBBC0613D6 for ; Mon, 9 Nov 2020 19:12:46 -0800 (PST) Received: by mail-ej1-x643.google.com with SMTP id oq3so15359460ejb.7 for ; Mon, 09 Nov 2020 19:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xzmJsWC6dWZQj1XvWO6xJYEz8vIsIxpieR4F7Jap3XY=; b=dxZP5LurjoMY+67L6FJnXmxEHoYPw16qhZAeOyWG1ERPn886+jasIPgXr/LCZ57Mps Isrxb9tNDyGDxpGtiHj+f3ObDkYNk1lcDzVOMJTkdsVyy69uePT5mT6b2prUhBEMf024 ZNmPI5b/9pt22TjuKOK87RYl1qeaY7H7dDPx+F1W5i84695rG+cWGjtTREBoaZu3K95S /h81TSnDH8J9EozxG6K23XEfvG23QiG3MgIk3K6fv0sLD6LIA7YnvdtHeZPAxNUjFgoo yrIRf9S9ue3GKiGjICrWDc7M+Yo0DoY1r1tx6/iSYoWEd/TIccktxDGww6KuTXOg4gR2 nwfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xzmJsWC6dWZQj1XvWO6xJYEz8vIsIxpieR4F7Jap3XY=; b=oqjjtGJ2RIDwm2sAgI8FhJq20g9x3GZhoQV7NaLC0q0UdwfGk9fOL+R0R2M4WTaE+m H6P16zIOAeLpqcbC316ttmepTPMRVEihpr3zfnQhIcOyDqaK+8/HbOj4zm4dG7NaLPxP Gt1rAgBwK0elIQ/5oXxBDVPaXmmHEdTf9FyqZZfjoegRHpsylCvX2QMdAnTeHCIqg9Rf GQjRQak6T9EscsV0M+2mK0OlrwrYSoOvVrOZr2NSSPIB5LMJ2XA0g3GMRrBWs90Z+wxK PgZqW6LWTHqvA2xSWn1JzPI4sn/OmlJW62zjET9drC4QEuM4dZgWdsXB6XO64jrQ+F+9 8dqA== X-Gm-Message-State: AOAM532Elis/Qrysm9Ar4fRiyEVVlRqvf9ARpj1JZHxK44VUxu7fnrAN t7l2cgZNlYcpipeZ6EeHL0jhUKJ6KjmmLeZt+g6r X-Received: by 2002:a17:906:c096:: with SMTP id f22mr17581308ejz.488.1604977965148; Mon, 09 Nov 2020 19:12:45 -0800 (PST) MIME-Version: 1.0 References: <20201106155626.3395468-1-lokeshgidra@google.com> <20201106155626.3395468-4-lokeshgidra@google.com> In-Reply-To: <20201106155626.3395468-4-lokeshgidra@google.com> From: Paul Moore Date: Mon, 9 Nov 2020 22:12:33 -0500 Message-ID: Subject: Re: [PATCH v12 3/4] selinux: teach SELinux about anonymous inodes To: Lokesh Gidra Cc: Andrea Arcangeli , Alexander Viro , James Morris , Stephen Smalley , Casey Schaufler , Eric Biggers , "Serge E. Hallyn" , Eric Paris , Daniel Colascione , Kees Cook , "Eric W. Biederman" , KP Singh , David Howells , Thomas Cedeno , Anders Roxell , Sami Tolvanen , Matthew Garrett , Aaron Goidel , Randy Dunlap , "Joel Fernandes (Google)" , YueHaibing , Christian Brauner , Alexei Starovoitov , Alexey Budankov , Adrian Reber , Aleksa Sarai , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, kaleshsingh@google.com, calin@google.com, surenb@google.com, nnk@google.com, jeffv@google.com, kernel-team@android.com, linux-mm@kvack.org, Andrew Morton , hch@infradead.org, Daniel Colascione Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 6, 2020 at 10:56 AM Lokesh Gidra wrote: > > From: Daniel Colascione > > This change uses the anon_inodes and LSM infrastructure introduced in > the previous patches to give SELinux the ability to control > anonymous-inode files that are created using the new > anon_inode_getfd_secure() function. > > A SELinux policy author detects and controls these anonymous inodes by > adding a name-based type_transition rule that assigns a new security > type to anonymous-inode files created in some domain. The name used > for the name-based transition is the name associated with the > anonymous inode for file listings --- e.g., "[userfaultfd]" or > "[perf_event]". > > Example: > > type uffd_t; > type_transition sysadm_t sysadm_t : anon_inode uffd_t "[userfaultfd]"; > allow sysadm_t uffd_t:anon_inode { create }; > > (The next patch in this series is necessary for making userfaultfd > support this new interface. The example above is just > for exposition.) > > Signed-off-by: Daniel Colascione > Signed-off-by: Lokesh Gidra > --- > security/selinux/hooks.c | 53 +++++++++++++++++++++++++++++ > security/selinux/include/classmap.h | 2 ++ > 2 files changed, 55 insertions(+) > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > index 6b1826fc3658..1c0adcdce7a8 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -2927,6 +2927,58 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, > return 0; > } > > +static int selinux_inode_init_security_anon(struct inode *inode, > + const struct qstr *name, > + const struct inode *context_inode) > +{ > + const struct task_security_struct *tsec = selinux_cred(current_cred()); > + struct common_audit_data ad; > + struct inode_security_struct *isec; > + int rc; > + > + if (unlikely(!selinux_initialized(&selinux_state))) > + return 0; > + > + isec = selinux_inode(inode); > + > + /* > + * We only get here once per ephemeral inode. The inode has > + * been initialized via inode_alloc_security but is otherwise > + * untouched. > + */ > + > + if (context_inode) { > + struct inode_security_struct *context_isec = > + selinux_inode(context_inode); > + isec->sclass = context_isec->sclass; > + isec->sid = context_isec->sid; I suppose this isn't a major concern given the limited usage at the moment, but I wonder if it would be a good idea to make sure the context_inode's SELinux label is valid before we assign it to the anonymous inode? If it is invalid, what should we do? Do we attempt to (re)validate it? Do we simply fallback to the transition approach? > + } else { > + isec->sclass = SECCLASS_ANON_INODE; > + rc = security_transition_sid( > + &selinux_state, tsec->sid, tsec->sid, > + isec->sclass, name, &isec->sid); > + if (rc) > + return rc; > + } > + > + isec->initialized = LABEL_INITIALIZED; > + > + /* > + * Now that we've initialized security, check whether we're > + * allowed to actually create this type of anonymous inode. > + */ > + > + ad.type = LSM_AUDIT_DATA_INODE; > + ad.u.inode = inode; > + > + return avc_has_perm(&selinux_state, > + tsec->sid, > + isec->sid, > + isec->sclass, > + FILE__CREATE, I believe you want to use ANON_INODE__CREATE here instead of FILE__CREATE, yes? This brings up another question, and requirement - what testing are you doing for this patchset? We require that new SELinux kernel functionality includes additions to the SELinux test suite to help verify the functionality. I'm also *strongly* encouraging that new contributions come with updates to The SELinux Notebook. If you are unsure about what to do for either, let us know and we can help get you started. * https://github.com/SELinuxProject/selinux-testsuite * https://github.com/SELinuxProject/selinux-notebook > + &ad); > +} > + > static int selinux_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode) > { > return may_create(dir, dentry, SECCLASS_FILE); > @@ -6992,6 +7044,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { > > LSM_HOOK_INIT(inode_free_security, selinux_inode_free_security), > LSM_HOOK_INIT(inode_init_security, selinux_inode_init_security), > + LSM_HOOK_INIT(inode_init_security_anon, selinux_inode_init_security_anon), > LSM_HOOK_INIT(inode_create, selinux_inode_create), > LSM_HOOK_INIT(inode_link, selinux_inode_link), > LSM_HOOK_INIT(inode_unlink, selinux_inode_unlink), > diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h > index 40cebde62856..ba2e01a6955c 100644 > --- a/security/selinux/include/classmap.h > +++ b/security/selinux/include/classmap.h > @@ -249,6 +249,8 @@ struct security_class_mapping secclass_map[] = { > {"open", "cpu", "kernel", "tracepoint", "read", "write"} }, > { "lockdown", > { "integrity", "confidentiality", NULL } }, > + { "anon_inode", > + { COMMON_FILE_PERMS, NULL } }, > { NULL } > }; > -- paul moore www.paul-moore.com