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, USER_AGENT_GIT autolearn=unavailable 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 F263AC56201 for ; Thu, 5 Nov 2020 21:33:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6154720867 for ; Thu, 5 Nov 2020 21:33:33 +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="iBnclI64" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6154720867 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 BBDB86B01A4; Thu, 5 Nov 2020 16:33:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B48AC6B01A5; Thu, 5 Nov 2020 16:33:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A35E86B01A6; Thu, 5 Nov 2020 16:33:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 6F83F6B01A4 for ; Thu, 5 Nov 2020 16:33:32 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0F5F7181AEF00 for ; Thu, 5 Nov 2020 21:33:32 +0000 (UTC) X-FDA: 77451666264.22.beef50_5011f9c272cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id DD4FF18038E68 for ; Thu, 5 Nov 2020 21:33:31 +0000 (UTC) X-HE-Tag: beef50_5011f9c272cd X-Filterd-Recvd-Size: 8437 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 21:33:31 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id o135so3151635ybc.16 for ; Thu, 05 Nov 2020 13:33:31 -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=JxEU6nxtnscWTRV4NP6TUtkxst/drXUYmjzv3EN+9u0=; b=iBnclI64wiVtr6uywUdrU0+21va32D2OtQfGCmrfMewTcS5cWDULSljgoALK2XhnN0 6Tsl1vvqRrGGoJPXOloUQWGSig/XtkZVYtJ1Sx9i7zobZOpoJx6sMo7t2D7cMbPFkFeA BN8z8JH4wdIejzySSmx0Y87eeE1zagxbjWu410f9jojLgU+MAooGkpCWO+JIIi+uScyN wzWXjOHcPijU6EKI2V8sQXsBuqmMvGJFmg32m8dO7wlfowA5Bv4YJZE69k3AJRKBRKV1 c3ZxhjApPOlpWYOO4GK50khT6vtl+8LbkBosKd/UoZ3RismUD5rO62F6GWpeuBDHB5rk /1Tg== 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=JxEU6nxtnscWTRV4NP6TUtkxst/drXUYmjzv3EN+9u0=; b=rVOzNwI+RjU4hbsM6/qdAVZaiGpxrON1aXM5X23iDkArpiCMiwVYm2HDcQZassmvwi AdZeGmGVdi//AYyoXUijaq5CCqaed3SzVzmrf3S8jteKrOpfaehvWV0EEHi7U3eetiJl Pg0eL2VKMWsQwyJjGPG5mrG/xpejqGMTwTio1f6QroqZJEhthiN00oEaWwNtO0X3UDGq LtCYyBlpwbYevhWNhO90j+XYbKNp6W5/X1jpwihU07cCh1kBKSXW4dCTvZhAWDTcMdAC UTKo3fDfTWqhqqt8/seOJYvQTYvXvwYe5+rlwNhXSVF8wDhNkFd8ahO3IenQ8G+hTXo3 pLhA== X-Gm-Message-State: AOAM532u/inzDAD1Ssr+G3jI7Y3qJsXgCetI42QoPeMJM6pm0k87O0tn t3Ayc5sn1D3GQjsnqeMkpsR5tFEuZVK9WGDmXg== X-Google-Smtp-Source: ABdhPJxp4ud9F0XXGnk+/NPkc07vMWY3+QWHWoqCKr56ocLP9D9oQC4SU34vx5k14AEBaTpFOkEx5r7EVhkJwmj6Rg== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:f693:9fff:fef4:29dd]) (user=lokeshgidra job=sendgmr) by 2002:a25:9c02:: with SMTP id c2mr6112707ybo.228.1604612010473; Thu, 05 Nov 2020 13:33:30 -0800 (PST) Date: Thu, 5 Nov 2020 13:33:21 -0800 In-Reply-To: <20201105213324.3111570-1-lokeshgidra@google.com> Message-Id: <20201105213324.3111570-2-lokeshgidra@google.com> Mime-Version: 1.0 References: <20201105213324.3111570-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v11 1/4] security: add inode_init_security_anon() LSM hook 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, Andrew Morton , hch@infradead.org 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: This change adds a new LSM hook, inode_init_security_anon(), that will be used while creating secure anonymous inodes. The new hook accepts an optional context_inode parameter that callers can use to provide additional contextual information to security modules for granting/denying permission to create an anon- inode of the same type. Signed-off-by: Lokesh Gidra --- include/linux/lsm_hook_defs.h | 2 ++ include/linux/lsm_hooks.h | 9 +++++++++ include/linux/security.h | 10 ++++++++++ security/security.c | 8 ++++++++ 4 files changed, 29 insertions(+) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 32a940117e7a..435a2e22ff95 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -113,6 +113,8 @@ LSM_HOOK(void, LSM_RET_VOID, inode_free_security, struct inode *inode) LSM_HOOK(int, 0, inode_init_security, struct inode *inode, struct inode *dir, const struct qstr *qstr, const char **name, void **value, size_t *len) +LSM_HOOK(int, 0, inode_init_security_anon, struct inode *inode, + const struct qstr *name, const struct inode *context_inode) LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry, umode_t mode) LSM_HOOK(int, 0, inode_link, struct dentry *old_dentry, struct inode *dir, diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index c503f7ab8afb..3af055b7ee1f 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -233,6 +233,15 @@ * Returns 0 if @name and @value have been successfully set, * -EOPNOTSUPP if no security attribute is needed, or * -ENOMEM on memory allocation failure. + * @inode_init_security_anon: + * Set up the incore security field for the new anonymous inode + * and return whether the inode creation is permitted by the security + * module or not. + * @inode contains the inode structure + * @name name of the anonymous inode class + * @context_inode optional related inode + * Returns 0 on success, -EACCES if the security module denies the + * creation of this inode, or another -errno upon other errors. * @inode_create: * Check permission to create a regular file. * @dir contains inode structure of the parent of the new file. diff --git a/include/linux/security.h b/include/linux/security.h index bc2725491560..7494a93b9ed9 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -323,6 +323,9 @@ void security_inode_free(struct inode *inode); int security_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr, initxattrs initxattrs, void *fs_data); +int security_inode_init_security_anon(struct inode *inode, + const struct qstr *name, + const struct inode *context_inode); int security_old_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr, const char **name, void **value, size_t *len); @@ -737,6 +740,13 @@ static inline int security_inode_init_security(struct inode *inode, return 0; } +static inline int security_inode_init_security_anon(struct inode *inode, + const struct qstr *name, + const struct inode *context_inode) +{ + return 0; +} + static inline int security_old_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr, diff --git a/security/security.c b/security/security.c index a28045dc9e7f..8989ba6af4f6 100644 --- a/security/security.c +++ b/security/security.c @@ -1058,6 +1058,14 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, } EXPORT_SYMBOL(security_inode_init_security); +int security_inode_init_security_anon(struct inode *inode, + const struct qstr *name, + const struct inode *context_inode) +{ + return call_int_hook(inode_init_security_anon, 0, inode, name, + context_inode); +} + int security_old_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr, const char **name, void **value, size_t *len) -- 2.29.1.341.ge80a0c044ae-goog