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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 80E77C55179 for ; Tue, 3 Nov 2020 22:00:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12BE92242A for ; Tue, 3 Nov 2020 22:00:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="VqcV4He5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12BE92242A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 923036B006E; Tue, 3 Nov 2020 17:00:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FC036B0070; Tue, 3 Nov 2020 17:00:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C7356B0071; Tue, 3 Nov 2020 17:00:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 486796B006E for ; Tue, 3 Nov 2020 17:00:52 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8ABC7362B for ; Tue, 3 Nov 2020 22:00:51 +0000 (UTC) X-FDA: 77444477502.03.bike71_3513ff6272bc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 5D13328A4E9 for ; Tue, 3 Nov 2020 22:00:51 +0000 (UTC) X-HE-Tag: bike71_3513ff6272bc X-Filterd-Recvd-Size: 8270 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Nov 2020 22:00:50 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id b10so8359917qvl.8 for ; Tue, 03 Nov 2020 14:00:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=DS8C9e64g1Tr1aD0/k+FxGXbkI0cBOsw5SM2h09qao8=; b=VqcV4He5rZhPbQX4UdXbDeXipK4H++sRS1EVizUGZm9yvjtv177iTPjDmaqbzmYi27 N3AbEA1Hm2baXa14J901W6OTAdT0Ll/2YFr/4d9Xk1m8Glz2uXJqn3oTVTC79bHDDR4Q L1kBYrEki1W3En5yRiE9sYbCvRtJwtxiIzeL1kKVR4NiOubBxIRQJAJKh9FF0mls/7VK rvGHXeGpK1fZu8Eri0BQqHW3jyGlIvIHE1TgOiWsGRLjOSQqE/ikmvM6+Aid1/nMoDEi okttAHEX4k6qK/nGlvhqV2BpjPGXaylk1yfdiZ0j+feN+oB+8vQqL6/8N+G4sA2bIhhc /cOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DS8C9e64g1Tr1aD0/k+FxGXbkI0cBOsw5SM2h09qao8=; b=Ht/vhKB1mGHhhdVXsHz7lJdiq8kseJMoDqe7ENP/XbS+cpddTQ4xJgDHtXehso/jdo bRBn+PESRoZUkSFJKE7ouN0rV1cesFbH7rLKTrCaAGOC50174EJyvqqMT8vQQdhhGrUR sjjWsf5/cHPuVs3WAUaSj0NMciRXS9q4Lxphs2szAjv3hCtbgUmbNw7+AvAA4mZOC7Ey F4oDNIQniJG7pvPbW/zclKlImg1OhFzGAFto7Yf6Hy+PF5n5duVAfjczkHjkps8MY2mc HsEu3U7Kr4XuYXx55FOOzXRx4AdJH2HsW8LpMxHULCB0H+bc4KjKef6lQygjLbM1O5E5 Qm6w== X-Gm-Message-State: AOAM5329G7pspbLtFcLcMKuoNMSXY7uwcLE2uOJJrNvST5ii/8DL1Uau QEnO2KFSNd6ETI58IJgIXN/n/j8p6RzRByTdLQ== X-Google-Smtp-Source: ABdhPJyrzHFm37zi4Tt3XNpWXIV1jM5J6gMLqgaBO9Ndnlyc3VBgU7cKH+T8O0BXVmBittkbHtmYM0hDsUPR0gk4XQ== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:f693:9fff:fef4:29dd]) (user=lokeshgidra job=sendgmr) by 2002:ad4:45b4:: with SMTP id y20mr7899379qvu.46.1604440849606; Tue, 03 Nov 2020 14:00:49 -0800 (PST) Date: Tue, 3 Nov 2020 14:00:19 -0800 In-Reply-To: <20201103220020.2399003-1-lokeshgidra@google.com> Message-Id: <20201103220020.2399003-3-lokeshgidra@google.com> Mime-Version: 1.0 References: <20201103220020.2399003-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v10 2/3] Teach SELinux about anonymous inodes From: Lokesh Gidra To: Andrea Arcangeli , Alexander Viro , James Morris , Stephen Smalley , Casey Schaufler , Eric Biggers Cc: "Serge E. Hallyn" , Paul Moore , Eric Paris , Lokesh Gidra , 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, Daniel Colascione , Andrew Morton 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: 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 Signed-off-by: Lokesh Gidra 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..7b22c3112583 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_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; + } 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, + &ad); +} + static int selinux_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode) { return may_create(dir, dentry, SECCLASS_FILE); @@ -6987,6 +7039,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 } }; -- 2.28.0.1011.ga647a8990f-goog