Skip to contentSkip to conversation

init: Fix crash observed if there is no initial console

PATCH In review Guenter Roeck 1 participant 2 messages Dec 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init: Fix crash observed if there is no initial console

Systems with no initial console crash in f_dupfd(). This happens because console_on_rootfs() was changed to call filp_open(). Its return value (a file pointer) is checked against NULL, but returns an ERR_PTR after errors. This ERR_PTR is then passed as file parameter to f_dupfd(), which experiences a severe case of indigestion.

Cc Dominik Brodowski <[email protected]>
Cc Linus Torvalds <[email protected]>
Fixes 8243186f0cc7 ("fs: remove ksys_dup()"),
---
 init/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
init/main.c +1 -1
index ec3a1463ac69..1ecfd43ed464 100644
@@ -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 */
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Guenter Roeck

Systems with no initial console crash in f_dupfd(). This happens because console_on_rootfs() was changed to call filp_open(). Its return value (a file pointer) is checked against NULL, but returns an ERR_PTR after errors. This ERR_PTR is then passed as file parameter to f_dupfd(), which experiences a severe case of indigestion.

I should have pulled upstream before sending this. Sorry for the noise.

Guenter

Quoted 24 lines
Cc Dominik Brodowski <[email protected]>
Cc Linus Torvalds <[email protected]>
Fixes 8243186f0cc7 ("fs: remove ksys_dup()"),
---
 init/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
init/main.c +1 -1
index ec3a1463ac69..1ecfd43ed464 100644
@@ -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 */
Signature · 1 line
2.17.1