Commit 393c8b4
kcm: switch order of device registration to fix a crash
[ Upstream commit 3c446e6 ]
When kcm is loaded while many processes try to create a KCM socket, a
crash occurs:
BUG: unable to handle kernel NULL pointer dereference at 000000000000000e
IP: mutex_lock+0x27/0x40 kernel/locking/mutex.c:240
PGD 8000000016ef2067 P4D 8000000016ef2067 PUD 3d6e9067 PMD 0
Oops: 0002 [#1] SMP KASAN PTI
CPU: 0 PID: 7005 Comm: syz-executor.5 Not tainted 4.12.14-396-default #1 SLE15-SP1 (unreleased)
RIP: 0010:mutex_lock+0x27/0x40 kernel/locking/mutex.c:240
RSP: 0018:ffff88000d487a00 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 000000000000000e RCX: 1ffff100082b0719
...
CR2: 000000000000000e CR3: 000000004b1bc003 CR4: 0000000000060ef0
Call Trace:
kcm_create+0x600/0xbf0 [kcm]
__sock_create+0x324/0x750 net/socket.c:1272
...
This is due to race between sock_create and unfinished
register_pernet_device. kcm_create tries to do "net_generic(net,
kcm_net_id)". but kcm_net_id is not initialized yet.
So switch the order of the two to close the race.
This can be reproduced with mutiple processes doing socket(PF_KCM, ...)
and one process doing module removal.
Fixes: ab7ac4e ("kcm: Kernel Connection Multiplexor module")
Reviewed-by: Michal Kubecek <[email protected]>
Signed-off-by: Jiri Slaby <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>1 parent b74c299 commit 393c8b4
1 file changed
+8
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2059 | 2059 | | |
2060 | 2060 | | |
2061 | 2061 | | |
2062 | | - | |
2063 | | - | |
2064 | | - | |
2065 | | - | |
2066 | 2062 | | |
2067 | 2063 | | |
2068 | 2064 | | |
2069 | 2065 | | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
2070 | 2070 | | |
2071 | 2071 | | |
2072 | 2072 | | |
2073 | 2073 | | |
2074 | 2074 | | |
2075 | 2075 | | |
2076 | 2076 | | |
2077 | | - | |
2078 | | - | |
2079 | | - | |
2080 | 2077 | | |
2081 | 2078 | | |
2082 | 2079 | | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
2083 | 2083 | | |
2084 | 2084 | | |
2085 | 2085 | | |
| |||
2095 | 2095 | | |
2096 | 2096 | | |
2097 | 2097 | | |
2098 | | - | |
2099 | 2098 | | |
| 2099 | + | |
2100 | 2100 | | |
2101 | 2101 | | |
2102 | 2102 | | |
| |||
0 commit comments