dev->promiscuity refcounting broken in af_packet.c
Subsystems (3)
PATCH RESEND 1/1 dev->promiscuity refcounting broken in af_packet.c
According to today's bkcvs, the below patch still hasn't been applied to 2.4 or 2.5 despite a -pre release or two, Alexey reviewed it and recommended for inclusion.
James, I know you applied it to your bk tree. Will that be enough to get it into 2.4 and 2.5, or should I submit it elsewhere?
Jason
Quoted 31 lines · [email protected] said:
The problem is that packet sockets are calling
dev_set_promiscuitytoo many times. For example, if I take an unconfigured interface and do:halfoat:~ # ip link show eth1
9: eth1: <BROADCAST,MULTICAST> mtu 1500 qdiscpfifo_fastqlen 100link/ether 00:30:48:41:62:12 brd ff:ff:ff:ff:ff:ffhalfoat:~ # ip link set up eth1
halfoat:~ # tcpdump -i eth1 &
[1] 457
tcpdump: WARNING: eth1: no IPv4 address assigned
tcpdump: listening on eth1
halfoat:~ # ip link set down eth1
tcpdump:pcap_loop: recvfrom: Network is down
[1]+ Exit 1 tcpdump -i eth1
halfoat:~ # ip link show eth1
9: eth1: <BROADCAST,MULTICAST,PROMISC> mtu 1500 qdiscpfifo_fastqlen 100link/ether 00:30:48:41:62:12 brd ff:ff:ff:ff:ff:ffeth1 is now in promiscuous mode because
dev->promiscuityis -1 (!= 0).When the interface goes down,
dev_change_flagscallsdev_close, which sendsNETDEV_DOWNdown the netdev notifier chain. Because tcpdump has a packet socket open,packet_notifiercallspacket_dev_mclist->packet_dev_mc->dev_set_promiscuity.When tcpdump gets ENETDOWN, it aborts, closing the packet socket. af_packet.c's
proto_ops->releasecleanup method ispacket_release. Onclose(),packet_releasecallspacket_flush_mclist, which again decrementsdev->promiscuity, so when tcpdump exits, dev promiscuity is left at -1.
Quoted 8 lines
I can't see any reason to be mucking about with the device promiscuity on
NETDEV_DOWNandNETDEV_UPevents in the first place. The attached patch seems to fix all the cases I can think of. It works properly in both of the above cases, and has also been verified to do the right thing withNETDEV_UNREGISTERevents.Jason
Index: linux-2.4/net/packet/af_packet.c
===================================================================
RCS file: /home/cvs/linux-2.4/net/packet/af_packet.c,v retrieving revision 1.11
net/packet/af_packet.c +6 -9
@@ -1378,8 +1378,13 @@ static int packet_notifier(struct notifi po = sk->protinfo.af_packet;switch (msg) { -case NETDEV_DOWN :case NETDEV_UNREGISTER : +#ifdef CONFIG_PACKET_MULTICAST +if (po->mclist) +packet_dev_mclist (dev, po->mclist,-1 ); +// fallthrough +#endif +case NETDEV_DOWN :if (dev->ifindex == po->ifindex) {spin_lock (&po->bind_lock);if (po->running) {
@@ -1396,10 +1401,6 @@ static int packet_notifier(struct notifi }spin_unlock (&po->bind_lock); } -#ifdef CONFIG_PACKET_MULTICAST -if (po->mclist) -packet_dev_mclist (dev, po->mclist,-1 ); -#endif break ;case NETDEV_UP :spin_lock (&po->bind_lock);
@@ -1409,10 +1410,6 @@ static int packet_notifier(struct notifi po->running =1 ; }spin_unlock (&po->bind_lock); -#ifdef CONFIG_PACKET_MULTICAST -if (po->mclist) -packet_dev_mclist (dev, po->mclist,+1 ); -#endif break ; } }
From: Jason Lunz <[email protected]>
Date: Tue, 8 Jul 2003 18:12:39 -0400
James, I know you applied it to your bk tree. Will that be enough to get it into 2.4 and 2.5, or should I submit it elsewhere?
We're just waiting for me to catchup to my backlog from my vacation and push James's tree(s) to Marcelo and Linus.
Please be patient! :-)