Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'remove-ksys-mount-dup' of git://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux

Pull ksys_mount() and ksys_dup() removal from Dominik Brodowski:
"This small series replaces all in-kernel calls to the
userspace-focused ksys_mount() and ksys_dup() with calls to
kernel-centric functions:

For each replacement of ksys_mount() with do_mount(), one needs to
verify that the first and third parameter (char *dev_name, char *type)
are strings allocated in kernelspace and that the fifth parameter
(void *data) is either NULL or refers to a full page (only occurence
in init/do_mounts.c::do_mount_root()). The second and fourth
parameters (char *dir_name, unsigned long flags) are passed by
ksys_mount() to do_mount() unchanged, and therefore do not require
particular care.

Moreover, instead of pretending to be userspace, the opening of
/dev/console as stdin/stdout/stderr can be implemented using in-kernel
functions as well. Thereby, ksys_dup() can be removed for good"

[ This doesn't get rid of the special "kernel init runs with KERNEL_DS"
case, but it at least removes _some_ of the users of "treat kernel
pointers as user pointers for our magical init sequence".

One day we'll hopefully be rid of it all, and can initialize our
init_thread addr_limit to USER_DS. - Linus ]

* 'remove-ksys-mount-dup' of git://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux:
fs: remove ksys_dup()
init: unify opening /dev/console as stdin/stdout/stderr
init: use do_mount() instead of ksys_mount()
initrd: use do_mount() instead of ksys_mount()
devtmpfs: use do_mount() instead of ksys_mount()

+63 -41
+3 -3
drivers/base/devtmpfs.c
··· 359 359 * If configured, or requested by the commandline, devtmpfs will be 360 360 * auto-mounted after the kernel mounted the root filesystem. 361 361 */ 362 - int devtmpfs_mount(const char *mntdir) 362 + int devtmpfs_mount(void) 363 363 { 364 364 int err; 365 365 ··· 369 369 if (!thread) 370 370 return 0; 371 371 372 - err = ksys_mount("devtmpfs", mntdir, "devtmpfs", MS_SILENT, NULL); 372 + err = do_mount("devtmpfs", "dev", "devtmpfs", MS_SILENT, NULL); 373 373 if (err) 374 374 printk(KERN_INFO "devtmpfs: error mounting %i\n", err); 375 375 else ··· 394 394 *err = ksys_unshare(CLONE_NEWNS); 395 395 if (*err) 396 396 goto out; 397 - *err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL); 397 + *err = do_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL); 398 398 if (*err) 399 399 goto out; 400 400 ksys_chdir("/.."); /* will traverse into overmounted root */
+1 -6
fs/file.c
··· 960 960 return ksys_dup3(oldfd, newfd, 0); 961 961 } 962 962 963 - int ksys_dup(unsigned int fildes) 963 + SYSCALL_DEFINE1(dup, unsigned int, fildes) 964 964 { 965 965 int ret = -EBADF; 966 966 struct file *file = fget_raw(fildes); ··· 973 973 fput(file); 974 974 } 975 975 return ret; 976 - } 977 - 978 - SYSCALL_DEFINE1(dup, unsigned int, fildes) 979 - { 980 - return ksys_dup(fildes); 981 976 } 982 977 983 978 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
+2 -8
fs/namespace.c
··· 3325 3325 } 3326 3326 EXPORT_SYMBOL(mount_subtree); 3327 3327 3328 - int ksys_mount(const char __user *dev_name, const char __user *dir_name, 3329 - const char __user *type, unsigned long flags, void __user *data) 3328 + SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 3329 + char __user *, type, unsigned long, flags, void __user *, data) 3330 3330 { 3331 3331 int ret; 3332 3332 char *kernel_type; ··· 3357 3357 kfree(kernel_type); 3358 3358 out_type: 3359 3359 return ret; 3360 - } 3361 - 3362 - SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 3363 - char __user *, type, unsigned long, flags, void __user *, data) 3364 - { 3365 - return ksys_mount(dev_name, dir_name, type, flags, data); 3366 3360 } 3367 3361 3368 3362 /*
+2 -2
include/linux/device.h
··· 1666 1666 #ifdef CONFIG_DEVTMPFS 1667 1667 extern int devtmpfs_create_node(struct device *dev); 1668 1668 extern int devtmpfs_delete_node(struct device *dev); 1669 - extern int devtmpfs_mount(const char *mntdir); 1669 + extern int devtmpfs_mount(void); 1670 1670 #else 1671 1671 static inline int devtmpfs_create_node(struct device *dev) { return 0; } 1672 1672 static inline int devtmpfs_delete_node(struct device *dev) { return 0; } 1673 - static inline int devtmpfs_mount(const char *mountpoint) { return 0; } 1673 + static inline int devtmpfs_mount(void) { return 0; } 1674 1674 #endif 1675 1675 1676 1676 /* drivers/base/power/shutdown.c */
+2
include/linux/initrd.h
··· 28 28 29 29 extern char __initramfs_start[]; 30 30 extern unsigned long __initramfs_size; 31 + 32 + void console_on_rootfs(void);
-3
include/linux/syscalls.h
··· 1231 1231 * the ksys_xyzyyz() functions prototyped below. 1232 1232 */ 1233 1233 1234 - int ksys_mount(const char __user *dev_name, const char __user *dir_name, 1235 - const char __user *type, unsigned long flags, void __user *data); 1236 1234 int ksys_umount(char __user *name, int flags); 1237 - int ksys_dup(unsigned int fildes); 1238 1235 int ksys_chroot(const char __user *filename); 1239 1236 ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count); 1240 1237 int ksys_chdir(const char __user *filename);
+23 -7
init/do_mounts.c
··· 387 387 *s = '\0'; 388 388 } 389 389 390 - static int __init do_mount_root(char *name, char *fs, int flags, void *data) 390 + static int __init do_mount_root(const char *name, const char *fs, 391 + const int flags, const void *data) 391 392 { 392 393 struct super_block *s; 393 - int err = ksys_mount(name, "/root", fs, flags, data); 394 - if (err) 395 - return err; 394 + char *data_page; 395 + struct page *p; 396 + int ret; 397 + 398 + /* do_mount() requires a full page as fifth argument */ 399 + p = alloc_page(GFP_KERNEL); 400 + if (!p) 401 + return -ENOMEM; 402 + 403 + data_page = page_address(p); 404 + strncpy(data_page, data, PAGE_SIZE - 1); 405 + 406 + ret = do_mount(name, "/root", fs, flags, data_page); 407 + if (ret) 408 + goto out; 396 409 397 410 ksys_chdir("/root"); 398 411 s = current->fs->pwd.dentry->d_sb; ··· 415 402 s->s_type->name, 416 403 sb_rdonly(s) ? " readonly" : "", 417 404 MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); 418 - return 0; 405 + 406 + out: 407 + put_page(p); 408 + return ret; 419 409 } 420 410 421 411 void __init mount_block_root(char *name, int flags) ··· 686 670 687 671 mount_root(); 688 672 out: 689 - devtmpfs_mount("dev"); 690 - ksys_mount(".", "/", NULL, MS_MOVE, NULL); 673 + devtmpfs_mount(); 674 + do_mount(".", "/", NULL, MS_MOVE, NULL); 691 675 ksys_chroot("."); 692 676 } 693 677
+4 -7
init/do_mounts_initrd.c
··· 48 48 static int init_linuxrc(struct subprocess_info *info, struct cred *new) 49 49 { 50 50 ksys_unshare(CLONE_FS | CLONE_FILES); 51 - /* stdin/stdout/stderr for /linuxrc */ 52 - ksys_open("/dev/console", O_RDWR, 0); 53 - ksys_dup(0); 54 - ksys_dup(0); 51 + console_on_rootfs(); 55 52 /* move initrd over / and chdir/chroot in initrd root */ 56 53 ksys_chdir("/root"); 57 - ksys_mount(".", "/", NULL, MS_MOVE, NULL); 54 + do_mount(".", "/", NULL, MS_MOVE, NULL); 58 55 ksys_chroot("."); 59 56 ksys_setsid(); 60 57 return 0; ··· 86 89 current->flags &= ~PF_FREEZER_SKIP; 87 90 88 91 /* move initrd to rootfs' /old */ 89 - ksys_mount("..", ".", NULL, MS_MOVE, NULL); 92 + do_mount("..", ".", NULL, MS_MOVE, NULL); 90 93 /* switch root and cwd back to / of rootfs */ 91 94 ksys_chroot(".."); 92 95 ··· 100 103 mount_root(); 101 104 102 105 printk(KERN_NOTICE "Trying to move old root to /initrd ... "); 103 - error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); 106 + error = do_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); 104 107 if (!error) 105 108 printk("okay\n"); 106 109 else {
+26 -5
init/main.c
··· 93 93 #include <linux/rodata_test.h> 94 94 #include <linux/jump_label.h> 95 95 #include <linux/mem_encrypt.h> 96 + #include <linux/file.h> 96 97 97 98 #include <asm/io.h> 98 99 #include <asm/bugs.h> ··· 1156 1155 "See Linux Documentation/admin-guide/init.rst for guidance."); 1157 1156 } 1158 1157 1158 + void console_on_rootfs(void) 1159 + { 1160 + struct file *file; 1161 + unsigned int i; 1162 + 1163 + /* Open /dev/console in kernelspace, this should never fail */ 1164 + file = filp_open("/dev/console", O_RDWR, 0); 1165 + if (!file) 1166 + goto err_out; 1167 + 1168 + /* create stdin/stdout/stderr, this should never fail */ 1169 + for (i = 0; i < 3; i++) { 1170 + if (f_dupfd(i, file, 0) != i) 1171 + goto err_out; 1172 + } 1173 + 1174 + return; 1175 + 1176 + err_out: 1177 + /* no panic -- this might not be fatal */ 1178 + pr_err("Warning: unable to open an initial console.\n"); 1179 + return; 1180 + } 1181 + 1159 1182 static noinline void __init kernel_init_freeable(void) 1160 1183 { 1161 1184 /* ··· 1215 1190 1216 1191 do_basic_setup(); 1217 1192 1218 - /* Open the /dev/console on the rootfs, this should never fail */ 1219 - if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) 1220 - pr_err("Warning: unable to open an initial console.\n"); 1193 + console_on_rootfs(); 1221 1194 1222 - (void) ksys_dup(0); 1223 - (void) ksys_dup(0); 1224 1195 /* 1225 1196 * check if there is an early userspace init. If yes, let it do all 1226 1197 * the work