2020-03-30 08:33:47

by Thibaut Sautereau

[permalink] [raw]
Subject: NULL pointer dereference in coredump code

I hit a kernel NULL pointer dereference caused by the following call chain:

do_coredump()
file_start_write(cprm.file) # cprm.file is NULL
file_inode(file) # NULL ptr deref

The `ispipe` path is followed in do_coredump(), and:
# cat /proc/sys/kernel/core_pattern
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h

It seems that cprm.file can be NULL after the call to the usermode
helper, especially when setting CONFIG_STATIC_USERMODEHELPER=y and
CONFIG_STATIC_USERMODEHELPER_PATH="", which is the case for me.

One may say it's a strange combination of configuration options but I
think it should not crash the kernel anyway. As I don't know much about
coredumps in general and this code, I don't know what's the best way to
fix this issue in a clean and comprehensive way.

I attached the patch I used to temporarily work around this issue, if
that can clarify anything.

Thanks,

--
Thibaut Sautereau
CLIP OS developer


Attachments:
(No filename) (971.00 B)
0001-coredump-FIXUP.patch (703.00 B)
Download all attachments

2020-05-19 07:18:59

by Thibaut Sautereau

[permalink] [raw]
Subject: Re: NULL pointer dereference in coredump code

On Mon, Mar 30, 2020 at 10:31:59AM +0200, Thibaut Sautereau wrote:
> I hit a kernel NULL pointer dereference caused by the following call chain:
>
> do_coredump()
> file_start_write(cprm.file) # cprm.file is NULL
> file_inode(file) # NULL ptr deref
>
> The `ispipe` path is followed in do_coredump(), and:
> # cat /proc/sys/kernel/core_pattern
> |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
>
> It seems that cprm.file can be NULL after the call to the usermode
> helper, especially when setting CONFIG_STATIC_USERMODEHELPER=y and
> CONFIG_STATIC_USERMODEHELPER_PATH="", which is the case for me.
>
> One may say it's a strange combination of configuration options but I
> think it should not crash the kernel anyway. As I don't know much about
> coredumps in general and this code, I don't know what's the best way to
> fix this issue in a clean and comprehensive way.
>
> I attached the patch I used to temporarily work around this issue, if
> that can clarify anything.
>
> Thanks,

For the record, this had previously been reported [1] and was eventually
fixed by 3740d93e3790 ("coredump: fix crash when umh is disabled").

[1] https://bugzilla.kernel.org/show_bug.cgi?id=199795

--
Thibaut Sautereau
CLIP OS developer