Skip to content

Commit 0523820

Browse files
fableddavem330
authored andcommitted
af_key: Free dumping state on socket close
Fix a xfrm_{state,policy}_walk leak if pfkey socket is closed while dumping is on-going. Signed-off-by: Timo Teras <timo.teras@iki.fi> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5dc121e commit 0523820

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎net/key/af_key.c‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,18 @@ static int pfkey_can_dump(struct sock *sk)
7373
return 0;
7474
}
7575

76-
static int pfkey_do_dump(struct pfkey_sock *pfk)
76+
static void pfkey_terminate_dump(struct pfkey_sock *pfk)
7777
{
78-
int rc;
79-
80-
rc = pfk->dump.dump(pfk);
81-
if (rc == -ENOBUFS)
82-
return 0;
83-
84-
pfk->dump.done(pfk);
85-
pfk->dump.dump = NULL;
86-
pfk->dump.done = NULL;
87-
return rc;
78+
if (pfk->dump.dump) {
79+
pfk->dump.done(pfk);
80+
pfk->dump.dump = NULL;
81+
pfk->dump.done = NULL;
82+
}
8883
}
8984

9085
static void pfkey_sock_destruct(struct sock *sk)
9186
{
87+
pfkey_terminate_dump(pfkey_sk(sk));
9288
skb_queue_purge(&sk->sk_receive_queue);
9389

9490
if (!sock_flag(sk, SOCK_DEAD)) {
@@ -310,6 +306,18 @@ static int pfkey_broadcast(struct sk_buff *skb, gfp_t allocation,
310306
return err;
311307
}
312308

309+
static int pfkey_do_dump(struct pfkey_sock *pfk)
310+
{
311+
int rc;
312+
313+
rc = pfk->dump.dump(pfk);
314+
if (rc == -ENOBUFS)
315+
return 0;
316+
317+
pfkey_terminate_dump(pfk);
318+
return rc;
319+
}
320+
313321
static inline void pfkey_hdr_dup(struct sadb_msg *new, struct sadb_msg *orig)
314322
{
315323
*new = *orig;

0 commit comments

Comments
 (0)