From: Joe Perches <joe@perches.com>
To: Patrick McHardy <kaber@trash.net>
Cc: "Luis R. Rodriguez" <mcgrof@gmail.com>,
netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
Jeff Garzik <jeff@garzik.org>, David Miller <davem@davemloft.net>
Subject: Re: [PATCH] Fix infinite loop on dev_mc_unsync()
Date: Fri, 09 Nov 2007 16:08:40 -0800 [thread overview]
Message-ID: <1194653320.19522.28.camel@localhost> (raw)
In-Reply-To: <4734E962.3010603@trash.net>
On Sat, 2007-11-10 at 00:12 +0100, Patrick McHardy wrote:
> This may cause a use-after-free since __dev_addr_delete frees the address
> when all references are gone.
How about a comment then? Perhaps:
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index ae35405..63576aa 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -165,16 +165,23 @@ void dev_mc_unsync(struct net_device *to, struct net_device *from)
netif_tx_lock_bh(from);
netif_tx_lock_bh(to);
+ /*
+ This while loop can't be written as
+ for (da = from->mc_list; da; da = da->next)
+ da = from->mc_list and __dev_addr_delete can kfree(from->mc_list)
+ which could cause a use-after-free of da->next
+ */
+
da = from->mc_list;
while (da != NULL) {
next = da->next;
- if (!da->da_synced)
- continue;
- __dev_addr_delete(&to->mc_list, &to->mc_count,
- da->da_addr, da->da_addrlen, 0);
- da->da_synced = 0;
- __dev_addr_delete(&from->mc_list, &from->mc_count,
- da->da_addr, da->da_addrlen, 0);
+ if (da->da_synced) {
+ __dev_addr_delete(&to->mc_list, &to->mc_count,
+ da->da_addr, da->da_addrlen, 0);
+ da->da_synced = 0;
+ __dev_addr_delete(&from->mc_list, &from->mc_count,
+ da->da_addr, da->da_addrlen, 0);
+ }
da = next;
}
__dev_set_rx_mode(to);
WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
To: Patrick McHardy <kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org>
Cc: "Luis R. Rodriguez"
<mcgrof-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Jeff Garzik <jeff-o2qLIJkoznsdnm+yROfE0A@public.gmane.org>,
David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
Subject: Re: [PATCH] Fix infinite loop on dev_mc_unsync()
Date: Fri, 09 Nov 2007 16:08:40 -0800 [thread overview]
Message-ID: <1194653320.19522.28.camel@localhost> (raw)
In-Reply-To: <4734E962.3010603-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org>
On Sat, 2007-11-10 at 00:12 +0100, Patrick McHardy wrote:
> This may cause a use-after-free since __dev_addr_delete frees the address
> when all references are gone.
How about a comment then? Perhaps:
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index ae35405..63576aa 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -165,16 +165,23 @@ void dev_mc_unsync(struct net_device *to, struct net_device *from)
netif_tx_lock_bh(from);
netif_tx_lock_bh(to);
+ /*
+ This while loop can't be written as
+ for (da = from->mc_list; da; da = da->next)
+ da = from->mc_list and __dev_addr_delete can kfree(from->mc_list)
+ which could cause a use-after-free of da->next
+ */
+
da = from->mc_list;
while (da != NULL) {
next = da->next;
- if (!da->da_synced)
- continue;
- __dev_addr_delete(&to->mc_list, &to->mc_count,
- da->da_addr, da->da_addrlen, 0);
- da->da_synced = 0;
- __dev_addr_delete(&from->mc_list, &from->mc_count,
- da->da_addr, da->da_addrlen, 0);
+ if (da->da_synced) {
+ __dev_addr_delete(&to->mc_list, &to->mc_count,
+ da->da_addr, da->da_addrlen, 0);
+ da->da_synced = 0;
+ __dev_addr_delete(&from->mc_list, &from->mc_count,
+ da->da_addr, da->da_addrlen, 0);
+ }
da = next;
}
__dev_set_rx_mode(to);
next prev parent reply other threads:[~2007-11-10 0:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-09 15:11 [PATCH] Fix infinite loop on dev_mc_unsync() Luis R. Rodriguez
2007-11-09 15:11 ` Luis R. Rodriguez
2007-11-09 18:51 ` Luis R. Rodriguez
2007-11-09 18:51 ` Luis R. Rodriguez
2007-11-09 19:07 ` Joe Perches
2007-11-09 19:07 ` Joe Perches
2007-11-09 19:21 ` Luis R. Rodriguez
2007-11-09 19:21 ` Luis R. Rodriguez
2007-11-09 23:12 ` Patrick McHardy
2007-11-10 0:08 ` Joe Perches [this message]
2007-11-10 0:08 ` Joe Perches
2007-11-10 0:13 ` Patrick McHardy
2007-11-10 0:13 ` Patrick McHardy
2007-11-11 5:34 ` David Miller
2007-11-11 5:34 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1194653320.19522.28.camel@localhost \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=jeff@garzik.org \
--cc=kaber@trash.net \
--cc=linux-wireless@vger.kernel.org \
--cc=mcgrof@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.