kernel NULL pointer deref in pipe() - hotplug in initramfs
In-Reply-To: <[email protected]>
Quoted 2 lines · Michael Tokarev
When
/sbin/hotplugis present in initramfs, and it's a shell script, kernel OOPSes on every hotplug invocation.
Does this mean that if it's _not_ a shell script everything is fine?
----------------------
<4> <1>BUG: unable to handle kernel NULL pointer dereference at virtual address 00000014 <1> printing eip:
<4>c015c80a
<1>*pde = 00000000
<0>Oops: 0000 [#2]
<4>Modules linked in:
<0>CPU: 0
<0>EIP: 0060:[<c015c80a>] Not tainted VLI
<0>EFLAGS: 00010282 (2.6.19-c3 #2.6.19.0)
<0>EIP is at create_write_pipe+0x1a/0x1c0
<0>eax: 00000000 ebx: bfb07cfc ecx: 00000000 edx: c13915a0 <0>esi: cf739820 edi: ffffffff ebp: c13a2fa8 esp: c13a2f40
<0>ds: 007b es: 007b ss: 0068
<0>Process hotplug (pid: 34, ti=c13a2000 task=c13915a0 task.ti=c13a2000)
<0>Stack: 00001fff c1382da0 c137fba0 c1387b7c 00000000 c12b2ce0 080dfd04 080dfd04
<0> 00000003 c015a27f 00000000 c1382da0 b7f64d30 00000004 c011412a 00000000
<0> bfb07cfc 00000004 ffffffff c015cfde c137fba0 bfb07cfc 00000004 ffffffff
<0>Call Trace:
<0> [<c015cfde>] do_pipe+0xe/0xa0
<0> [<c0107cac>] sys_pipe+0xc/0x40
<0> [<c0102eb7>] syscall_call+0x7/0xb
<0> [<b7f6607d>] 0xb7f6607d
<0> =======================
<0>Code: 00 00 00 89 b3 74 01 00 00 89 d8 5b 5e c3 8d 76 00 57 56 53 83 ec 40 e8 35 bb ff ff 89 c6 85 c0 0f 84 7b 01 00 00 a1 c0 85 2d c0 <8b> 40 14 e8 de d0 00 00 89 c3 85 c0 0f 84 44 01 00 00 e8 8f ff <0>EIP: [<c015c80a>] create_write_pipe+0x1a/0x1c0 SS:ESP 0068:c13a2f40
<4> <1>BUG: unable to handle kernel NULL pointer dereference at virtual address 00000014
<1> printing eip:
----------------------
Quoted 1 line
(note also the formatting is a bit wrong here -- that <4> prefix in front of <1>BUG..)
Yeah, that's from the previous oops. I don't know why bust_spinlocks() leaves that hanging space, but it's been that way for a long time.
BTW did you hand-edit the kernel .version file? "(2.6.19-c3 #2.6.19.0)" should not print unless you put that 2.6.19.0 there yourself.
Quoted 1 line
Are pipes disallowed in hotplug fired off initramfs?
AFAICT the pipe filesystem isn't registered yet, so probably not.
Quoted 1 line
(Even if they are, kernel probably still should not OOPS like that ;)
Either (a) pipefs should be registered early, or (b) the call should just fail instead of oopsing. Untested patch for (b) below, can you test it? (I'm not messing with the init sequence.)
Quoted 2 lines
The error seems to be harmful however. That is, hotplug script does not run, but the kernel continues running.
You mean harmless, right?
fs/pipe.c +3 -1
@@ -839,9 +839,11 @@ static struct dentry_operations pipefs_dstatic struct inode *get_pipe_inode (void ) { -struct inode *inode =new_inode (pipe_mnt->mnt_sb); +struct inode *inode =NULL ;struct pipe_inode_info *pipe; +if (pipe_mnt) + inode =new_inode (pipe_mnt->mnt_sb);if (!inode) goto fail_inode;
Signature · 2 lines
Chuck "Even supernovas have their duller moments."
Quoted 9 lines · Chuck Ebbert
In-Reply-To: <[email protected]>
Quoted 2 lines · Michael Tokarev
When
/sbin/hotplugis present in initramfs, and it's a shell script, kernel OOPSes on every hotplug invocation.Does this mean that if it's _not_ a shell script everything is fine?
It means that if there's no pipe() call, everything is fine. That is, for a shell script it's just more likely to contain some pipelines.
[]
Quoted 1 line
Quoted 1 line
<0>EFLAGS: 00010282 (2.6.19-c3 #2.6.19.0)
[]
Quoted 5 lines
Quoted 2 lines
<4> <1>BUG: unable to handle kernel NULL pointer dereference at virtual address 00000014 (note also the formatting is a bit wrong here -- that <4> prefix in front of <1>BUG..)
Yeah, that's from the previous oops. I don't know why
bust_spinlocks()leaves that hanging space, but it's been that way for a long time.
So can this be fixed, too? ;)
Quoted 2 lines
BTW did you hand-edit the kernel .version file? "(2.6.19-c3 #2.6.19.0)" should not print unless you put that 2.6.19.0 there yourself.
Yes I did. For an rpm- or deb-based kernel, the "build number" is irrelevant (it's always 1, since both rpm and deb rebuilds everything from scratch). This #2.6.19.0 comes from the package revision number - I just do
echo $revision > .version
and remove the part from Makefile which updates the file on every (re)build. But this isn't relevant for the discussion.
Quoted 6 lines
Quoted 1 line
Are pipes disallowed in hotplug fired off initramfs?
AFAICT the pipe filesystem isn't registered yet, so probably not.
Quoted 1 line
(Even if they are, kernel probably still should not OOPS like that ;)
Quoted 8 lines
Either (a) pipefs should be registered early, or (b) the call should just fail instead of oopsing. Untested patch for (b) below, can you test it? (I'm not messing with the init sequence.)
Quoted 2 lines
The error seems to be harmful however. That is, hotplug script does not run, but the kernel continues running.
You mean harmless, right?
Yup. Oh those foreign languages... :)
fs/pipe.c
Quoted 4 lines
Signed-off-by Chuck Ebbert <[email protected]>fs/pipe.c +0
-0
Another funny revision number? ;)
fs/pipe.c static struct dentry_operations pipefs_d · line 848
Quoted 12 lines
fs/pipe.c +3
-1@@ -839,9 +839,11 @@ static struct dentry_operations pipefs_dstatic struct inode *get_pipe_inode (void ) { -struct inode *inode =new_inode (pipe_mnt->mnt_sb); +struct inode *inode =NULL ;struct pipe_inode_info *pipe; +if (pipe_mnt) + inode =new_inode (pipe_mnt->mnt_sb);if (!inode) goto fail_inode;
Well, that fixes the OOPs, but I'd do it a in bit more readable way, and eliminating the gotos too (this is a stylistic change - I see alot of gotos in kernel for error returns, but here, in such a small function, gotos looks somewhat funny, esp. when the only statement after the label is 'return NULL'):
fs/pipe.c renamed from fs/pipe.c.orig +9 -10
@@ -839,15 +839,20 @@ static struct dentry_operations pipefs_dstatic struct inode *get_pipe_inode (void ) { -struct inode *inode =new_inode (pipe_mnt->mnt_sb); +struct inode *inode;struct pipe_inode_info *pipe; +if (!pipe_mnt)/* if pipefs isn't mounted (yet) */ +return NULL ; + inode =new_inode (pipe_mnt->mnt_sb);if (!inode) - goto fail_inode; +return NULL ; pipe =alloc_pipe_info (inode); -if (!pipe) - goto fail_iput; +if (!pipe) { +iput (inode); +return NULL ; + } inode->i_pipe = pipe; pipe->readers = pipe->writers =1 ;
@@ -866,12 +871,6 @@ static struct inode * get_pipe_inode(voi inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;return inode; - -fail_iput: -iput (inode); - -fail_inode: -return NULL ; }struct file *create_write_pipe (void )
Or like this (without messing up with goto):
fs/pipe.c renamed from fs/pipe.c.orig +4 -1
@@ -839,9 +839,12 @@ static struct dentry_operations pipefs_dstatic struct inode *get_pipe_inode (void ) { -struct inode *inode =new_inode (pipe_mnt->mnt_sb); +struct inode *inode;struct pipe_inode_info *pipe; +if (!pipe_mnt)/* in case pipefs isn't mounted (yet) */ + goto fail_inode; + inode =new_inode (pipe_mnt->mnt_sb);if (!inode) goto fail_inode;
In either case, this change not fixes the problem. As I said, the OOPs is harmless (yes, not harmful :), so the end effect is the same, just instead of the OOPs, now the bad stuff is coming from shell complaining about failing to create pipe.
/mjt