Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1149868pxk; Mon, 31 Aug 2020 11:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTaC7aMhP6oxQWBjVIxPAT+OHuPUqbXp+j2GEmst4tcyHLoJaVQQPpFEAOljPttks1R87A X-Received: by 2002:a50:e109:: with SMTP id h9mr2274270edl.47.1598897298849; Mon, 31 Aug 2020 11:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598897298; cv=none; d=google.com; s=arc-20160816; b=RfbuVxLNif1kbGDdmNaCpEvhNt75bzHmXj+ZEW7FNKJHtavDtr0cyl7AazJrFKiVJZ 1fH4kcIQE1cDegypx1dJnkXckBpG3nc4j9JZIUSmY5JTOfrioNbNzhUq/SmK0AaSpCRt PdtFLKuzVVTTInUr9iKkT5R9O1/sO4mxIf/0QKCcAqZQwjt6XEUUuema6o81lMw9BdY0 hw0tG2hzQoltIXytiPce3uqLsK5oAXXbg/VWZdQ69eijjAcBxawbnY3k1iaJMp5eBqSz qozt+J7SB1ruG/OP4M5Ra/Nl+b7/fyFS5RQrUICeweXbX1V7uC4cbIUwFjjL2xSmiIaU 38rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fB2hgS86VUCnF7yNZR4pCTgsV4Yb+eIpZMc0LiTgDLY=; b=yZg6qtSE1SDw9RkuoejfAqaJXmj8wtiqrP9Wr0n/HVoj4zebwt/cPrFSpAIidQmVCx MCUgA/Cg2wgv2kJci/z/DmqSF1evHrxJM9Oa9vu3uR/l0E1yKq4wCuApSeMQbx0/JFNH PX/oyapNKU/rEBuDgrKiJX9m5A9B+o2NEr0e+Es4bwE8nnthbZirC1tH52aGGE6I4mId VaRFpMT1VDc48h4aKg2ExQ8KebGqQ3LhtwrPK1b6jjE2MQUl2GJj9v7kUor/7fwZhHIT GjcjCyQvnMxCrICMQ9wXWgc74bSbTN5IFtQek7+ORx+O2JJfrpbK0gNDG7pximQqLA2l Sm8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hzvT2JPT; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si5663856edq.93.2020.08.31.11.07.56; Mon, 31 Aug 2020 11:08:18 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=hzvT2JPT; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729016AbgHaSGA (ORCPT + 99 others); Mon, 31 Aug 2020 14:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbgHaSFy (ORCPT ); Mon, 31 Aug 2020 14:05:54 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8217DC061573; Mon, 31 Aug 2020 11:05:54 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id e6so1750504oii.4; Mon, 31 Aug 2020 11:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fB2hgS86VUCnF7yNZR4pCTgsV4Yb+eIpZMc0LiTgDLY=; b=hzvT2JPT7Uk5rs2pbVB21bPgFFEF7nl+1cdFbDyOubsOI8kRapf0yRczK5zfxfWg4w zLYki7oh7AjCbHtDkh+qhTqyyjl2ZQDn60e5MmElvBWynA4feKWOwgappr263RlgQCFm 2mWVvItWhFIIiv6wMyZ5Za+t174ujMTyVU0tum1LMZpuHO14ymMGvqQhe13d/YCMCuyD 4hkfT/gJVeBAvVVBpuk0M+oaKIUmcFdssTihaHBnwnXO07S12/uWt16J9yt1PlRHkN7I pzVVxp2WrvqT2UeMooZYmQ28bvebX59rDL6lxsYhu2EvqHXCi6IOOCYYJi+ANSK86sLu HjIw== 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=fB2hgS86VUCnF7yNZR4pCTgsV4Yb+eIpZMc0LiTgDLY=; b=qMf46AioisVhEp7He3MHs+6rcU1l489waYQq59bdfdraSamnlW9qGQrIysuX1XXYbD hmHjQCz+Mv6SwJCEvwbcwFHoqpKY+qxUyaoPmZUu9RrD5bhI5K+Ql8aTltwPPk2lTOud foSMtQMurMuIXvgc6YWtAZ9AbQypAj2G+ZW+UuVl+Mz0DD0ode85+30QwjS/qBPrpKOd uKEt+Z8kyvLGj+Zp3qSaOfkd0m93bhu/2cIfQT9wJYxe6ZLVw0bySDIOc4Sfl497DIo9 aoNsytXruqBa2BQSYjZBtGQeF/Gu7Y+EEB5vZOVH4Y5Eye/OzD4Oa3d1w3+vfeCvUzHp 0uTA== X-Gm-Message-State: AOAM530zyaIZJkGxmVqOasOyRz7F0nzp3W9YENqbrOLEI6uubwmSEDaI 2hDvaQHh3/1yPiBkn4zal2HY9ROFXc4YVMbE6So= X-Received: by 2002:aca:4007:: with SMTP id n7mr328835oia.160.1598897153903; Mon, 31 Aug 2020 11:05:53 -0700 (PDT) MIME-Version: 1.0 References: <20200827063522.2563293-1-lokeshgidra@google.com> <20200827063522.2563293-3-lokeshgidra@google.com> In-Reply-To: <20200827063522.2563293-3-lokeshgidra@google.com> From: Stephen Smalley Date: Mon, 31 Aug 2020 14:05:43 -0400 Message-ID: Subject: Re: [PATCH v8 2/3] Teach SELinux about anonymous inodes To: Lokesh Gidra Cc: Alexander Viro , James Morris , Casey Schaufler , Eric Biggers , "Serge E. Hallyn" , Paul Moore , 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 FS Devel , linux-kernel , LSM List , SElinux list , kaleshsingh@google.com, calin@google.com, surenb@google.com, Nick Kralevich , Jeffrey Vander Stoep , kernel-team@android.com, Daniel Colascione , Andrew Morton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 27, 2020 at 2:35 AM Lokesh Gidra wrote: > > From: Daniel Colascione > > This change uses the anon_inodes and LSM infrastructure introduced in > the previous patch 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 > Acked-by: Casey Schaufler > Acked-by: Stephen Smalley > Cc: Al Viro > Cc: Andrew Morton > --- > 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 a340986aa92e..b83f56e5ef40 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -2926,6 +2926,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_state.initialized)) This should use selinux_initialized(&selinux_state) instead.