Skip to content

Commit 9915672

Browse files
Eric Dumazetdavem330
authored andcommitted
af_unix: limit unix_tot_inflight
Vegard Nossum found a unix socket OOM was possible, posting an exploit program. My analysis is we can eat all LOWMEM memory before unix_gc() being called from unix_release_sock(). Moreover, the thread blocked in unix_gc() can consume huge amount of time to perform cleanup because of huge working set. One way to handle this is to have a sensible limit on unix_tot_inflight, tested from wait_for_unix_gc() and to force a call to unix_gc() if this limit is hit. This solves the OOM and also reduce overall latencies, and should not slowdown normal workloads. Reported-by: Vegard Nossum <vegard.nossum@gmail.com> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cf41a51 commit 9915672

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

net/unix/garbage.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,16 @@ static void inc_inflight_move_tail(struct unix_sock *u)
259259
}
260260

261261
static bool gc_in_progress = false;
262+
#define UNIX_INFLIGHT_TRIGGER_GC 16000
262263

263264
void wait_for_unix_gc(void)
264265
{
266+
/*
267+
* If number of inflight sockets is insane,
268+
* force a garbage collect right now.
269+
*/
270+
if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress)
271+
unix_gc();
265272
wait_event(unix_gc_wait, gc_in_progress == false);
266273
}
267274

0 commit comments

Comments
 (0)