From: Andrew Morton <akpm@linux-foundation.org>
To: Roberto Sassu <roberto.sassu@huaweicloud.com>
Cc: casey@schaufler-ca.com, paul@paul-moore.com, jmorris@namei.org,
serge@hallyn.com, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org,
Roberto Sassu <roberto.sassu@huawei.com>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH v3 5/5] ramfs: Initialize security of in-memory inodes
Date: Thu, 25 Jan 2024 17:08:58 -0800 [thread overview]
Message-ID: <20240125170858.1ce723a57c7fd2b9bfb5d28d@linux-foundation.org> (raw)
In-Reply-To: <20231116090125.187209-6-roberto.sassu@huaweicloud.com>
On Thu, 16 Nov 2023 10:01:25 +0100 Roberto Sassu <roberto.sassu@huaweicloud.com> 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.
>
fwiw,
Acked-by: Andrew Morton <akpm@linux-foundation.org>
Please include this in the relevant security tree.
> diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
> index 4ac05a9e25bc..8006faaaf0ec 100644
> --- a/fs/ramfs/inode.c
> +++ b/fs/ramfs/inode.c
> @@ -102,11 +102,20 @@ 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);
> + goto out;
> + }
> +
> d_instantiate(dentry, inode);
> dget(dentry); /* Extra count - pin the dentry in core */
> error = 0;
> inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
> }
> +out:
> return error;
> }
>
> @@ -134,6 +143,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);
> + goto out;
> + }
> +
> error = page_symlink(inode, symname, l);
> if (!error) {
> d_instantiate(dentry, inode);
> @@ -143,6 +161,7 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
> } else
> iput(inode);
> }
> +out:
> return error;
> }
>
> @@ -150,12 +169,23 @@ 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);
> + goto out;
> + }
> +
> d_tmpfile(file, inode);
> - return finish_open_simple(file, 0);
> +out:
> + return finish_open_simple(file, error);
> }
>
> static const struct inode_operations ramfs_dir_inode_operations = {
> --
> 2.34.1
next prev parent reply other threads:[~2024-01-26 1:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 9:01 [PATCH v3 0/5] Smack transmute fixes Roberto Sassu
2023-11-16 9:01 ` [PATCH v3 1/5] smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr() Roberto Sassu
2023-11-16 9:01 ` [PATCH v3 2/5] smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity() Roberto Sassu
2023-11-16 9:01 ` [PATCH v3 3/5] smack: Always determine inode labels in smack_inode_init_security() Roberto Sassu
2023-11-16 9:01 ` [PATCH v3 4/5] smack: Initialize the in-memory inode " Roberto Sassu
2023-11-16 9:01 ` [PATCH v3 5/5] ramfs: Initialize security of in-memory inodes Roberto Sassu
2024-01-12 8:17 ` Roberto Sassu
2024-01-16 8:39 ` Roberto Sassu
2024-01-26 1:08 ` Andrew Morton [this message]
2024-01-26 7:53 ` Roberto Sassu
2024-01-26 16:27 ` Casey Schaufler
2024-01-24 22:31 ` [PATCH v3 0/5] Smack transmute fixes Casey Schaufler
2024-01-25 8:44 ` Roberto Sassu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240125170858.1ce723a57c7fd2b9bfb5d28d@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=casey@schaufler-ca.com \
--cc=hughd@google.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=roberto.sassu@huawei.com \
--cc=roberto.sassu@huaweicloud.com \
--cc=serge@hallyn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).