Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b131b8a

Browse files
gregkhTreehugger Robot
authored andcommitted
Revert "rtnetlink: change nlk->cb_mutex role"
This reverts commit c8c76f1 which is commit e39951d upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: I9d5e72c3356fbe99b940a2ca1bc1aefe267cbf97 Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 20a7f3c commit b131b8a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

net/netlink/af_netlink.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static struct proto netlink_proto = {
636636
};
637637

638638
static int __netlink_create(struct net *net, struct socket *sock,
639-
struct mutex *dump_cb_mutex, int protocol,
639+
struct mutex *cb_mutex, int protocol,
640640
int kern)
641641
{
642642
struct sock *sk;
@@ -651,11 +651,15 @@ static int __netlink_create(struct net *net, struct socket *sock,
651651
sock_init_data(sock, sk);
652652

653653
nlk = nlk_sk(sk);
654-
mutex_init(&nlk->nl_cb_mutex);
655-
lockdep_set_class_and_name(&nlk->nl_cb_mutex,
654+
if (cb_mutex) {
655+
nlk->cb_mutex = cb_mutex;
656+
} else {
657+
nlk->cb_mutex = &nlk->cb_def_mutex;
658+
mutex_init(nlk->cb_mutex);
659+
lockdep_set_class_and_name(nlk->cb_mutex,
656660
nlk_cb_mutex_keys + protocol,
657661
nlk_cb_mutex_key_strings[protocol]);
658-
nlk->dump_cb_mutex = dump_cb_mutex;
662+
}
659663
init_waitqueue_head(&nlk->wait);
660664

661665
sk->sk_destruct = netlink_sock_destruct;
@@ -2207,7 +2211,7 @@ static int netlink_dump(struct sock *sk, bool lock_taken)
22072211
int alloc_size;
22082212

22092213
if (!lock_taken)
2210-
mutex_lock(&nlk->nl_cb_mutex);
2214+
mutex_lock(nlk->cb_mutex);
22112215
if (!nlk->cb_running) {
22122216
err = -EINVAL;
22132217
goto errout_skb;
@@ -2259,22 +2263,14 @@ static int netlink_dump(struct sock *sk, bool lock_taken)
22592263
netlink_skb_set_owner_r(skb, sk);
22602264

22612265
if (nlk->dump_done_errno > 0) {
2262-
struct mutex *extra_mutex = nlk->dump_cb_mutex;
2263-
22642266
cb->extack = &extack;
2265-
2266-
if (extra_mutex)
2267-
mutex_lock(extra_mutex);
22682267
nlk->dump_done_errno = cb->dump(skb, cb);
2269-
if (extra_mutex)
2270-
mutex_unlock(extra_mutex);
2271-
22722268
cb->extack = NULL;
22732269
}
22742270

22752271
if (nlk->dump_done_errno > 0 ||
22762272
skb_tailroom(skb) < nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
2277-
mutex_unlock(&nlk->nl_cb_mutex);
2273+
mutex_unlock(nlk->cb_mutex);
22782274

22792275
if (sk_filter(sk, skb))
22802276
kfree_skb(skb);
@@ -2308,13 +2304,13 @@ static int netlink_dump(struct sock *sk, bool lock_taken)
23082304
WRITE_ONCE(nlk->cb_running, false);
23092305
module = cb->module;
23102306
skb = cb->skb;
2311-
mutex_unlock(&nlk->nl_cb_mutex);
2307+
mutex_unlock(nlk->cb_mutex);
23122308
module_put(module);
23132309
consume_skb(skb);
23142310
return 0;
23152311

23162312
errout_skb:
2317-
mutex_unlock(&nlk->nl_cb_mutex);
2313+
mutex_unlock(nlk->cb_mutex);
23182314
kfree_skb(skb);
23192315
return err;
23202316
}
@@ -2337,7 +2333,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
23372333
}
23382334

23392335
nlk = nlk_sk(sk);
2340-
mutex_lock(&nlk->nl_cb_mutex);
2336+
mutex_lock(nlk->cb_mutex);
23412337
/* A dump is in progress... */
23422338
if (nlk->cb_running) {
23432339
ret = -EBUSY;
@@ -2388,7 +2384,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
23882384
module_put(control->module);
23892385
error_unlock:
23902386
sock_put(sk);
2391-
mutex_unlock(&nlk->nl_cb_mutex);
2387+
mutex_unlock(nlk->cb_mutex);
23922388
error_free:
23932389
kfree_skb(skb);
23942390
return ret;

net/netlink/af_netlink.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ struct netlink_sock {
3939
bool cb_running;
4040
int dump_done_errno;
4141
struct netlink_callback cb;
42-
struct mutex nl_cb_mutex;
43-
44-
struct mutex *dump_cb_mutex;
42+
struct mutex *cb_mutex;
43+
struct mutex cb_def_mutex;
4544
void (*netlink_rcv)(struct sk_buff *skb);
4645
int (*netlink_bind)(struct net *net, int group);
4746
void (*netlink_unbind)(struct net *net, int group);

0 commit comments

Comments
 (0)