Commit f41557d
netlabel: fix RCU annotation for IPv4 options on socket creation
Xiumei reports the following splat when netlabel and TCP socket are used:
=============================
WARNING: suspicious RCU usage
6.9.0-rc2+ kernel-patches#637 Not tainted
-----------------------------
net/ipv4/cipso_ipv4.c:1880 suspicious rcu_dereference_protected() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
1 lock held by ncat/23333:
#0: ffffffff906030c0 (rcu_read_lock){....}-{1:2}, at: netlbl_sock_setattr+0x25/0x1b0
stack backtrace:
CPU: 11 PID: 23333 Comm: ncat Kdump: loaded Not tainted 6.9.0-rc2+ kernel-patches#637
Hardware name: Supermicro SYS-6027R-72RF/X9DRH-7TF/7F/iTF/iF, BIOS 3.0 07/26/2013
Call Trace:
<TASK>
dump_stack_lvl+0xa9/0xc0
lockdep_rcu_suspicious+0x117/0x190
cipso_v4_sock_setattr+0x1ab/0x1b0
netlbl_sock_setattr+0x13e/0x1b0
selinux_netlbl_socket_post_create+0x3f/0x80
selinux_socket_post_create+0x1a0/0x460
security_socket_post_create+0x42/0x60
__sock_create+0x342/0x3a0
__sys_socket_create.part.22+0x42/0x70
__sys_socket+0x37/0xb0
__x64_sys_socket+0x16/0x20
do_syscall_64+0x96/0x180
? do_user_addr_fault+0x68d/0xa30
? exc_page_fault+0x171/0x280
? asm_exc_page_fault+0x22/0x30
entry_SYSCALL_64_after_hwframe+0x71/0x79
RIP: 0033:0x7fbc0ca3fc1b
Code: 73 01 c3 48 8b 0d 05 f2 1b 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa b8 29 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d d5 f1 1b 00 f7 d8 64 89 01 48
RSP: 002b:00007fff18635208 EFLAGS: 00000246 ORIG_RAX: 0000000000000029
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007fbc0ca3fc1b
RDX: 0000000000000006 RSI: 0000000000000001 RDI: 0000000000000002
RBP: 000055d24f80f8a0 R08: 0000000000000003 R09: 0000000000000001
R10: 0000000000020000 R11: 0000000000000246 R12: 000055d24f80f8a0
R13: 0000000000000000 R14: 000055d24f80fb88 R15: 0000000000000000
</TASK>
The current implementation of cipso_v4_sock_setattr() replaces IP options
under the assumption that the caller holds the socket lock; however, such
assumption is not true, nor needed, in selinux_socket_post_create() hook.
Let all callers of cipso_v4_sock_setattr() specify the "socket lock held"
condition, except selinux_socket_post_create() _ where such condition can
safely be set as true even without holding the socket lock.
While at it: use rcu_replace_pointer() instead of open coding, and remove
useless NULL check of 'old' before kfree_rcu(old, ...).
v2:
- pass lockdep_sock_is_held() through a boolean variable in the stack
(thanks Eric Dumazet, Paul Moore, Casey Schaufler)
- use rcu_replace_pointer() instead of rcu_dereference_protected() +
rcu_assign_pointer()
- remove NULL check of 'old' before kfree_rcu()
Fixes: f6d8bd0 ("inet: add RCU protection to inet->opt")
Reported-by: Xiumei Mu <[email protected]>
Signed-off-by: Davide Caratti <[email protected]>
Signed-off-by: NipaLocal <nipa@local>1 parent 9a74f62 commit f41557d
File tree
6 files changed
+26
-16
lines changed- include/net
- net
- ipv4
- netlabel
- security
- selinux
- smack
6 files changed
+26
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
| 187 | + | |
187 | 188 | | |
188 | 189 | | |
189 | 190 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
217 | | - | |
| 218 | + | |
| 219 | + | |
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
473 | | - | |
| 473 | + | |
| 474 | + | |
474 | 475 | | |
475 | 476 | | |
476 | 477 | | |
| |||
614 | 615 | | |
615 | 616 | | |
616 | 617 | | |
617 | | - | |
| 618 | + | |
| 619 | + | |
618 | 620 | | |
619 | 621 | | |
620 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1815 | 1815 | | |
1816 | 1816 | | |
1817 | 1817 | | |
| 1818 | + | |
1818 | 1819 | | |
1819 | 1820 | | |
1820 | 1821 | | |
| |||
1826 | 1827 | | |
1827 | 1828 | | |
1828 | 1829 | | |
1829 | | - | |
| 1830 | + | |
| 1831 | + | |
1830 | 1832 | | |
1831 | 1833 | | |
1832 | 1834 | | |
| |||
1876 | 1878 | | |
1877 | 1879 | | |
1878 | 1880 | | |
1879 | | - | |
1880 | | - | |
| 1881 | + | |
1881 | 1882 | | |
1882 | 1883 | | |
1883 | 1884 | | |
1884 | 1885 | | |
1885 | | - | |
| 1886 | + | |
1886 | 1887 | | |
1887 | 1888 | | |
1888 | | - | |
1889 | | - | |
1890 | | - | |
| 1889 | + | |
1891 | 1890 | | |
1892 | 1891 | | |
1893 | 1892 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
965 | 965 | | |
966 | 966 | | |
967 | 967 | | |
| 968 | + | |
968 | 969 | | |
969 | 970 | | |
970 | 971 | | |
| |||
977 | 978 | | |
978 | 979 | | |
979 | 980 | | |
980 | | - | |
| 981 | + | |
| 982 | + | |
981 | 983 | | |
982 | 984 | | |
983 | 985 | | |
| |||
997 | 999 | | |
998 | 1000 | | |
999 | 1001 | | |
1000 | | - | |
| 1002 | + | |
1001 | 1003 | | |
1002 | 1004 | | |
1003 | 1005 | | |
| |||
1126 | 1128 | | |
1127 | 1129 | | |
1128 | 1130 | | |
1129 | | - | |
| 1131 | + | |
| 1132 | + | |
1130 | 1133 | | |
1131 | 1134 | | |
1132 | 1135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
406 | 409 | | |
407 | 410 | | |
408 | 411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2565 | 2565 | | |
2566 | 2566 | | |
2567 | 2567 | | |
2568 | | - | |
| 2568 | + | |
| 2569 | + | |
2569 | 2570 | | |
2570 | 2571 | | |
2571 | 2572 | | |
| |||
0 commit comments