From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AF30C433E0 for ; Fri, 8 Jan 2021 21:24:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2172F23A9C for ; Fri, 8 Jan 2021 21:24:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2172F23A9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 461DB8D01AE; Fri, 8 Jan 2021 16:24:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 412D38D01AC; Fri, 8 Jan 2021 16:24:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 328AB8D01AE; Fri, 8 Jan 2021 16:24:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 1C41A8D01AC for ; Fri, 8 Jan 2021 16:24:12 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CE2E4824556B for ; Fri, 8 Jan 2021 21:24:11 +0000 (UTC) X-FDA: 77683885902.12.time26_2b0374e274f6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id A8EAD1801B775 for ; Fri, 8 Jan 2021 21:24:11 +0000 (UTC) X-HE-Tag: time26_2b0374e274f6 X-Filterd-Recvd-Size: 8453 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Jan 2021 21:24:11 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id h205so26289261lfd.5 for ; Fri, 08 Jan 2021 13:24:10 -0800 (PST) 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=+afgHAtxhrr/i0EcynJ2CYFaHfGmcyOTzMQ7jRJw+34=; b=EWLV5/5BkInHF7B8SUxiUYVtKJo/pNuo44Gb8xnDt/w4FZxPLZ8xfTzdWYJMrAW/+a +LaIs19proJuaO55Kb6fm7+XwoBa0RSfdRj8CDpynFu+mvinLspy6QaPnJmyHZCXTpRH 2tzjQhNaKzXG/hsIDyZN7dp+K0bG1Q1yOxvrbLQMQADxtmON3+FCqM6CvATijn69lpXO 9g32ONk0kwEuiJ0f1/C+jgSCoxih3JnKyx8TQtMjyO0q7RmPmAItIL9AGhHuI+nVQ7dC YcfRN5oyxzE08hOUyju+DpHfnCLTyQYxz1HZ/Bv9mXci8/QpfnGPzGuEyGXWQbe/uGW3 58vg== 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=+afgHAtxhrr/i0EcynJ2CYFaHfGmcyOTzMQ7jRJw+34=; b=gEZr9jopXazBoIEQSv8jw3N6rK1jjUpLQG2vxeuw9g6DL9wCiFm++GX8ki9wfBEzXZ x4G5Z9o178gNDm9OjyPoFRKlGN228JuV/BnC3LOSMNxx7GJ9jckj5iWP5YsObq8pLK5v sHlfIPYt99IIrgfw0KeCgfhYVwtnkdlFWROP0sIDTwlUpux8ARz+kg8wGJCJqI1dUawN CiAKoW6w9pV1fYrJcgLG3iSTCogvCWSYvyuapmR9zCEq6eeEMpZORxKA76PPPU3w4O83 mnnLlikY/gU4el8odyudvbIOW0OSvBx8+YZvYctfc8qyK0LPCTT9WfWvZ04EHVFN9vC8 U7pw== X-Gm-Message-State: AOAM533slM1Qv3XoSUOw5rOoHlVrVYTpeaD9+iGx+B+y2f5SD8G1njr/ ul7XqA1xzqRqZFFfQ/+ychyxU41n2YpaFp4vic4= X-Google-Smtp-Source: ABdhPJw0Nu906p07vhl6IlMcKRUd1QVarTQZeVS6m9q64qCsKOGolBZa7QCJCdGe5JoJ7BqKGChStMaECN6aBDppJQc= X-Received: by 2002:a19:6b0e:: with SMTP id d14mr162388lfa.210.1610141049528; Fri, 08 Jan 2021 13:24:09 -0800 (PST) MIME-Version: 1.0 References: <20201112015359.1103333-1-lokeshgidra@google.com> <20201112015359.1103333-4-lokeshgidra@google.com> In-Reply-To: From: Stephen Smalley Date: Fri, 8 Jan 2021 16:23:58 -0500 Message-ID: Subject: Re: [PATCH v13 3/4] selinux: teach SELinux about anonymous inodes To: Lokesh Gidra 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.