Skip to content

Commit b873498

Browse files
author
Christoph Hellwig
committed
init: add an init_chown helper
Add a simple helper to chown with a kernel space file name and switch the early init code over to it. Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 4b7ca50 commit b873498

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎fs/init.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ int __init init_chroot(const char *filename)
7878
return error;
7979
}
8080

81+
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags)
82+
{
83+
int lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
84+
struct path path;
85+
int error;
86+
87+
error = kern_path(filename, lookup_flags, &path);
88+
if (error)
89+
return error;
90+
error = mnt_want_write(path.mnt);
91+
if (!error) {
92+
error = chown_common(&path, user, group);
93+
mnt_drop_write(path.mnt);
94+
}
95+
path_put(&path);
96+
return error;
97+
}
98+
8199
int __init init_unlink(const char *pathname)
82100
{
83101
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));

‎fs/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
134134
int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
135135
int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
136136
int flag);
137-
137+
int chown_common(const struct path *path, uid_t user, gid_t group);
138138
extern int vfs_open(const struct path *, struct file *);
139139

140140
/*

‎fs/open.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode)
639639
return do_fchmodat(AT_FDCWD, filename, mode);
640640
}
641641

642-
static int chown_common(const struct path *path, uid_t user, gid_t group)
642+
int chown_common(const struct path *path, uid_t user, gid_t group)
643643
{
644644
struct inode *inode = path->dentry->d_inode;
645645
struct inode *delegated_inode = NULL;

‎include/linux/init_syscalls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ int __init init_mount(const char *dev_name, const char *dir_name,
55
int __init init_umount(const char *name, int flags);
66
int __init init_chdir(const char *filename);
77
int __init init_chroot(const char *filename);
8+
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
89
int __init init_unlink(const char *pathname);
910
int __init init_rmdir(const char *pathname);

‎init/initramfs.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,14 @@ static int __init do_name(void)
349349
}
350350
} else if (S_ISDIR(mode)) {
351351
ksys_mkdir(collected, mode);
352-
ksys_chown(collected, uid, gid);
352+
init_chown(collected, uid, gid, 0);
353353
ksys_chmod(collected, mode);
354354
dir_add(collected, mtime);
355355
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
356356
S_ISFIFO(mode) || S_ISSOCK(mode)) {
357357
if (maybe_link() == 0) {
358358
ksys_mknod(collected, mode, rdev);
359-
ksys_chown(collected, uid, gid);
359+
init_chown(collected, uid, gid, 0);
360360
ksys_chmod(collected, mode);
361361
do_utime(collected, mtime);
362362
}
@@ -393,7 +393,7 @@ static int __init do_symlink(void)
393393
collected[N_ALIGN(name_len) + body_len] = '\0';
394394
clean_path(collected, 0);
395395
ksys_symlink(collected + N_ALIGN(name_len), collected);
396-
ksys_lchown(collected, uid, gid);
396+
init_chown(collected, uid, gid, AT_SYMLINK_NOFOLLOW);
397397
do_utime(collected, mtime);
398398
state = SkipIt;
399399
next_state = Reset;

0 commit comments

Comments
 (0)