Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1636047 > unrolled thread
| Started by | Rob Landley <rob@landley.net> |
|---|---|
| First post | 2017-05-04 23:10 +0200 |
| Last post | 2017-05-11 19:10 +0200 |
| Articles | 5 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] Make initramfs honor CONFIG_DEVTMPFS_MOUNT Rob Landley <rob@landley.net> - 2017-05-04 23:10 +0200
Re: [PATCH] Make initramfs honor CONFIG_DEVTMPFS_MOUNT Kees Cook <keescook@chromium.org> - 2017-05-05 01:40 +0200
Re: [PATCH] Make initramfs honor CONFIG_DEVTMPFS_MOUNT Andrew Morton <akpm@linux-foundation.org> - 2017-05-09 23:40 +0200
Re: [PATCH] Make initramfs honor CONFIG_DEVTMPFS_MOUNT Rob Landley <rob@landley.net> - 2017-05-11 19:10 +0200
[PATCHv2] Make initramfs honor CONFIG_DEVTMPFS_MOUNT Rob Landley <rob@landley.net> - 2017-05-11 19:10 +0200
| From | Rob Landley <rob@landley.net> |
|---|---|
| Date | 2017-05-04 23:10 +0200 |
| Subject | [PATCH] Make initramfs honor CONFIG_DEVTMPFS_MOUNT |
| Message-ID | <tDwaC-tB-5@gated-at.bofh.it> |
From: Rob Landley <rob@landley.net>
Make initramfs honor CONFIG_DEVTMPFS_MOUNT, and move
/dev/console open after devtmpfs mount.
Signed-off-by: Rob Landley <rob@landley.net>
---
init/main.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/init/main.c b/init/main.c
index 2858be7..71ed0d7 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1016,12 +1016,6 @@ static noinline void __init kernel_init_freeable(void)
do_basic_setup();
- /* Open the /dev/console on the rootfs, this should never fail */
- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
- pr_err("Warning: unable to open an initial console.\n");
-
- (void) sys_dup(0);
- (void) sys_dup(0);
/*
* check if there is an early userspace init. If yes, let it do all
* the work
@@ -1033,8 +1027,17 @@ static noinline void __init kernel_init_freeable(void)
if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
ramdisk_execute_command = NULL;
prepare_namespace();
+ } else if (IS_ENABLED(CONFIG_DEVTMPFS_MOUNT)) {
+ sys_mkdir("/dev", 0755);
+ sys_mount("dev", "dev", "devtmpfs", MS_SILENT, NULL);
}
+ /* Open the /dev/console on the rootfs, this should never fail */
+ if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+ pr_err("Warning: unable to open an initial console.\n");
+ (void) sys_dup(0);
+ (void) sys_dup(0);
+
/*
* Ok, we have completed the initial bootup, and
* we're essentially up and running. Get rid of the
[toc] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2017-05-05 01:40 +0200 |
| Message-ID | <tDyvL-1QX-3@gated-at.bofh.it> |
| In reply to | #1636047 |
On Thu, May 4, 2017 at 2:09 PM, Rob Landley <rob@landley.net> wrote:
> From: Rob Landley <rob@landley.net>
>
> Make initramfs honor CONFIG_DEVTMPFS_MOUNT, and move
> /dev/console open after devtmpfs mount.
>
> Signed-off-by: Rob Landley <rob@landley.net>
Seems sensible.
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
>
> init/main.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/init/main.c b/init/main.c
> index 2858be7..71ed0d7 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1016,12 +1016,6 @@ static noinline void __init kernel_init_freeable(void)
>
> do_basic_setup();
>
> - /* Open the /dev/console on the rootfs, this should never fail */
> - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
> - pr_err("Warning: unable to open an initial console.\n");
> -
> - (void) sys_dup(0);
> - (void) sys_dup(0);
> /*
> * check if there is an early userspace init. If yes, let it do all
> * the work
> @@ -1033,8 +1027,17 @@ static noinline void __init kernel_init_freeable(void)
> if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
> ramdisk_execute_command = NULL;
> prepare_namespace();
> + } else if (IS_ENABLED(CONFIG_DEVTMPFS_MOUNT)) {
> + sys_mkdir("/dev", 0755);
> + sys_mount("dev", "dev", "devtmpfs", MS_SILENT, NULL);
> }
>
> + /* Open the /dev/console on the rootfs, this should never fail */
> + if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
> + pr_err("Warning: unable to open an initial console.\n");
> + (void) sys_dup(0);
> + (void) sys_dup(0);
> +
> /*
> * Ok, we have completed the initial bootup, and
> * we're essentially up and running. Get rid of the
--
Kees Cook
Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Date | 2017-05-09 23:40 +0200 |
| Message-ID | <tFl1n-7qN-1@gated-at.bofh.it> |
| In reply to | #1636047 |
On Thu, 4 May 2017 16:09:06 -0500 Rob Landley <rob@landley.net> wrote: > From: Rob Landley <rob@landley.net> > > Make initramfs honor CONFIG_DEVTMPFS_MOUNT, and move > /dev/console open after devtmpfs mount. Could we please see complete description of the runtime effects of this change? How does it affect users? How does it benefit users? The DEVTMPFS_MOUNT Kconfig help (drivers/base/Kconfig) says: This option does not affect initramfs based booting, here the devtmpfs filesystem always needs to be mounted manually after the rootfs is mounted. which seems to no longer be correct?
[toc] | [prev] | [next] | [standalone]
| From | Rob Landley <rob@landley.net> |
|---|---|
| Date | 2017-05-11 19:10 +0200 |
| Message-ID | <tFZLb-KD-3@gated-at.bofh.it> |
| In reply to | #1638410 |
On 05/09/2017 04:31 PM, Andrew Morton wrote: > On Thu, 4 May 2017 16:09:06 -0500 Rob Landley <rob@landley.net> wrote: > >> From: Rob Landley <rob@landley.net> >> >> Make initramfs honor CONFIG_DEVTMPFS_MOUNT, and move >> /dev/console open after devtmpfs mount. > > > Could we please see complete description of the runtime effects of this > change? How does it affect users? How does it benefit users? It makes the behavior consistent. If you're going to have the config symbol anyway, why is initramfs a second class citizen? That said, I was fixing a specific bug when I started the patch: when you statically link in an initramfs by pointing the kernel build at a directory (so it makes its own cpio archive from that), if you're not running the build as root you can't create dev/console in there and there's no obvious way to add nodes (like you can editing the gen_initramfs_list) output. This means there's no /dev/console when init gets launched, so PID 1's stdin/stdout/stderr go nowhere, and until your init script can open its own and redirect you get no output if something goes wrong, so debugging is fiddly and there's a hole where output gets lost. Userspace can't close that hole. When making the patch I did a version that mounted /proc /sys and /dev/pts too, so rdinit=/bin/sh had pretty much its full environment without an init script just like the DEVTMPFS_MOUNT option's help text implied... but that seemed unlikely to be accepted. The console gap is a problem userspace can't fix, the rest userspace can, so I did the minimal thing. > The DEVTMPFS_MOUNT Kconfig help (drivers/base/Kconfig) says: > > This option does not affect initramfs based booting, here > the devtmpfs filesystem always needs to be mounted manually > after the rootfs is mounted. > > which seems to no longer be correct? Ah, sorry. I rewrote the help text and didn't include that file in the diff. And rechecking I see the override part wasn't implemented by my patch, I'll send a new one. Rob
[toc] | [prev] | [next] | [standalone]
| From | Rob Landley <rob@landley.net> |
|---|---|
| Date | 2017-05-11 19:10 +0200 |
| Subject | [PATCHv2] Make initramfs honor CONFIG_DEVTMPFS_MOUNT |
| Message-ID | <tFZLc-KD-9@gated-at.bofh.it> |
| In reply to | #1638410 |
From: Rob Landley <rob@landley.net>
Make initramfs honor CONFIG_DEVTMPFS_MOUNT, move /dev/console
open after devtmpfs mount, and update help text.
Signed-off-by: Rob Landley <rob@landley.net>
---
drivers/base/Kconfig | 14 ++++----------
init/main.c | 15 +++++++++------
2 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d718ae4..74779ee 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -48,16 +48,10 @@ config DEVTMPFS_MOUNT
bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs"
depends on DEVTMPFS
help
- This will instruct the kernel to automatically mount the
- devtmpfs filesystem at /dev, directly after the kernel has
- mounted the root filesystem. The behavior can be overridden
- with the commandline parameter: devtmpfs.mount=0|1.
- This option does not affect initramfs based booting, here
- the devtmpfs filesystem always needs to be mounted manually
- after the rootfs is mounted.
- With this option enabled, it allows to bring up a system in
- rescue mode with init=/bin/sh, even when the /dev directory
- on the rootfs is completely empty.
+ Automatically mount devtmpfs at /dev on the root filesystem, which
+ lets the system come up in rescue mode with [rd]init=/bin/sh.
+ Override with devtmpfs.mount=0 on the commandline. Initramfs can
+ create a /dev dir as needed, other rootfs needs the mount point.
config STANDALONE
bool "Select only drivers that don't need compile-time external firmware"
diff --git a/init/main.c b/init/main.c
index f866510..9ec09ff 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1038,12 +1038,6 @@ static noinline void __init kernel_init_freeable(void)
do_basic_setup();
- /* Open the /dev/console on the rootfs, this should never fail */
- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
- pr_err("Warning: unable to open an initial console.\n");
-
- (void) sys_dup(0);
- (void) sys_dup(0);
/*
* check if there is an early userspace init. If yes, let it do all
* the work
@@ -1055,8 +1049,17 @@ static noinline void __init kernel_init_freeable(void)
if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
ramdisk_execute_command = NULL;
prepare_namespace();
+ } else if (IS_ENABLED(CONFIG_DEVTMPFS_MOUNT)) {
+ sys_mkdir("/dev", 0755);
+ devtmpfs_mount("/dev");
}
+ /* Open the /dev/console on the rootfs, this should never fail */
+ if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+ pr_err("Warning: unable to open an initial console.\n");
+ (void) sys_dup(0);
+ (void) sys_dup(0);
+
/*
* Ok, we have completed the initial bootup, and
* we're essentially up and running. Get rid of the
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web