From patchwork Thu Nov 12 01:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 11898869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCB80139F for ; Thu, 12 Nov 2020 01:54:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B7A520791 for ; Thu, 12 Nov 2020 01:54:11 +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="SQyRpCsk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B7A520791 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 6BB8C6B0068; Wed, 11 Nov 2020 20:54:10 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 643066B006C; Wed, 11 Nov 2020 20:54:10 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BF386B006E; Wed, 11 Nov 2020 20:54:10 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 1C9CA6B0068 for ; Wed, 11 Nov 2020 20:54:10 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C14411EE6 for ; Thu, 12 Nov 2020 01:54:09 +0000 (UTC) X-FDA: 77474095818.10.gold45_4b1688627302 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 9DEEC16A07E for ; Thu, 12 Nov 2020 01:54:09 +0000 (UTC) X-Spam-Summary: 1,0,0,66d8a422ecda5f83,d41d8cd98f00b204,3wjwsxwskckemplftihjesbhpphmf.dpnmjovy-nnlwbdl.psh@flex--lokeshgidra.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:2892:2894:2899:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3871:3874:4119:4250:4321:4385:4398:4605:5007:6117:6119:6120:6261:6653:6742:6743:7901:7903:8568:9969:10004:11026:11473:11658:11914:12043:12048:12114:12296:12297:12438:12555:12895:12986:13138:13161:13229:13231:14096:14097:14181:14394:14659:14721:21080:21433:21444:21451:21627:21990:30029:30054:30070:30075,0,RBL:209.85.219.202:@flex--lokeshgidra.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yf64pfn1o3qtepg45ncq5qdd6e8ycgkmkk3w5nf7e7637sgwns9wytk97h3kb.wdtwcufzmcwamgjwwg9euwswzj65a3a6a9ofh1iwmfpen1n4at7rib7e9zcsxej.r-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0 .5,0.5,N X-HE-Tag: gold45_4b1688627302 X-Filterd-Recvd-Size: 8665 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Nov 2020 01:54:09 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id v12so4272396ybi.6 for ; Wed, 11 Nov 2020 17:54:09 -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=c9Og5DC1k1cUQRw8CGbu3hvhZccACMgaVukw9TXsnBk=; b=SQyRpCskDDQyjOj6Y7KQvyf3aH7p5CeESVkOzrwBVOw1wcZF5i6plpZZMnli4dRCk7 KoIwO3P2UyZnp6UypXtHWy5M2Dap/44fsRQwyPpwXGdkVenFWanSIFIsv8SGfQcvEbdD o3eZGOw8xs9KPTNqy27mnkEv64rarQjcTaWJnxSDIWKqLGZwr5qem3oI89F0v3cxeyAU j/PhrDuI/dRIqJ5zGSIoLc1kEtTjSQdSW91Q0HjlOPZvrgj3pxvwZiNTwhAZwfq7bafH 2sxTzHwcbexnyW7lTYQKJQZnTscocjiFdeH1tr0iAXvu/jrYNsRGNcaV10CkQ6IUrf/I 8iBA== 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=c9Og5DC1k1cUQRw8CGbu3hvhZccACMgaVukw9TXsnBk=; b=mSII/ycSdUfMwUUm0hxX4AG/+0kY1J4qec3jGKZDwECw/GCjpzORbjpejU+3CBp9mL sle5NKSfILh6EZ7p85byQM8wMXvIamNbSn01fugawi2dLgFlJvQDvChqnnPHxi6u69Rx LIEVLpc6iQRX1HmTmwavUMUj97RNwCP4fNXOpYP9qY4g2HAUvUvYuY5QjTLfJEbB9dn2 IMoovpQRz/N9zaPNoGtkt1p0lMn2ly35lZVpvJydObeC2iTm0c9xKowKPGRQXtwPEiqq SlRCrO8NJWvRFg5giIwStA5XPkCRNE4EW9fpUyOmHLwUpbYWA1Gq0Igft3Mv5pthnqFY Nruw== X-Gm-Message-State: AOAM530y+uBFdweO1MC/e2qaLhPoM4sPACq0dGi7/O0v9S8WbRd1RUM7 Gevgp/l8C1Luv6J6AyK/yluEadTGfWiFAzWKzg== X-Google-Smtp-Source: ABdhPJwbEExJZLbWaATpLGAop1r2dI05u8VEsbPmkQZCo1UtYBTDWpESrtyVB/fsRM0ZspxgBdPVqcsf9LpufrRfvw== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:f693:9fff:fef4:29dd]) (user=lokeshgidra job=sendgmr) by 2002:a25:5702:: with SMTP id l2mr38652087ybb.184.1605146048341; Wed, 11 Nov 2020 17:54:08 -0800 (PST) Date: Wed, 11 Nov 2020 17:53:56 -0800 In-Reply-To: <20201112015359.1103333-1-lokeshgidra@google.com> Message-Id: <20201112015359.1103333-2-lokeshgidra@google.com> Mime-Version: 1.0 References: <20201112015359.1103333-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH v13 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 , Paul Moore Cc: "Serge E. Hallyn" , Eric Paris , Lokesh Gidra , 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-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, jeffv@google.com, kernel-team@android.com, linux-mm@kvack.org, Andrew Morton , hch@infradead.org, Eric Biggers 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 hook allows/denies its creation and assigns a security context to the inode. 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. This context_inode's security_context can also be used to initialize the newly created anon-inode's security_context. Signed-off-by: Lokesh Gidra Reviewed-by: Eric Biggers --- 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)