mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
netlink: Do not schedule work from sk_destruct
[ Upstream commited5d7788a9] 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. Fixes:707693c8a4("netlink: Call cb->done from a worker thread") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Tested-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
d1ed9c1dba
commit
baaf0c65bc
@@ -924,11 +924,13 @@ static void netlink_skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
|
||||
sk_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);
|
||||
}
|
||||
@@ -962,21 +964,7 @@ static void netlink_sock_destruct_work(struct work_struct *work)
|
||||
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
|
||||
@@ -1284,8 +1272,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;
|
||||
|
||||
sock_put(&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;
|
||||
}
|
||||
|
||||
sk_free(sk);
|
||||
}
|
||||
|
||||
static int netlink_release(struct socket *sock)
|
||||
|
||||
Reference in New Issue
Block a user