Skip to content

Commit f0816d4

Browse files
robertosassucschaufler
authored andcommitted
ramfs: Initialize security of in-memory inodes
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. Cc: Hugh Dickins <[email protected]> Acked-by: Andrew Morton <[email protected]> Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent e63d86b commit f0816d4

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

fs/ramfs/inode.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,20 @@ ramfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
102102
int error = -ENOSPC;
103103

104104
if (inode) {
105+
error = security_inode_init_security(inode, dir,
106+
&dentry->d_name, NULL,
107+
NULL);
108+
if (error) {
109+
iput(inode);
110+
goto out;
111+
}
112+
105113
d_instantiate(dentry, inode);
106114
dget(dentry); /* Extra count - pin the dentry in core */
107115
error = 0;
108116
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
109117
}
118+
out:
110119
return error;
111120
}
112121

@@ -134,6 +143,15 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
134143
inode = ramfs_get_inode(dir->i_sb, dir, S_IFLNK|S_IRWXUGO, 0);
135144
if (inode) {
136145
int l = strlen(symname)+1;
146+
147+
error = security_inode_init_security(inode, dir,
148+
&dentry->d_name, NULL,
149+
NULL);
150+
if (error) {
151+
iput(inode);
152+
goto out;
153+
}
154+
137155
error = page_symlink(inode, symname, l);
138156
if (!error) {
139157
d_instantiate(dentry, inode);
@@ -143,19 +161,31 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
143161
} else
144162
iput(inode);
145163
}
164+
out:
146165
return error;
147166
}
148167

149168
static int ramfs_tmpfile(struct mnt_idmap *idmap,
150169
struct inode *dir, struct file *file, umode_t mode)
151170
{
152171
struct inode *inode;
172+
int error;
153173

154174
inode = ramfs_get_inode(dir->i_sb, dir, mode, 0);
155175
if (!inode)
156176
return -ENOSPC;
177+
178+
error = security_inode_init_security(inode, dir,
179+
&file_dentry(file)->d_name, NULL,
180+
NULL);
181+
if (error) {
182+
iput(inode);
183+
goto out;
184+
}
185+
157186
d_tmpfile(file, inode);
158-
return finish_open_simple(file, 0);
187+
out:
188+
return finish_open_simple(file, error);
159189
}
160190

161191
static const struct inode_operations ramfs_dir_inode_operations = {

0 commit comments

Comments
 (0)