Skip to content

Commit 7ff28d3

Browse files
herbertxgregkh
authored andcommitted
crypto: deadlock between crypto_alg_sem/rtnl_mutex/genl_mutex
[ Upstream commit 8a0f5cc ] On Tue, Mar 14, 2017 at 10:44:10AM +0100, Dmitry Vyukov wrote: > > Yes, please. > Disregarding some reports is not a good way long term. Please try this patch. ---8<--- Subject: netlink: Annotate nlk cb_mutex by protocol Currently all occurences of nlk->cb_mutex are annotated by lockdep as a single class. This causes a false lcokdep cycle involving genl and crypto_user. This patch fixes it by dividing cb_mutex into individual classes based on the netlink protocol. As genl and crypto_user do not use the same netlink protocol this breaks the false dependency loop. Reported-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ddfc9f7 commit 7ff28d3

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

net/netlink/af_netlink.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,44 @@ EXPORT_SYMBOL_GPL(nl_table);
9696

9797
static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait);
9898

99+
static struct lock_class_key nlk_cb_mutex_keys[MAX_LINKS];
100+
101+
static const char *const nlk_cb_mutex_key_strings[MAX_LINKS + 1] = {
102+
"nlk_cb_mutex-ROUTE",
103+
"nlk_cb_mutex-1",
104+
"nlk_cb_mutex-USERSOCK",
105+
"nlk_cb_mutex-FIREWALL",
106+
"nlk_cb_mutex-SOCK_DIAG",
107+
"nlk_cb_mutex-NFLOG",
108+
"nlk_cb_mutex-XFRM",
109+
"nlk_cb_mutex-SELINUX",
110+
"nlk_cb_mutex-ISCSI",
111+
"nlk_cb_mutex-AUDIT",
112+
"nlk_cb_mutex-FIB_LOOKUP",
113+
"nlk_cb_mutex-CONNECTOR",
114+
"nlk_cb_mutex-NETFILTER",
115+
"nlk_cb_mutex-IP6_FW",
116+
"nlk_cb_mutex-DNRTMSG",
117+
"nlk_cb_mutex-KOBJECT_UEVENT",
118+
"nlk_cb_mutex-GENERIC",
119+
"nlk_cb_mutex-17",
120+
"nlk_cb_mutex-SCSITRANSPORT",
121+
"nlk_cb_mutex-ECRYPTFS",
122+
"nlk_cb_mutex-RDMA",
123+
"nlk_cb_mutex-CRYPTO",
124+
"nlk_cb_mutex-SMC",
125+
"nlk_cb_mutex-23",
126+
"nlk_cb_mutex-24",
127+
"nlk_cb_mutex-25",
128+
"nlk_cb_mutex-26",
129+
"nlk_cb_mutex-27",
130+
"nlk_cb_mutex-28",
131+
"nlk_cb_mutex-29",
132+
"nlk_cb_mutex-30",
133+
"nlk_cb_mutex-31",
134+
"nlk_cb_mutex-MAX_LINKS"
135+
};
136+
99137
static int netlink_dump(struct sock *sk);
100138
static void netlink_skb_destructor(struct sk_buff *skb);
101139

@@ -585,6 +623,9 @@ static int __netlink_create(struct net *net, struct socket *sock,
585623
} else {
586624
nlk->cb_mutex = &nlk->cb_def_mutex;
587625
mutex_init(nlk->cb_mutex);
626+
lockdep_set_class_and_name(nlk->cb_mutex,
627+
nlk_cb_mutex_keys + protocol,
628+
nlk_cb_mutex_key_strings[protocol]);
588629
}
589630
init_waitqueue_head(&nlk->wait);
590631

0 commit comments

Comments
 (0)