Commit e9f2517
smb: client: fix TCP timers deadlock after rmmod
Commit ef7134c ("smb: client: Fix use-after-free of network namespace.")
fixed a netns UAF by manually enabled socket refcounting
(sk->sk_net_refcnt=1 and sock_inuse_add(net, 1)).
The reason the patch worked for that bug was because we now hold
references to the netns (get_net_track() gets a ref internally)
and they're properly released (internally, on __sk_destruct()),
but only because sk->sk_net_refcnt was set.
Problem:
(this happens regardless of CONFIG_NET_NS_REFCNT_TRACKER and regardless
if init_net or other)
Setting sk->sk_net_refcnt=1 *manually* and *after* socket creation is not
only out of cifs scope, but also technically wrong -- it's set conditionally
based on user (=1) vs kernel (=0) sockets. And net/ implementations
seem to base their user vs kernel space operations on it.
e.g. upon TCP socket close, the TCP timers are not cleared because
sk->sk_net_refcnt=1:
(cf. commit 151c9c7 ("tcp: properly terminate timers for kernel sockets"))
net/ipv4/tcp.c:
void tcp_close(struct sock *sk, long timeout)
{
lock_sock(sk);
__tcp_close(sk, timeout);
release_sock(sk);
if (!sk->sk_net_refcnt)
inet_csk_clear_xmit_timers_sync(sk);
sock_put(sk);
}
Which will throw a lockdep warning and then, as expected, deadlock on
tcp_write_timer().
A way to reproduce this is by running the reproducer from ef7134c
and then 'rmmod cifs'. A few seconds later, the deadlock/lockdep
warning shows up.
Fix:
We shouldn't mess with socket internals ourselves, so do not set
sk_net_refcnt manually.
Also change __sock_create() to sock_create_kern() for explicitness.
As for non-init_net network namespaces, we deal with it the best way
we can -- hold an extra netns reference for server->ssocket and drop it
when it's released. This ensures that the netns still exists whenever
we need to create/destroy server->ssocket, but is not directly tied to
it.
Fixes: ef7134c ("smb: client: Fix use-after-free of network namespace.")
Cc: [email protected]
Signed-off-by: Enzo Matsumiya <[email protected]>
Signed-off-by: Steve French <[email protected]>1 parent ee1c8e6 commit e9f2517
1 file changed
+26
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
987 | 987 | | |
988 | 988 | | |
989 | 989 | | |
| 990 | + | |
990 | 991 | | |
991 | 992 | | |
992 | 993 | | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
993 | 997 | | |
994 | 998 | | |
995 | 999 | | |
| |||
1037 | 1041 | | |
1038 | 1042 | | |
1039 | 1043 | | |
| 1044 | + | |
1040 | 1045 | | |
1041 | 1046 | | |
1042 | 1047 | | |
| |||
1713 | 1718 | | |
1714 | 1719 | | |
1715 | 1720 | | |
| 1721 | + | |
| 1722 | + | |
1716 | 1723 | | |
1717 | 1724 | | |
1718 | 1725 | | |
| |||
1844 | 1851 | | |
1845 | 1852 | | |
1846 | 1853 | | |
| 1854 | + | |
1847 | 1855 | | |
1848 | 1856 | | |
1849 | 1857 | | |
| |||
1852 | 1860 | | |
1853 | 1861 | | |
1854 | 1862 | | |
1855 | | - | |
| 1863 | + | |
1856 | 1864 | | |
| 1865 | + | |
| 1866 | + | |
1857 | 1867 | | |
1858 | 1868 | | |
1859 | 1869 | | |
| |||
3131 | 3141 | | |
3132 | 3142 | | |
3133 | 3143 | | |
3134 | | - | |
3135 | 3144 | | |
3136 | | - | |
3137 | | - | |
| 3145 | + | |
3138 | 3146 | | |
3139 | 3147 | | |
3140 | 3148 | | |
3141 | 3149 | | |
3142 | 3150 | | |
3143 | | - | |
3144 | | - | |
3145 | | - | |
3146 | | - | |
3147 | | - | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
3148 | 3158 | | |
3149 | 3159 | | |
3150 | 3160 | | |
| |||
3158 | 3168 | | |
3159 | 3169 | | |
3160 | 3170 | | |
3161 | | - | |
| 3171 | + | |
| 3172 | + | |
3162 | 3173 | | |
| 3174 | + | |
3163 | 3175 | | |
3164 | 3176 | | |
3165 | 3177 | | |
| |||
3196 | 3208 | | |
3197 | 3209 | | |
3198 | 3210 | | |
| 3211 | + | |
3199 | 3212 | | |
3200 | 3213 | | |
3201 | 3214 | | |
| |||
3204 | 3217 | | |
3205 | 3218 | | |
3206 | 3219 | | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
3207 | 3223 | | |
3208 | 3224 | | |
3209 | 3225 | | |
| |||
0 commit comments