Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2436080rdb; Wed, 15 Nov 2023 00:02:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjJZw52B49NzbEa8X0OqnSsyWHZqnLSJWyNJuZX7Uio6ecafY12hBwjgMSx5Y5+pfWDl+F X-Received: by 2002:a05:6358:340b:b0:16b:7751:37a8 with SMTP id h11-20020a056358340b00b0016b775137a8mr4429066rwd.9.1700035357425; Wed, 15 Nov 2023 00:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700035357; cv=none; d=google.com; s=arc-20160816; b=at6Lfk1nnIOnJI0BtF7wEFqg9yBYoShJITLGxl1GGnSJ+8v14RyxCETcHy9ocgu+zt GC7/wwcLuAhMp1nSl3ZE03C0xxqBLgG5us0VK/lij8lzwiQy94bvtrjsL7Bjl2/six0r qqg4oIs9hM2+eCE/fTC1upy6r3Q5dWG2NlacTYqRcvpSzmIzWhT1sairT86EvkmBZbjm F6ldxVX/lcCMI0qj1MhIfHPWQtyTWGPdzjBnPzyR0fmj4QDXj1RJhXZ3L/FMzDkuXOHH bZ5cLNCBoY+zeZEDdlYP3fLWOlR0kyuCEbGfJ+X9ceFDorlVuj/n4PyV33axQHMwi+Ha 8VxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=xeP4dbzLaMAZl0qXQSS3hB35WogguzA0n1tRD6nQwLk=; fh=EdLEWB6RPHfwa2vAusVWlM51Xf1dMfxztSIWoWLig9s=; b=rglgAKO3mtyvrj3qdNigg00hd/d9ZLFVmEyDzOHaqlGH96WTfMmn1RLr+NFr+W/mzx 4xA8VbVGn1CfyR/+GFUffpDsnW2l2HDvMtUhSTQemNzNQo8Q0Gm9Li30ZmHPAMd3NPbi LVOMSUjlJ0ivdPW4VIdukf8zM+AaYcnv0XCqDl0p9vW6HQQbCDLbjcKOLm9AZ2jZQOJ4 hq5sWT2fyF1ax0gICKSKsD3ffakIH/aqp2IagSbZCQ0eBFLSkEYDVyZ6KSes4VcRwAgE TUpQwV6N8u9qs6CvmS8F40dSRpu5fh9AqQ1IjYvRs6Oo+a4nYShezycm332yUT0SoBa8 UuLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bo23-20020a056a02039700b005b8f45e32c8si10274770pgb.776.2023.11.15.00.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 00:02:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C0B428033DEB; Wed, 15 Nov 2023 00:02:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343499AbjKOICY convert rfc822-to-8bit (ORCPT + 99 others); Wed, 15 Nov 2023 03:02:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbjKOICW (ORCPT ); Wed, 15 Nov 2023 03:02:22 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED979DF; Wed, 15 Nov 2023 00:02:18 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4SVZwC08m1z9ycNc; Wed, 15 Nov 2023 15:45:47 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwCHN2HyelRliayxAA--.29367S2; Wed, 15 Nov 2023 09:02:00 +0100 (CET) Message-ID: <379f6a45a3102e8cd1ed992c1895ac9f69ae0595.camel@huaweicloud.com> Subject: Re: [PATCH v2 5/5] ramfs: Initialize security of in-memory inodes From: Roberto Sassu To: casey@schaufler-ca.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Roberto Sassu Date: Wed, 15 Nov 2023 09:01:52 +0100 In-Reply-To: <20230724151341.538889-6-roberto.sassu@huaweicloud.com> References: <20230724151341.538889-1-roberto.sassu@huaweicloud.com> <20230724151341.538889-6-roberto.sassu@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-CM-TRANSID: GxC2BwCHN2HyelRliayxAA--.29367S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWr1fCrW5tr43uF4UuF1UAwb_yoW5ArykpF WIqas8Gwn5tF9rWr1fKF4Uu3WSqayrKr4DJws3Zw17AFn7Gw1Utr4Skr13CF1rGr48Gw4F qw4j9ry5Ww1DZFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUglb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_WFyUJw CI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVF xhVjvjDU0xZFpf9x07UQzVbUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgACBF1jj5J4hwABsZ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 00:02:34 -0800 (PST) On Mon, 2023-07-24 at 17:13 +0200, Roberto Sassu wrote: > From: Roberto Sassu > > 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 + 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); > }