Message ID | 20230724151341.538889-6-roberto.sassu@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1881231vqg; Mon, 24 Jul 2023 08:39:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlFSpcBV/t6VXAj9kXe3H4YdSY3Davle0Bcoy7plhVlrcQsn7N/VB8JGtgfYHhBEmrBJiYpr X-Received: by 2002:a17:906:1c5:b0:988:fb2f:274e with SMTP id 5-20020a17090601c500b00988fb2f274emr9543734ejj.27.1690213143343; Mon, 24 Jul 2023 08:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690213143; cv=none; d=google.com; s=arc-20160816; b=kc4acB0CtYXdkkwl+IPZMiV409FRMYHrY1iwWlQun1TQtg4+oL9Uu6U/Dwhr+G/vvH nsaeZtje05cjHvqkvkB05nGFNw+FWFrLpX1dPsUm/F0mBsofhGG6M/0RTbViqEMD3BLP 5qajHqRachsImRHS5zDD3O5hFcexkaURedvAtPzAHUVuJpiDTXFEj/l8qUXZDbnFXasn V1d4UYNfa3JN9iWhLaVEs5wU7IyYcW5p/rmvDjdW9/3AU1/Vcyo1G1yrnU0Khx2PRS5P Re4pAjNChwzm8PSTUDnF0Og1AkOHI4Tmd8Q776sgOn+9FKKTabjkIkrkqfEJxbGyWPun 27QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=p1t8kNyoaLvZI8oyJeRqI9PLO4T6nlwE4JyeuwRTnv4=; fh=z7vPyysRJOxh1U4ufKlXD98Auu6H+pYIEt5RTGBgBtQ=; b=EV9LNKyYiYxbV28XjjfHvuxlPR/WrD0Ta4WFKkSMsZArQtwaCdamSxw3pQ1BT9K/RE OrxgUpO0iiwHfYN4uBzZD5CaxvhTIHVSlpm+YEkiRJY4KZwxVGFYceT0F1HrBbBY25B5 3LO5Y3TAli/IVU5tD/bZ+ZkFhstjQyyBoHLBJxxjLMZBeRCLX3o+4jDF2R8VSZXrL60z JitiVVaAKxOnzKstVrZzVuLOt1F9RzKJmwScXAxUquM12G0VBLiW9/zTrHzTtN3r6cVc 9QdF4sdJyihfUtiz/09Mdzsc5jP9rFlPZ7W3BGs87NBCLAHncDTKkXljKRzb8F0nD3Ed hdWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qo12-20020a170907212c00b00977e4a1fe32si6486999ejb.539.2023.07.24.08.38.38; Mon, 24 Jul 2023 08:39:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231299AbjGXPT1 (ORCPT <rfc822;kautuk.consul.80@gmail.com> + 99 others); Mon, 24 Jul 2023 11:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbjGXPTL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Jul 2023 11:19:11 -0400 Received: from frasgout11.his.huawei.com (unknown [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1793A19B7; Mon, 24 Jul 2023 08:19:04 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4R8k6l34txz9yGhK; Mon, 24 Jul 2023 23:07:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwCHTlU3lr5kJcTzBA--.28220S7; Mon, 24 Jul 2023 16:18:51 +0100 (CET) From: Roberto Sassu <roberto.sassu@huaweicloud.com> To: casey@schaufler-ca.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Roberto Sassu <roberto.sassu@huawei.com> Subject: [PATCH v2 5/5] ramfs: Initialize security of in-memory inodes Date: Mon, 24 Jul 2023 17:13:41 +0200 Message-Id: <20230724151341.538889-6-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724151341.538889-1-roberto.sassu@huaweicloud.com> References: <20230724151341.538889-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GxC2BwCHTlU3lr5kJcTzBA--.28220S7 X-Coremail-Antispam: 1UD129KBjvJXoW7WrWUKFWkXw13Jry5AF13Jwb_yoW8uw15pF 42qasxGwn5WFZ7Wr1ftF4Uuw1ftayfKr4DJws7Zw17A3Z7Jw1Utr4Syr13CFyfGrW8Gw1S qF45ur45C3W7A3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvKb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AK xVWxJr0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbV WUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF 67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42 IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF 0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAIBF1jj5DcNgAAsG X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_L3,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772316937031687345 X-GMAIL-MSGID: 1772316937031687345 |
Series |
Smack transmute fixes
|
|
Commit Message
Roberto Sassu
July 24, 2023, 3:13 p.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com> Add a call security_inode_init_security() after ramfs_get_inode(), to let LSMs initialize the inode security field. Skip ramfs_fill_super(), as the initialization is done through the sb_set_mnt_opts hook. Calling security_inode_init_security() call inside ramfs_get_inode() is not possible since, for CONFIG_SHMEM=n, tmpfs also calls the former after the latter. Pass NULL as initxattrs() callback to security_inode_init_security(), since the purpose of the call is only to initialize the in-memory inodes. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> --- fs/ramfs/inode.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
Comments
On Mon, 2023-07-24 at 17:13 +0200, Roberto Sassu wrote: > From: Roberto Sassu <roberto.sassu@huawei.com> > > Add a call security_inode_init_security() after ramfs_get_inode(), to let > LSMs initialize the inode security field. Skip ramfs_fill_super(), as the > initialization is done through the sb_set_mnt_opts hook. > > Calling security_inode_init_security() call inside ramfs_get_inode() is > not possible since, for CONFIG_SHMEM=n, tmpfs also calls the former after > the latter. > > Pass NULL as initxattrs() callback to security_inode_init_security(), since > the purpose of the call is only to initialize the in-memory inodes. > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> + Andrew Hi Andrew I'm proposing an extension to initialize the inode security field at inode creation time for filesystems that don't support xattrs (ramfs in this case). The LSM infrastructure already supports setting the inode security field, but only at run-time, with the inode_setsecurity hook. I developed this to do some testing on the Smack LSM, and I thought it could be useful anyway. Casey would need your acked-by, to carry this patch in his repository. I'm not completely sure if you are the maintainer, but in the past you accepted a patch for ramfs. If you have time and you could have a look, that would be great! Thanks Roberto > --- > fs/ramfs/inode.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c > index fef477c7810..ac90ebd9dbd 100644 > --- a/fs/ramfs/inode.c > +++ b/fs/ramfs/inode.c > @@ -102,6 +102,14 @@ ramfs_mknod(struct mnt_idmap *idmap, struct inode *dir, > int error = -ENOSPC; > > if (inode) { > + error = security_inode_init_security(inode, dir, > + &dentry->d_name, NULL, > + NULL); > + if (error) { > + iput(inode); > + return error; > + } > + > d_instantiate(dentry, inode); > dget(dentry); /* Extra count - pin the dentry in core */ > error = 0; > @@ -134,6 +142,15 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir, > inode = ramfs_get_inode(dir->i_sb, dir, S_IFLNK|S_IRWXUGO, 0); > if (inode) { > int l = strlen(symname)+1; > + > + error = security_inode_init_security(inode, dir, > + &dentry->d_name, NULL, > + NULL); > + if (error) { > + iput(inode); > + return error; > + } > + > error = page_symlink(inode, symname, l); > if (!error) { > d_instantiate(dentry, inode); > @@ -149,10 +166,20 @@ static int ramfs_tmpfile(struct mnt_idmap *idmap, > struct inode *dir, struct file *file, umode_t mode) > { > struct inode *inode; > + int error; > > inode = ramfs_get_inode(dir->i_sb, dir, mode, 0); > if (!inode) > return -ENOSPC; > + > + error = security_inode_init_security(inode, dir, > + &file_dentry(file)->d_name, NULL, > + NULL); > + if (error) { > + iput(inode); > + return error; > + } > + > d_tmpfile(file, inode); > return finish_open_simple(file, 0); > }
On Wed, 15 Nov 2023 09:01:52 +0100 Roberto Sassu <roberto.sassu@huaweicloud.com> wrote: > On Mon, 2023-07-24 at 17:13 +0200, Roberto Sassu wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > Add a call security_inode_init_security() after ramfs_get_inode(), to let > > LSMs initialize the inode security field. Skip ramfs_fill_super(), as the > > initialization is done through the sb_set_mnt_opts hook. > > > > Calling security_inode_init_security() call inside ramfs_get_inode() is > > not possible since, for CONFIG_SHMEM=n, tmpfs also calls the former after > > the latter. > > > > Pass NULL as initxattrs() callback to security_inode_init_security(), since > > the purpose of the call is only to initialize the in-memory inodes. > > > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > > + Andrew > > Hi Andrew > > I'm proposing an extension to initialize the inode security field at > inode creation time for filesystems that don't support xattrs (ramfs in > this case). > > The LSM infrastructure already supports setting the inode security > field, but only at run-time, with the inode_setsecurity hook. > > I developed this to do some testing on the Smack LSM, and I thought it > could be useful anyway. > > Casey would need your acked-by, to carry this patch in his repository. > I'm not completely sure if you are the maintainer, but in the past you > accepted a patch for ramfs. > > If you have time and you could have a look, that would be great! Patch looks OK to me. Please cc Hugh and myself on a resend. One little thing: > > +++ b/fs/ramfs/inode.c > > @@ -102,6 +102,14 @@ ramfs_mknod(struct mnt_idmap *idmap, struct inode *dir, > > int error = -ENOSPC; > > > > if (inode) { > > + error = security_inode_init_security(inode, dir, > > + &dentry->d_name, NULL, > > + NULL); > > + if (error) { > > + iput(inode); > > + return error; A `break' here would be better. To avoid having multiple return points, which are often a maintenance hassle. Same treatment at the other sites.
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c index fef477c7810..ac90ebd9dbd 100644 --- a/fs/ramfs/inode.c +++ b/fs/ramfs/inode.c @@ -102,6 +102,14 @@ ramfs_mknod(struct mnt_idmap *idmap, struct inode *dir, int error = -ENOSPC; if (inode) { + error = security_inode_init_security(inode, dir, + &dentry->d_name, NULL, + NULL); + if (error) { + iput(inode); + return error; + } + d_instantiate(dentry, inode); dget(dentry); /* Extra count - pin the dentry in core */ error = 0; @@ -134,6 +142,15 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir, inode = ramfs_get_inode(dir->i_sb, dir, S_IFLNK|S_IRWXUGO, 0); if (inode) { int l = strlen(symname)+1; + + error = security_inode_init_security(inode, dir, + &dentry->d_name, NULL, + NULL); + if (error) { + iput(inode); + return error; + } + error = page_symlink(inode, symname, l); if (!error) { d_instantiate(dentry, inode); @@ -149,10 +166,20 @@ static int ramfs_tmpfile(struct mnt_idmap *idmap, struct inode *dir, struct file *file, umode_t mode) { struct inode *inode; + int error; inode = ramfs_get_inode(dir->i_sb, dir, mode, 0); if (!inode) return -ENOSPC; + + error = security_inode_init_security(inode, dir, + &file_dentry(file)->d_name, NULL, + NULL); + if (error) { + iput(inode); + return error; + } + d_tmpfile(file, inode); return finish_open_simple(file, 0); }