mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
netlink: Do not call the unbind callback with the table locked
When netlink_bind() fails to insert the socket, it calls
netlink_undo_bind() with the table locked. genl_unbind() then takes
cb_lock, while genl_unregister_family() and genl_register_family() take
cb_lock for writing and then wait in netlink_table_grab() for the table
users to go away:
netlink_bind() genl_unregister_family()
netlink_lock_table() down_write(&cb_lock)
netlink_insert() fails
netlink_undo_bind() netlink_table_grab()
genl_unbind() waits for nl_table_users == 0
down_read(&cb_lock)
An unprivileged user can get here by binding to a port ID that is in
use, with nl_groups set. Lockdep does not see it, as nl_table_users is a
plain counter.
Unlock the table first, as the comment in netlink_release() asks for.
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]
Fixes: 3de21a8990 ("genetlink: Add per family bind/unbind callbacks")
Signed-off-by: Anil Kaushik <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
This commit is contained in:
committed by
Jakub Kicinski
parent
29066b0fc0
commit
a36b9e205c
@@ -1047,8 +1047,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr_unsized *addr,
|
||||
netlink_insert(sk, nladdr->nl_pid) :
|
||||
netlink_autobind(sock);
|
||||
if (err) {
|
||||
netlink_unlock_table();
|
||||
netlink_undo_bind(BITS_PER_TYPE(u32), groups, sk);
|
||||
goto unlock;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user