Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp620005pxb; Fri, 8 Jan 2021 13:35:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbheDLMLCvNdcHGdevJ5IRF6yHtRqkzXZkOLVVxjd70T2l1kfnoVzYBFII8PScge9pBhzI X-Received: by 2002:a17:906:8151:: with SMTP id z17mr3980560ejw.48.1610141734830; Fri, 08 Jan 2021 13:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610141734; cv=none; d=google.com; s=arc-20160816; b=ty8IUYBwq0NO4JEiu4mw4wNHu7vdd7NWJ/yXgp6pyLylsB6c8KDwkB3I5VAXJE+4kM ns1U3jncGfuITsVDjjJoAvQ3bs5ih+wVCa2vWgr9lhRe9FMgEwK8TgJBR9xfFN0O+MoG w6Tq7f7EXdVzXvwSSYBHeE60gtdjX7FEmMZl5RVwwY8jNU+UuymCJkm2+fsqpiEr7IB1 mWY/+7+l0FQvr7Ke+o6XAxpIQCUOWSStCtSlyzmGcprtOoDmryGA2mLhfU7zdkEKVIAX jbiuE2poruHx48OFMw9kOtVRbV8K+rx18o9oSNjK0QCE71JG7NU1J5CNPC8ZjC7hNrbA lhHg== 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=usABmZbPBqvxIY7U6EdGtDSIYnBKPUAxoopqfJsbtF4=; b=EOjLffGmwr2CSV7WII9xRSdib8lR6avDeGEKVsJb/dTotTtPISsUx9Nh3m1LzApw71 upKu2cTfSQhj0jlUwTIazBGpE5cSRjSAOnGsFqEwaMVZZh/jMfc6IqW93OxeyitPObiH YRL+aqS8BaL56+TDukfT2cAmh36UhclG8UDq2NerYQb8NyHOhQDB3SBYr7QyO1JrFJk0 AOwEm0aixqDrm0S69WlramhpTCxiCgO35Gdy+SojfsmIQlUoJAUG5u35otgKIyxrV28V oXKVy3PmUghKqIHRFUXZtorNRmDJsMOMHi3n4y0IiHqKarklf7SjfIIn7ulepgRMn3G8 0uTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pBGi9wER; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si4015011edt.265.2021.01.08.13.35.10; Fri, 08 Jan 2021 13:35:34 -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=@google.com header.s=20161025 header.b=pBGi9wER; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728720AbhAHVcZ (ORCPT + 99 others); Fri, 8 Jan 2021 16:32:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728420AbhAHVcX (ORCPT ); Fri, 8 Jan 2021 16:32:23 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDE2EC061786 for ; Fri, 8 Jan 2021 13:31:42 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id v26so3653940eds.13 for ; Fri, 08 Jan 2021 13:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=usABmZbPBqvxIY7U6EdGtDSIYnBKPUAxoopqfJsbtF4=; b=pBGi9wERfXy2hax+45WV3pYPQR65fOvZkuo+5mJBYJm6oCBXdlsNQ8MLB2BBZJghLV krg0LeT8dDbheD2uijN7Xt+GmkSuJtHYSwgxWq/ZMwJHgwuur7rw2L4h0Q84fHnxuYNJ BqLkmzGllNp9DvPfiijxoam7DIejfT06c3wqhBqPdvllpbzncL7z7xc3zfkeYvEFM0/y wLRqioz1SjBMUYCnZJZfs2GaQIr7j9B/ZvO5kT1xaSSlgo1x8DGIuqaPmbr921IxGow9 VT3idPThY7BJWa/DhX2K/205uPggSR1O8exx7M439p7jP5pUTCEm50o6MJ2bZAPGa1i1 9JFw== 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=usABmZbPBqvxIY7U6EdGtDSIYnBKPUAxoopqfJsbtF4=; b=i0bvVJWVcfRWMubS0XexXJijhTOJdq4lS89QMEds3zBAxUq+yFdtn/PnsF0Qql2d02 886NZK30pQPvYOW44IgP1o0OLSOjBgYsgWLygG60oThTBjTvQKmy2X7mSd07uCcBYhOh 4mMVYHxexe/gzewgmkENWGciN7xAaFBEvKnEyNY0pRytFl33A3Cida7JfT7Fyyn7crNe lnLoBVOOr1zLknqm+OoP0C7xOjyvsz+2UpfHzGsD+p+fgJJPV/02k2VQs1neVUo7+6OI H5fshNWX1jZCHqtpSbT8fVrOI+yTy/829b3ZR7inc511CeohLNgrf/cL0Ev/gaEva+qW Qe2Q== X-Gm-Message-State: AOAM532Im6vUNntI6909irEwNeZCPHNFajCvVDtRwD0z9IC7D17/f7eM 7s5jvmNHgfxeX6Efgt8bZWM1CfkQc1bwt6hfB9+oRA== X-Received: by 2002:aa7:da03:: with SMTP id r3mr6546470eds.155.1610141501281; Fri, 08 Jan 2021 13:31:41 -0800 (PST) MIME-Version: 1.0 References: <20201112015359.1103333-1-lokeshgidra@google.com> <20201112015359.1103333-4-lokeshgidra@google.com> In-Reply-To: From: Lokesh Gidra Date: Fri, 8 Jan 2021 13:31:30 -0800 Message-ID: Subject: Re: [PATCH v13 3/4] selinux: teach SELinux about anonymous inodes To: Stephen Smalley Cc: Paul Moore , Andrea Arcangeli , Alexander Viro , James Morris , Casey Schaufler , Eric Biggers , "Serge E. Hallyn" , Eric Paris , Daniel Colascione , Kees Cook , "Eric W. Biederman" , KP Singh , David Howells , 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 FS Devel , linux-kernel , LSM List , SElinux list , Kalesh Singh , Calin Juravle , Suren Baghdasaryan , Jeffrey Vander Stoep , "Cc: Android Kernel" , "open list:MEMORY MANAGEMENT" , Andrew Morton , Christoph Hellwig , Daniel Colascione Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 8, 2021 at 1:24 PM Stephen Smalley wrote: > > On Fri, Jan 8, 2021 at 3:17 PM Lokesh Gidra wrote: > > > > On Fri, Jan 8, 2021 at 11:35 AM Stephen Smalley > > wrote: > > > > > > On Wed, Jan 6, 2021 at 10:03 PM Paul Moore wrote: > > > > > > > > On Wed, Nov 11, 2020 at 8:54 PM 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 | 56 +++++++++++++++++++++++++++++ > > > > > security/selinux/include/classmap.h | 2 ++ > > > > > 2 files changed, 58 insertions(+) > > > > > > > > > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > > > > > index 6b1826fc3658..d092aa512868 100644 > > > > > --- a/security/selinux/hooks.c > > > > > +++ b/security/selinux/hooks.c > > > > > @@ -2927,6 +2927,61 @@ 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); > > > > > + if (context_isec->initialized != LABEL_INITIALIZED) > > > > > + return -EACCES; > > Stephen, as per your explanation below, is this check also > > problematic? I mean is it possible that /dev/kvm context_inode may not > > have its label initialized? If so, then v12 of the patch series can be > > used as is. Otherwise, I will send the next version which rollbacks > > v14 and v13, except for this check. Kindly confirm. > > The context_inode should always be initialized already. I'm not fond > though of silently returning -EACCES here. At the least we should > have a pr_err() or pr_warn() here. In reality, this could only occur > in the case of a kernel bug or memory corruption so it used to be a > candidate for WARN_ON() or BUG_ON() or similar but I know that > BUG_ON() at least is frowned upon these days. Got it. I'll add a pr_err(). Thanks a lot.