Skip to content

Commit 580acf6

Browse files
author
Paolo Abeni
committed
Merge branch 'af_unix-fix-gc-and-improve-selftest'
Michal Luczaj says: ==================== af_unix: Fix GC and improve selftest Series deals with AF_UNIX garbage collector mishandling some in-flight graph cycles. Embryos carrying OOB packets with SCM_RIGHTS cause issues. Patch 1/2 fixes the memory leak. Patch 2/2 tweaks the selftest for a better OOB coverage. v3: - Patch 1/2: correct the commit message (Kuniyuki) v2: https://lore.kernel.org/netdev/[email protected]/ - Patch 1/2: remove WARN_ON_ONCE() (Kuniyuki) - Combine both patches into a series (Kuniyuki) v1: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 3ebc46c + e060e43 commit 580acf6

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

net/unix/garbage.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ enum unix_recv_queue_lock_class {
342342
U_RECVQ_LOCK_EMBRYO,
343343
};
344344

345+
static void unix_collect_queue(struct unix_sock *u, struct sk_buff_head *hitlist)
346+
{
347+
skb_queue_splice_init(&u->sk.sk_receive_queue, hitlist);
348+
349+
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
350+
if (u->oob_skb) {
351+
WARN_ON_ONCE(skb_unref(u->oob_skb));
352+
u->oob_skb = NULL;
353+
}
354+
#endif
355+
}
356+
345357
static void unix_collect_skb(struct list_head *scc, struct sk_buff_head *hitlist)
346358
{
347359
struct unix_vertex *vertex;
@@ -365,18 +377,11 @@ static void unix_collect_skb(struct list_head *scc, struct sk_buff_head *hitlist
365377

366378
/* listener -> embryo order, the inversion never happens. */
367379
spin_lock_nested(&embryo_queue->lock, U_RECVQ_LOCK_EMBRYO);
368-
skb_queue_splice_init(embryo_queue, hitlist);
380+
unix_collect_queue(unix_sk(skb->sk), hitlist);
369381
spin_unlock(&embryo_queue->lock);
370382
}
371383
} else {
372-
skb_queue_splice_init(queue, hitlist);
373-
374-
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
375-
if (u->oob_skb) {
376-
kfree_skb(u->oob_skb);
377-
u->oob_skb = NULL;
378-
}
379-
#endif
384+
unix_collect_queue(u, hitlist);
380385
}
381386

382387
spin_unlock(&queue->lock);

tools/testing/selftests/net/af_unix/scm_rights.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ void __send_fd(struct __test_metadata *_metadata,
197197
const FIXTURE_VARIANT(scm_rights) *variant,
198198
int inflight, int receiver)
199199
{
200-
#define MSG "nop"
201-
#define MSGLEN 3
200+
#define MSG "x"
201+
#define MSGLEN 1
202202
struct {
203203
struct cmsghdr cmsghdr;
204204
int fd[2];

0 commit comments

Comments
 (0)