Commit eac0b6a
netlink: Fix wraparound of sk->sk_rmem_alloc
For netlink sockets, when comparing allocated rmem memory with the
rcvbuf limit, the comparison is done using signed values. This means
that if rcvbuf is near INT_MAX, then sk->sk_rmem_alloc may become
negative in the comparison with rcvbuf which will yield incorrect
results.
This can be reproduced by using the program from SOCK_DIAG(7) with
some slight modifications. First, setting sk->sk_rcvbuf to INT_MAX
using SO_RCVBUFFORCE and then secondly running the "send_query()"
in a loop while not calling "receive_responses()". In this case,
the value of sk->sk_rmem_alloc will continuously wrap around
and thus more memory is allocated than the sk->sk_rcvbuf limit.
This will eventually fill all of memory leading to an out of memory
condition with skbs filling up the slab.
Let's fix this in a similar manner to:
commit 5a465a0 ("udp: Fix multiple wraparounds of sk->sk_rmem_alloc.")
As noted in that fix, if there are multiple threads writing to a
netlink socket it's possible to slightly exceed rcvbuf value. But as
noted this avoids an expensive 'atomic_add_return()' for the common
case. I've confirmed that with the fix the modified program from
SOCK_DIAG(7) can no longer fill memory and the sk->sk_rcvbuf limit
is enforced.
Signed-off-by: Jason Baron <[email protected]>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: NipaLocal <nipa@local>1 parent f44c1ee commit eac0b6a
1 file changed
+21
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1216 | 1216 | | |
1217 | 1217 | | |
1218 | 1218 | | |
1219 | | - | |
1220 | | - | |
| 1219 | + | |
| 1220 | + | |
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
| |||
1230 | 1230 | | |
1231 | 1231 | | |
1232 | 1232 | | |
1233 | | - | |
| 1233 | + | |
1234 | 1234 | | |
1235 | 1235 | | |
1236 | 1236 | | |
| |||
1383 | 1383 | | |
1384 | 1384 | | |
1385 | 1385 | | |
| 1386 | + | |
1386 | 1387 | | |
1387 | | - | |
| 1388 | + | |
1388 | 1389 | | |
1389 | 1390 | | |
1390 | 1391 | | |
1391 | | - | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
1392 | 1395 | | |
1393 | 1396 | | |
1394 | 1397 | | |
| |||
1895 | 1898 | | |
1896 | 1899 | | |
1897 | 1900 | | |
| 1901 | + | |
1898 | 1902 | | |
1899 | 1903 | | |
1900 | 1904 | | |
| |||
1960 | 1964 | | |
1961 | 1965 | | |
1962 | 1966 | | |
1963 | | - | |
1964 | | - | |
1965 | | - | |
1966 | | - | |
1967 | | - | |
1968 | | - | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
1969 | 1976 | | |
1970 | 1977 | | |
1971 | 1978 | | |
| |||
2258 | 2265 | | |
2259 | 2266 | | |
2260 | 2267 | | |
2261 | | - | |
2262 | | - | |
2263 | | - | |
2264 | 2268 | | |
2265 | 2269 | | |
2266 | 2270 | | |
| |||
2283 | 2287 | | |
2284 | 2288 | | |
2285 | 2289 | | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
2286 | 2293 | | |
2287 | 2294 | | |
2288 | 2295 | | |
| |||
0 commit comments