2019-12-12 18:15:18

by Dominik Brodowski

[permalink] [raw]
Subject: [GIT PULL] remove ksys_mount() and ksys_dup()

The following changes since commit ae4b064e2a616b545acf02b8f50cc513b32c7522:

Merge tag 'afs-fixes-20191211' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs (2019-12-11 18:10:40 -0800)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux.git remove-ksys-mount-dup

for you to fetch changes up to 8243186f0cc7c57cf9d6a110cd7315c44e3e0be8:

fs: remove ksys_dup() (2019-12-12 19:00:36 +0100)

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.

---

Changes since the split-series patches[1,2]:
- merge both series (on suggestion by Linus)
- remove pointless cast (on suggestion by Linus)

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/


Thanks,
Dominik


----------------------------------------------------------------
Dominik Brodowski (5):
devtmpfs: use do_mount() instead of ksys_mount()
initrd: use do_mount() instead of ksys_mount()
init: use do_mount() instead of ksys_mount()
init: unify opening /dev/console as stdin/stdout/stderr
fs: remove ksys_dup()

drivers/base/devtmpfs.c | 6 +++---
fs/file.c | 7 +------
fs/namespace.c | 10 ++--------
include/linux/device.h | 4 ++--
include/linux/initrd.h | 2 ++
include/linux/syscalls.h | 3 ---
init/do_mounts.c | 30 +++++++++++++++++++++++-------
init/do_mounts_initrd.c | 11 ++++-------
init/main.c | 31 ++++++++++++++++++++++++++-----
9 files changed, 63 insertions(+), 41 deletions(-)

--
2.24.1


2019-12-12 18:15:23

by Dominik Brodowski

[permalink] [raw]
Subject: [PATCH 3/5] init: use do_mount() instead of ksys_mount()

In prepare_namespace(), do_mount() can be used instead of ksys_mount()
as the first and third argument are const strings in the kernel, the
second and fourth argument are passed through anyway, and the fifth
argument is NULL.

In do_mount_root(), ksys_mount() is called with the first and third
argument being already kernelspace strings, which do not need to be
copied over from userspace to kernelspace (again). The second and
fourth arguments are passed through to do_mount() anyway. The fifth
argument, while already residing in kernelspace, needs to be put into
a page of its own. Then, do_mount() can be used instead of
ksys_mount().

Once this is done, there are no in-kernel users to ksys_mount() left,
which can therefore be removed.

Signed-off-by: Dominik Brodowski <[email protected]>
---
fs/namespace.c | 10 ++--------
include/linux/syscalls.h | 2 --
init/do_mounts.c | 28 ++++++++++++++++++++++------
3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 2fd0c8bcb8c1..be601d3a8008 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name)
}
EXPORT_SYMBOL(mount_subtree);

-int ksys_mount(const char __user *dev_name, const char __user *dir_name,
- const char __user *type, unsigned long flags, void __user *data)
+SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
+ char __user *, type, unsigned long, flags, void __user *, data)
{
int ret;
char *kernel_type;
@@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name,
return ret;
}

-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
- char __user *, type, unsigned long, flags, void __user *, data)
-{
- return ksys_mount(dev_name, dir_name, type, flags, data);
-}
-
/*
* Create a kernel mount representation for a new, prepared superblock
* (specified by fs_fd) and attach to an open_tree-like file descriptor.
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index d0391cc2dae9..5262b7a76d39 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1231,8 +1231,6 @@ asmlinkage long sys_ni_syscall(void);
* the ksys_xyzyyz() functions prototyped below.
*/

-int ksys_mount(const char __user *dev_name, const char __user *dir_name,
- const char __user *type, unsigned long flags, void __user *data);
int ksys_umount(char __user *name, int flags);
int ksys_dup(unsigned int fildes);
int ksys_chroot(const char __user *filename);
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 43f6d098c880..f55cbd9cb818 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -387,12 +387,25 @@ static void __init get_fs_names(char *page)
*s = '\0';
}

-static int __init do_mount_root(char *name, char *fs, int flags, void *data)
+static int __init do_mount_root(const char *name, const char *fs,
+ const int flags, const void *data)
{
struct super_block *s;
- int err = ksys_mount(name, "/root", fs, flags, data);
- if (err)
- return err;
+ char *data_page;
+ struct page *p;
+ int ret;
+
+ /* do_mount() requires a full page as fifth argument */
+ p = alloc_page(GFP_KERNEL);
+ if (!p)
+ return -ENOMEM;
+
+ data_page = page_address(p);
+ strncpy(data_page, data, PAGE_SIZE - 1);
+
+ ret = do_mount(name, "/root", fs, flags, data_page);
+ if (ret)
+ goto out;

ksys_chdir("/root");
s = current->fs->pwd.dentry->d_sb;
@@ -402,7 +415,10 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data)
s->s_type->name,
sb_rdonly(s) ? " readonly" : "",
MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
- return 0;
+
+out:
+ put_page(p);
+ return ret;
}

void __init mount_block_root(char *name, int flags)
@@ -671,7 +687,7 @@ void __init prepare_namespace(void)
mount_root();
out:
devtmpfs_mount();
- ksys_mount(".", "/", NULL, MS_MOVE, NULL);
+ do_mount(".", "/", NULL, MS_MOVE, NULL);
ksys_chroot(".");
}

--
2.24.1

2019-12-12 18:15:32

by Dominik Brodowski

[permalink] [raw]
Subject: [PATCH 5/5] fs: remove ksys_dup()

ksys_dup() is used only at one place in the kernel, namely to duplicate
fd 0 of /dev/console to stdout and stderr. The same functionality can be
achieved by using functions already available within the kernel namespace.

Signed-off-by: Dominik Brodowski <[email protected]>
---
fs/file.c | 7 +------
include/linux/syscalls.h | 1 -
init/main.c | 26 ++++++++++++++++++++------
3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index 3da91a112bab..2f4fcf985079 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -960,7 +960,7 @@ SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd)
return ksys_dup3(oldfd, newfd, 0);
}

-int ksys_dup(unsigned int fildes)
+SYSCALL_DEFINE1(dup, unsigned int, fildes)
{
int ret = -EBADF;
struct file *file = fget_raw(fildes);
@@ -975,11 +975,6 @@ int ksys_dup(unsigned int fildes)
return ret;
}

-SYSCALL_DEFINE1(dup, unsigned int, fildes)
-{
- return ksys_dup(fildes);
-}
-
int f_dupfd(unsigned int from, struct file *file, unsigned flags)
{
int err;
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 5262b7a76d39..2960dedcfde8 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1232,7 +1232,6 @@ asmlinkage long sys_ni_syscall(void);
*/

int ksys_umount(char __user *name, int flags);
-int ksys_dup(unsigned int fildes);
int ksys_chroot(const char __user *filename);
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
int ksys_chdir(const char __user *filename);
diff --git a/init/main.c b/init/main.c
index 2cd736059416..ec3a1463ac69 100644
--- a/init/main.c
+++ b/init/main.c
@@ -93,6 +93,7 @@
#include <linux/rodata_test.h>
#include <linux/jump_label.h>
#include <linux/mem_encrypt.h>
+#include <linux/file.h>

#include <asm/io.h>
#include <asm/bugs.h>
@@ -1157,13 +1158,26 @@ static int __ref kernel_init(void *unused)

void console_on_rootfs(void)
{
- /* Open the /dev/console as stdin, this should never fail */
- if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
- pr_err("Warning: unable to open an initial console.\n");
+ struct file *file;
+ unsigned int i;
+
+ /* Open /dev/console in kernelspace, this should never fail */
+ file = filp_open("/dev/console", O_RDWR, 0);
+ if (!file)
+ goto err_out;
+
+ /* create stdin/stdout/stderr, this should never fail */
+ for (i = 0; i < 3; i++) {
+ if (f_dupfd(i, file, 0) != i)
+ goto err_out;
+ }
+
+ return;

- /* create stdout/stderr */
- (void) ksys_dup(0);
- (void) ksys_dup(0);
+err_out:
+ /* no panic -- this might not be fatal */
+ pr_err("Warning: unable to open an initial console.\n");
+ return;
}

static noinline void __init kernel_init_freeable(void)
--
2.24.1

2019-12-12 18:16:15

by Dominik Brodowski

[permalink] [raw]
Subject: [PATCH 2/5] initrd: use do_mount() instead of ksys_mount()

All three calls to ksys_mount() in initrd-related kernel code can
be switched over to do_mount():
- the first and third arguments are const strings in the kernel,
and do not need to be copied over from userspace;
- the fifth argument is NULL, and therefore no page needs to be,
copied over from userspace;
- the second and fourth argument are passed through anyway.

Signed-off-by: Dominik Brodowski <[email protected]>
---
init/do_mounts_initrd.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index a9c6cc56f505..3bf7b74153ab 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -54,7 +54,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
ksys_dup(0);
/* move initrd over / and chdir/chroot in initrd root */
ksys_chdir("/root");
- ksys_mount(".", "/", NULL, MS_MOVE, NULL);
+ do_mount(".", "/", NULL, MS_MOVE, NULL);
ksys_chroot(".");
ksys_setsid();
return 0;
@@ -89,7 +89,7 @@ static void __init handle_initrd(void)
current->flags &= ~PF_FREEZER_SKIP;

/* move initrd to rootfs' /old */
- ksys_mount("..", ".", NULL, MS_MOVE, NULL);
+ do_mount("..", ".", NULL, MS_MOVE, NULL);
/* switch root and cwd back to / of rootfs */
ksys_chroot("..");

@@ -103,7 +103,7 @@ static void __init handle_initrd(void)
mount_root();

printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
- error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
+ error = do_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
if (!error)
printk("okay\n");
else {
--
2.24.1

2019-12-12 18:16:49

by Dominik Brodowski

[permalink] [raw]
Subject: [PATCH 4/5] init: unify opening /dev/console as stdin/stdout/stderr

Merge the two instances where /dev/console is opened as
stdin/stdout/stderr.

Signed-off-by: Dominik Brodowski <[email protected]>
---
include/linux/initrd.h | 2 ++
init/do_mounts_initrd.c | 5 +----
init/main.c | 17 ++++++++++++-----
3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/include/linux/initrd.h b/include/linux/initrd.h
index d77fe34fb00a..aa5914355728 100644
--- a/include/linux/initrd.h
+++ b/include/linux/initrd.h
@@ -28,3 +28,5 @@ extern unsigned int real_root_dev;

extern char __initramfs_start[];
extern unsigned long __initramfs_size;
+
+void console_on_rootfs(void);
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 3bf7b74153ab..dab8b1151b56 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -48,10 +48,7 @@ early_param("initrd", early_initrd);
static int init_linuxrc(struct subprocess_info *info, struct cred *new)
{
ksys_unshare(CLONE_FS | CLONE_FILES);
- /* stdin/stdout/stderr for /linuxrc */
- ksys_open("/dev/console", O_RDWR, 0);
- ksys_dup(0);
- ksys_dup(0);
+ console_on_rootfs();
/* move initrd over / and chdir/chroot in initrd root */
ksys_chdir("/root");
do_mount(".", "/", NULL, MS_MOVE, NULL);
diff --git a/init/main.c b/init/main.c
index 91f6ebb30ef0..2cd736059416 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1155,6 +1155,17 @@ static int __ref kernel_init(void *unused)
"See Linux Documentation/admin-guide/init.rst for guidance.");
}

+void console_on_rootfs(void)
+{
+ /* Open the /dev/console as stdin, this should never fail */
+ if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+ pr_err("Warning: unable to open an initial console.\n");
+
+ /* create stdout/stderr */
+ (void) ksys_dup(0);
+ (void) ksys_dup(0);
+}
+
static noinline void __init kernel_init_freeable(void)
{
/*
@@ -1190,12 +1201,8 @@ static noinline void __init kernel_init_freeable(void)

do_basic_setup();

- /* Open the /dev/console on the rootfs, this should never fail */
- if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
- pr_err("Warning: unable to open an initial console.\n");
+ console_on_rootfs();

- (void) ksys_dup(0);
- (void) ksys_dup(0);
/*
* check if there is an early userspace init. If yes, let it do all
* the work
--
2.24.1

2019-12-12 18:17:01

by Dominik Brodowski

[permalink] [raw]
Subject: [PATCH 1/5] devtmpfs: use do_mount() instead of ksys_mount()

In devtmpfs, do_mount() can be called directly instead of complex wrapping
by ksys_mount():
- the first and third arguments are const strings in the kernel,
and do not need to be copied over from userspace;
- the fifth argument is NULL, and therefore no page needs to be
copied over from userspace;
- the second and fourth argument are passed through anyway.

Signed-off-by: Dominik Brodowski <[email protected]>
---
drivers/base/devtmpfs.c | 6 +++---
include/linux/device.h | 4 ++--
init/do_mounts.c | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index 30d0523014e0..6cdbf1531238 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -359,7 +359,7 @@ static int handle_remove(const char *nodename, struct device *dev)
* If configured, or requested by the commandline, devtmpfs will be
* auto-mounted after the kernel mounted the root filesystem.
*/
-int devtmpfs_mount(const char *mntdir)
+int devtmpfs_mount(void)
{
int err;

@@ -369,7 +369,7 @@ int devtmpfs_mount(const char *mntdir)
if (!thread)
return 0;

- err = ksys_mount("devtmpfs", mntdir, "devtmpfs", MS_SILENT, NULL);
+ err = do_mount("devtmpfs", "dev", "devtmpfs", MS_SILENT, NULL);
if (err)
printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
else
@@ -394,7 +394,7 @@ static int devtmpfsd(void *p)
*err = ksys_unshare(CLONE_NEWNS);
if (*err)
goto out;
- *err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
+ *err = do_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
if (*err)
goto out;
ksys_chdir("/.."); /* will traverse into overmounted root */
diff --git a/include/linux/device.h b/include/linux/device.h
index e226030c1df3..96ff76731e93 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1666,11 +1666,11 @@ extern bool kill_device(struct device *dev);
#ifdef CONFIG_DEVTMPFS
extern int devtmpfs_create_node(struct device *dev);
extern int devtmpfs_delete_node(struct device *dev);
-extern int devtmpfs_mount(const char *mntdir);
+extern int devtmpfs_mount(void);
#else
static inline int devtmpfs_create_node(struct device *dev) { return 0; }
static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
-static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
+static inline int devtmpfs_mount(void) { return 0; }
#endif

/* drivers/base/power/shutdown.c */
diff --git a/init/do_mounts.c b/init/do_mounts.c
index af9cda887a23..43f6d098c880 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -670,7 +670,7 @@ void __init prepare_namespace(void)

mount_root();
out:
- devtmpfs_mount("dev");
+ devtmpfs_mount();
ksys_mount(".", "/", NULL, MS_MOVE, NULL);
ksys_chroot(".");
}
--
2.24.1

2019-12-15 19:52:28

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PULL] remove ksys_mount() and ksys_dup()

On Thu, Dec 12, 2019 at 10:14 AM Dominik Brodowski
<[email protected]> wrote:
>
> the fifth parameter (void *data)
> is either NULL or refers to a full page (only occurence
> in init/do_mounts.c::do_mount_root()).

We probably should aim for the fifth parameter being a "buf, len" pair
at some point.

Then the system call interface still needs to copy the whole page and
pass in PAGE_SIZE as the length, but it would be a better model than
the magical fixed "it's always one page". And the kernel init sequence
wouldn't need that silly temporary page any more.

Linus

2019-12-15 20:51:05

by pr-tracker-bot

[permalink] [raw]
Subject: Re: [GIT PULL] remove ksys_mount() and ksys_dup()

The pull request you sent on Thu, 12 Dec 2019 19:14:17 +0100:

> git://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux.git remove-ksys-mount-dup

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/2e6d304515ba9936d85265ad93dddc4c13c17d06

Thank you!

--
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker

2019-12-19 07:10:54

by Dominik Brodowski

[permalink] [raw]
Subject: Re: [PATCH 4/5] init: unify opening /dev/console as stdin/stdout/stderr

On Thu, Dec 19, 2019 at 05:50:19AM +0800, youling 257 wrote:
> 2019-12-18 5:14 GMT+08:00, Linus Torvalds <[email protected]>:
> > This should be fixed by 2d3145f8d280 ("early init: fix error handling
> > when opening /dev/console")
>
> this fix no help for me.
>
> > I'm not sure what you did to trigger that bug, but it was a bug.
>
> alt+f1, type bash command,
> bash: cannot set terminal process group (-1): Inappropriate ioctl for device
> bash: no job control in this shell

Could you test this patch, please? And if it does not work: What is the
content of /proc/1/fd/ and /proc/1/fdinfo/* for the working and non-working
case? That are the only changes visible to userspace...

Thanks,
Dominik

diff --git a/init/main.c b/init/main.c
index 1ecfd43ed464..8886530e9dec 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1162,7 +1162,7 @@ void console_on_rootfs(void)
unsigned int i;

/* Open /dev/console in kernelspace, this should never fail */
- file = filp_open("/dev/console", O_RDWR, 0);
+ file = filp_open("/dev/console", force_o_largefile() ? O_LARGEFILE | O_RDWR : O_RDWR, 0);
if (IS_ERR(file))
goto err_out;

2019-12-19 09:36:01

by youling 257

[permalink] [raw]
Subject: Re: [PATCH 4/5] init: unify opening /dev/console as stdin/stdout/stderr

Test this patch not work, still has system/bin/sh warning.
ls -al /proc/1/fd
total 0
dr-x------ 2 root root 0 2019-12-19 17:19 [1;34m. [0m
dr-xr-xr-x 9 root root 0 2019-12-19 17:19 [1;34m.. [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m0 [0m ->
[1;31m/android/sys/fs/selinux/null [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m1 [0m ->
[1;31m/android/sys/fs/selinux/null [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m10 [0m ->
[1;31msocket:[12337] [0m
l-wx------ 1 root root 64 2019-12-19 17:19 [1;36m11 [0m ->
[1;31m/android/dev/pmsg0 [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m2 [0m ->
[1;31m/android/sys/fs/selinux/null [0m
l-wx------ 1 root root 64 2019-12-19 17:19 [1;36m3 [0m ->
[1;31m/android/dev/__kmsg__ (deleted) [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m4 [0m ->
[1;31manon_inode:[eventpoll] [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m5 [0m ->
[1;31msocket:[857] [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m6 [0m ->
[1;31msocket:[858] [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m7 [0m ->
[1;31msocket:[859] [0m
lrwx------ 1 root root 64 2019-12-19 17:19 [1;36m9 [0m ->
[1;31msocket:[10698] [0m

Revert "fs: remove ksys_dup()", no the system/bin/sh warning.
ls -al /proc/1/fd
total 0
dr-x------ 2 root root 0 2019-12-19 17:28 [1;34m. [0m
dr-xr-xr-x 9 root root 0 2019-12-19 17:28 [1;34m.. [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m0 [0m ->
[1;31m/android/sys/fs/selinux/null [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m1 [0m ->
[1;31m/android/sys/fs/selinux/null [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m10 [0m ->
[1;31msocket:[12506] [0m
l-wx------ 1 root root 64 2019-12-19 17:28 [1;36m11 [0m ->
[1;31m/android/dev/pmsg0 [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m2 [0m ->
[1;31m/android/sys/fs/selinux/null [0m
l-wx------ 1 root root 64 2019-12-19 17:28 [1;36m3 [0m ->
[1;31m/android/dev/__kmsg__ (deleted) [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m4 [0m ->
[1;31manon_inode:[eventpoll] [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m5 [0m ->
[1;31msocket:[1957] [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m6 [0m ->
[1;31msocket:[1958] [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m7 [0m ->
[1;31msocket:[1959] [0m
lrwx------ 1 root root 64 2019-12-19 17:28 [1;36m9 [0m ->
[1;31msocket:[2040] [0m

2019-12-19 15:08 GMT+08:00, Dominik Brodowski <[email protected]>:
> On Thu, Dec 19, 2019 at 05:50:19AM +0800, youling 257 wrote:
>> 2019-12-18 5:14 GMT+08:00, Linus Torvalds
>> <[email protected]>:
>> > This should be fixed by 2d3145f8d280 ("early init: fix error handling
>> > when opening /dev/console")
>>
>> this fix no help for me.
>>
>> > I'm not sure what you did to trigger that bug, but it was a bug.
>>
>> alt+f1, type bash command,
>> bash: cannot set terminal process group (-1): Inappropriate ioctl for
>> device
>> bash: no job control in this shell
>
> Could you test this patch, please? And if it does not work: What is the
> content of /proc/1/fd/ and /proc/1/fdinfo/* for the working and non-working
> case? That are the only changes visible to userspace...
>
> Thanks,
> Dominik
>
> diff --git a/init/main.c b/init/main.c
> index 1ecfd43ed464..8886530e9dec 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1162,7 +1162,7 @@ void console_on_rootfs(void)
> unsigned int i;
>
> /* Open /dev/console in kernelspace, this should never fail */
> - file = filp_open("/dev/console", O_RDWR, 0);
> + file = filp_open("/dev/console", force_o_largefile() ? O_LARGEFILE |
> O_RDWR : O_RDWR, 0);
> if (IS_ERR(file))
> goto err_out;
>
>