Patch "netlink: Do not schedule work from sk_destruct" has been added to the 4.8-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
netlink: Do not schedule work from sk_destruct
to the 4.8-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
netlink-do-not-schedule-work-from-sk_destruct.patch
and it can be found in the queue-4.8 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Thu Dec 8 07:19:12 CET 2016
From: Herbert Xu <[email protected]>
Date: Mon, 5 Dec 2016 15:28:21 +0800
Subject: netlink: Do not schedule work from sk_destruct
From: Herbert Xu <[email protected]>
[ Upstream commit ed5d7788a934a4b6d6d025e948ed4da496b4f12e ]
It is wrong to schedule a work from sk_destruct using the socket as the memory reserve because the socket will be freed immediately after the return from sk_destruct.
Instead we should do the deferral prior to sk_free.
This patch does just that.
--- net/netlink/af_netlink.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
net/netlink/af_netlink.c +15 -17
@@ -322,11 +322,13 @@ static void netlink_skb_set_owner_r(strusk_mem_charge (sk, skb->truesize); } -static void __netlink_sock_destruct (struct sock *sk) +static void netlink_sock_destruct (struct sock *sk) {struct netlink_sock *nlk =nlk_sk (sk);if (nlk->cb_running) { +if (nlk->cb.done) + nlk->cb.done (&nlk->cb);module_put (nlk->cb.module);kfree_skb (nlk->cb.skb); }
@@ -348,21 +350,7 @@ static void netlink_sock_destruct_work(s struct netlink_sock *nlk = container_of(work, struct netlink_sock, work); - nlk->cb.done (&nlk->cb); -__netlink_sock_destruct (&nlk->sk); -} - -static void netlink_sock_destruct (struct sock *sk) -{ -struct netlink_sock *nlk =nlk_sk (sk); - -if (nlk->cb_running && nlk->cb.done) { -INIT_WORK (&nlk->work, netlink_sock_destruct_work); -schedule_work (&nlk->work); -return ; - } - -__netlink_sock_destruct (sk); +sk_free (&nlk->sk); }/* This lock without WQ_FLAG_EXCLUSIVE is good on UP and it is _very_ bad on
@@ -667,8 +655,18 @@ out_module:static void deferred_put_nlk_sk (struct rcu_head *head) { struct netlink_sock *nlk = container_of(head, struct netlink_sock, rcu); +struct sock *sk = &nlk->sk; + +if (!atomic_dec_and_test (&sk->sk_refcnt)) +return ; + +if (nlk->cb_running && nlk->cb.done) { +INIT_WORK (&nlk->work, netlink_sock_destruct_work); +schedule_work (&nlk->work); +return ; + } -sock_put (&nlk->sk); +sk_free (sk); }static int netlink_release (struct socket *sock)
Patches currently in stable-queue which might be from [email protected] are
queue-4.8/udplite-call-proper-backlog-handlers.patch queue-4.8/netlink-do-not-schedule-work-from-sk_destruct.patch queue-4.8/netlink-call-cb-done-from-a-worker-thread.patch