netns: use a spin_lock to protect nsid management
Subsystems (3)
Hello Nicolas Dichtel,
The patch 95f38411df05: "netns: use a spin_lock to protect nsid management" from May 7, 2015, leads to the following static checker warning:
net/core/net_namespace.c:580 rtnl_net_newid() warn: inconsistent returns 'spin_lock:&nsid_lock'.
net/core/net_namespace.c
565
566 spin_lock_irqsave(&nsid_lock, flags);
567 if (__peernet2id(net, peer) >= 0) {
568 err = -EEXIST;
569 goto out;
I don't know if __peernet2id() unlocks on error but it can't possibly restore flags so this isn't right.
570 }
571
572 err = alloc_netid(net, peer, nsid);
573 spin_unlock_irqrestore(&nsid_lock, flags);
574 if (err >= 0) {
575 rtnl_net_notifyid(net, RTM_NEWNSID, err);
576 err = 0;
577 }
578 out:
579 put_net(peer);
580 return err;
581 }regards,
dan carpenter
(Please always Cc netdev for networking bugs)
Quoted 11 lines · Dan Carpenter
Hello Nicolas Dichtel,
The patch
95f38411df05: "netns: use aspin_lockto protect nsid management" from May 7, 2015, leads to the following static checker warning:
net/core/net_namespace.c:580rtnl_net_newid()
warn: inconsistent returns 'spin_lock:&nsid_lock'.
net/core/net_namespace.c
565
Quoted 8 lines
566 spin_lock_irqsave(&nsid_lock, flags); 567 if (__peernet2id(net, peer) >= 0) { 568 err = -EEXIST; 569 goto out;I don't know if
__peernet2id()unlocks on error but it can't possibly restore flags so this isn't right.
Yes it is a bug.
Also why do we have to disable IRQ when holding the spinlock? IOW, which case takes the spin lock in IRQ context?
Thanks.
Quoted 10 lines · Dan Carpenter
Hello Nicolas Dichtel,
The patch
95f38411df05: "netns: use aspin_lockto protect nsid management" from May 7, 2015, leads to the following static checker warning:net/core/net_namespace.c:580 rtnl_net_newid() warn: inconsistent returns 'spin_lock:&nsid_lock'.
net/core/net_namespace.c
Quoted 8 lines
565 566 spin_lock_irqsave(&nsid_lock, flags); 567 if (__peernet2id(net, peer) >= 0) { 568 err = -EEXIST; 569 goto out;I don't know if
__peernet2id()unlocks on error but it can't possibly restore flags so this isn't right.
It's a bug. I will send a patch.
Thank you for the report.
Nicolas
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 netns: fix unbalanced spin_lock on error
Unlock was missing on error path.
--- net/core/net_namespace.c | 1 + 1 file changed, 1 insertion(+)
net/core/net_namespace.c +1 -0
@@ -565,6 +565,7 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh)spin_lock_irqsave (&nsid_lock, flags);if (__peernet2id (net, peer) >=0 ) { +spin_unlock_irqrestore (&nsid_lock, flags); err = -EEXIST ; goto out; }
Signature · 1 line
2.2.2
Le 12/05/2015 21:16, Cong Wang a écrit :
[snip]
Quoted 2 lines
Also why do we have to disable IRQ when holding the spinlock? IOW, which case takes the spin lock in IRQ context?
peernet2id() is called by do_one_broadcast() (net/netlink/af_netlink.c). So every callers of netlink_broadcast[_filtered]()/nlmsg_unicast() /nlmsg_multicast() may needs this lock.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH net-next] netns: fix unbalanced spin_lock on error
In reply to Nicolas DichtelFrom: Nicolas Dichtel <[email protected]>
Date: Wed, 13 May 2015 13:43:09 +0200
Quoted 5 lines
Unlock was missing on error path.
Fixes 95f38411df05 ("netns: use a spin_lock to protect nsid management")Reported-by Dan Carpenter <[email protected]>Signed-off-by Nicolas Dichtel <[email protected]>
Applied.