All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] ip maddr: fix filtering by device
@ 2017-10-19  8:21 Michal Kubecek
  2017-10-19  9:06 ` Phil Sutter
  2017-10-23 12:42 ` Stephen Hemminger
  0 siblings, 2 replies; 4+ messages in thread
From: Michal Kubecek @ 2017-10-19  8:21 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Petr Vorel, Phil Sutter

Commit 530903dd9003 ("ip: fix igmp parsing when iface is long") uses
variable len to keep trailing colon from interface name comparison.  This
variable is local to loop body but we set it in one pass and use it in
following one(s) so that we are actually using (pseudo)random length for
comparison. This became apparent since commit b48a1161f5f9 ("ipmaddr: Avoid
accessing uninitialized data") always initializes len to zero so that the
name comparison is always true. As a result, "ip maddr show dev eth0" shows
IPv4 multicast addresses for all interfaces.

Instead of keeping the length, let's simply replace the trailing colon with
a null byte. The bonus is that we get correct interface name in ma.name.

Fixes: 530903dd9003 ("ip: fix igmp parsing when iface is long")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 ip/ipmaddr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 5683f6fa830c..46b86a3a7723 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -136,17 +136,18 @@ static void read_igmp(struct ma_info **result_p)
 
 	while (fgets(buf, sizeof(buf), fp)) {
 		struct ma_info *ma;
-		size_t len = 0;
 
 		if (buf[0] != '\t') {
+			size_t len;
+
 			sscanf(buf, "%d%s", &m.index, m.name);
 			len = strlen(m.name);
 			if (m.name[len - 1] == ':')
-				len--;
+				m.name[len - 1] = '\0';
 			continue;
 		}
 
-		if (filter.dev && strncmp(filter.dev, m.name, len))
+		if (filter.dev && strcmp(filter.dev, m.name))
 			continue;
 
 		sscanf(buf, "%08x%d", (__u32 *)&m.addr.data, &m.users);
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ip maddr: fix filtering by device
  2017-10-19  8:21 [PATCH iproute2] ip maddr: fix filtering by device Michal Kubecek
@ 2017-10-19  9:06 ` Phil Sutter
  2017-10-19  9:14   ` Petr Vorel
  2017-10-23 12:42 ` Stephen Hemminger
  1 sibling, 1 reply; 4+ messages in thread
From: Phil Sutter @ 2017-10-19  9:06 UTC (permalink / raw)
  To: Michal Kubecek; +Cc: Stephen Hemminger, netdev, Petr Vorel

On Thu, Oct 19, 2017 at 10:21:08AM +0200, Michal Kubecek wrote:
> Commit 530903dd9003 ("ip: fix igmp parsing when iface is long") uses
> variable len to keep trailing colon from interface name comparison.  This
> variable is local to loop body but we set it in one pass and use it in
> following one(s) so that we are actually using (pseudo)random length for
> comparison. This became apparent since commit b48a1161f5f9 ("ipmaddr: Avoid
> accessing uninitialized data") always initializes len to zero so that the
> name comparison is always true. As a result, "ip maddr show dev eth0" shows
> IPv4 multicast addresses for all interfaces.
> 
> Instead of keeping the length, let's simply replace the trailing colon with
> a null byte. The bonus is that we get correct interface name in ma.name.
> 
> Fixes: 530903dd9003 ("ip: fix igmp parsing when iface is long")
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

Acked-by: Phil Sutter <phil@nwl.cc>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ip maddr: fix filtering by device
  2017-10-19  9:06 ` Phil Sutter
@ 2017-10-19  9:14   ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2017-10-19  9:14 UTC (permalink / raw)
  To: Phil Sutter, Michal Kubecek, Stephen Hemminger, netdev

> On Thu, Oct 19, 2017 at 10:21:08AM +0200, Michal Kubecek wrote:
> > Commit 530903dd9003 ("ip: fix igmp parsing when iface is long") uses
> > variable len to keep trailing colon from interface name comparison.  This
> > variable is local to loop body but we set it in one pass and use it in
> > following one(s) so that we are actually using (pseudo)random length for
> > comparison. This became apparent since commit b48a1161f5f9 ("ipmaddr: Avoid
> > accessing uninitialized data") always initializes len to zero so that the
> > name comparison is always true. As a result, "ip maddr show dev eth0" shows
> > IPv4 multicast addresses for all interfaces.

> > Instead of keeping the length, let's simply replace the trailing colon with
> > a null byte. The bonus is that we get correct interface name in ma.name.

> > Fixes: 530903dd9003 ("ip: fix igmp parsing when iface is long")
> > Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

> Acked-by: Phil Sutter <phil@nwl.cc>

Acked-by: Petr Vorel <pvorel@suse.cz>

Thanks for fixing, Michal.
Petr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ip maddr: fix filtering by device
  2017-10-19  8:21 [PATCH iproute2] ip maddr: fix filtering by device Michal Kubecek
  2017-10-19  9:06 ` Phil Sutter
@ 2017-10-23 12:42 ` Stephen Hemminger
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-10-23 12:42 UTC (permalink / raw)
  To: Michal Kubecek; +Cc: netdev, Petr Vorel, Phil Sutter

On Thu, 19 Oct 2017 10:21:08 +0200 (CEST)
Michal Kubecek <mkubecek@suse.cz> wrote:

> Commit 530903dd9003 ("ip: fix igmp parsing when iface is long") uses
> variable len to keep trailing colon from interface name comparison.  This
> variable is local to loop body but we set it in one pass and use it in
> following one(s) so that we are actually using (pseudo)random length for
> comparison. This became apparent since commit b48a1161f5f9 ("ipmaddr: Avoid
> accessing uninitialized data") always initializes len to zero so that the
> name comparison is always true. As a result, "ip maddr show dev eth0" shows
> IPv4 multicast addresses for all interfaces.
> 
> Instead of keeping the length, let's simply replace the trailing colon with
> a null byte. The bonus is that we get correct interface name in ma.name.
> 
> Fixes: 530903dd9003 ("ip: fix igmp parsing when iface is long")
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

Applied

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-23 12:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19  8:21 [PATCH iproute2] ip maddr: fix filtering by device Michal Kubecek
2017-10-19  9:06 ` Phil Sutter
2017-10-19  9:14   ` Petr Vorel
2017-10-23 12:42 ` Stephen Hemminger

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.