History

init: add an init_chroot helper

Add a simple helper to chroot with a kernel space file name and switch the early init code over to it. Remove the now unused ksys_chroot.

Christoph Hellwig committed 6 years ago

Commit 4b7ca501 parent db63f1e7 files · +30 −12Browse files

Unified · Split

7 files
  1. drivers/base/devtmpfs.c +1 −1
  2. fs/init.c +24 −0
  3. fs/open.c +1 −6
  4. include/linux/init_syscalls.h +1 −0
  5. include/linux/syscalls.h +0 −2
  6. init/do_mounts.c +1 −1
  7. init/do_mounts_initrd.c +2 −2
drivers/base/devtmpfs.c+1−1
@@ -413,7 +413,7 @@ static int __init devtmpfs_setup(void *p) · 412 unmodified lines
413 if (err)413 if (err)
414 goto out;414 goto out;
415 init_chdir("/.."); /* will traverse into overmounted root */415 init_chdir("/.."); /* will traverse into overmounted root */
416 ksys_chroot(".");416 init_chroot(".");
417out:417out:
418 *(int *)p = err;418 *(int *)p = err;
419 complete(&setup_done);419 complete(&setup_done);
fs/init.c+24−0
@@ -9,6 +9,7 @@ · 8 unmodified lines
9#include <linux/fs.h>9#include <linux/fs.h>
10#include <linux/fs_struct.h>10#include <linux/fs_struct.h>
11#include <linux/init_syscalls.h>11#include <linux/init_syscalls.h>
12#include <linux/security.h>
12#include "internal.h"13#include "internal.h"
13 14
14int __init init_mount(const char *dev_name, const char *dir_name,15int __init init_mount(const char *dev_name, const char *dir_name,
@@ -54,6 +55,29 @@ int __init init_chdir(const char *filename) · 39 unmodified lines
54 return error;55 return error;
55}56}
56 57
58int __init init_chroot(const char *filename)
59{
60 struct path path;
61 int error;
62
63 error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
64 if (error)
65 return error;
66 error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
67 if (error)
68 goto dput_and_out;
69 error = -EPERM;
70 if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))
71 goto dput_and_out;
72 error = security_path_chroot(&path);
73 if (error)
74 goto dput_and_out;
75 set_fs_root(current->fs, &path);
76dput_and_out:
77 path_put(&path);
78 return error;
79}
80
57int __init init_unlink(const char *pathname)81int __init init_unlink(const char *pathname)
58{82{
59 return do_unlinkat(AT_FDCWD, getname_kernel(pathname));83 return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
fs/open.c+1−6
@@ -530,7 +530,7 @@ out: · 529 unmodified lines
530 return error;530 return error;
531}531}
532 532
533int ksys_chroot(const char __user *filename)533SYSCALL_DEFINE1(chroot, const char __user *, filename)
534{534{
535 struct path path;535 struct path path;
536 int error;536 int error;
@@ -563,11 +563,6 @@ out: · 26 unmodified lines
563 return error;563 return error;
564}564}
565 565
566SYSCALL_DEFINE1(chroot, const char __user *, filename)
567{
568 return ksys_chroot(filename);
569}
570
571static int chmod_common(const struct path *path, umode_t mode)566static int chmod_common(const struct path *path, umode_t mode)
572{567{
573 struct inode *inode = path->dentry->d_inode;568 struct inode *inode = path->dentry->d_inode;
include/linux/init_syscalls.h+1−0
@@ -4,5 +4,6 @@ int __init init_mount(const char *dev_name, const char *dir_name, · 3 unmodified lines
4 const char *type_page, unsigned long flags, void *data_page);4 const char *type_page, unsigned long flags, void *data_page);
5int __init init_umount(const char *name, int flags);5int __init init_umount(const char *name, int flags);
6int __init init_chdir(const char *filename);6int __init init_chdir(const char *filename);
7int __init init_chroot(const char *filename);
7int __init init_unlink(const char *pathname);8int __init init_unlink(const char *pathname);
8int __init init_rmdir(const char *pathname);9int __init init_rmdir(const char *pathname);
include/linux/syscalls.h+0−2
@@ -1235,8 +1235,6 @@ asmlinkage long sys_ni_syscall(void); · 1234 unmodified lines
1235 * Instead, use one of the functions which work equivalently, such as1235 * Instead, use one of the functions which work equivalently, such as
1236 * the ksys_xyzyyz() functions prototyped below.1236 * the ksys_xyzyyz() functions prototyped below.
1237 */1237 */
1238
1239int ksys_chroot(const char __user *filename);
1240ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);1238ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
1241int ksys_fchown(unsigned int fd, uid_t user, gid_t group);1239int ksys_fchown(unsigned int fd, uid_t user, gid_t group);
1242ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count);1240ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count);
init/do_mounts.c+1−1
@@ -629,7 +629,7 @@ void __init prepare_namespace(void) · 628 unmodified lines
629out:629out:
630 devtmpfs_mount();630 devtmpfs_mount();
631 init_mount(".", "/", NULL, MS_MOVE, NULL);631 init_mount(".", "/", NULL, MS_MOVE, NULL);
632 ksys_chroot(".");632 init_chroot(".");
633}633}
634 634
635static bool is_tmpfs;635static bool is_tmpfs;
init/do_mounts_initrd.c+2−2
@@ -63,7 +63,7 @@ static int __init init_linuxrc(struct subprocess_info *info, struct cred *new) · 62 unmodified lines
63 /* move initrd over / and chdir/chroot in initrd root */63 /* move initrd over / and chdir/chroot in initrd root */
64 init_chdir("/root");64 init_chdir("/root");
65 init_mount(".", "/", NULL, MS_MOVE, NULL);65 init_mount(".", "/", NULL, MS_MOVE, NULL);
66 ksys_chroot(".");66 init_chroot(".");
67 ksys_setsid();67 ksys_setsid();
68 return 0;68 return 0;
69}69}
@@ -101,7 +101,7 @@ static void __init handle_initrd(void) · 31 unmodified lines
101 /* move initrd to rootfs' /old */101 /* move initrd to rootfs' /old */
102 init_mount("..", ".", NULL, MS_MOVE, NULL);102 init_mount("..", ".", NULL, MS_MOVE, NULL);
103 /* switch root and cwd back to / of rootfs */103 /* switch root and cwd back to / of rootfs */
104 ksys_chroot("..");104 init_chroot("..");
105 105
106 if (new_decode_dev(real_root_dev) == Root_RAM0) {106 if (new_decode_dev(real_root_dev) == Root_RAM0) {
107 init_chdir("/old");107 init_chdir("/old");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t