projects/linux·commit 2d3145f8

early init: fix error handling when opening /dev/console

2d3145f8 · Linus Torvalds <[email protected]> · 2019-12-17 13:10:11 -08:00

The comment says "this should never fail", but it definitely can fail
when you have odd initial boot filesystems, or kernel configurations.

So get the error handling right: filp_open() returns an error pointer.

Reported-by: Jesse Barnes <[email protected]>
Reported-by: youling 257 <[email protected]>
Fixes: 8243186f0cc7 ("fs: remove ksys_dup()")
Cc: Dominik Brodowski <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Commit
2d3145f8d2809592ef803a30c8a342b5a9e2de9a
Parents
58d90a04

Changes

1 files changed · +1 −1

FileStatusAddDelContent
init/main.cmodified+1−1View file

init/main.c

View file
diff --git a/init/main.c b/init/main.c
index ec3a146..1ecfd43 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1163,7 +1163,7 @@ void console_on_rootfs(void)
/* Open /dev/console in kernelspace, this should never fail */
file = filp_open("/dev/console", O_RDWR, 0);
- if (!file)
+ if (IS_ERR(file))
goto err_out;
/* create stdin/stdout/stderr, this should never fail */