netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* iproute2 (addr flush) infinite loop when unprivileged users
@ 2008-01-25 23:00 Alon Bar-Lev
  2008-01-25 23:02 ` Stephen Hemminger
  2008-01-26  0:12 ` Stephen Hemminger
  0 siblings, 2 replies; 10+ messages in thread
From: Alon Bar-Lev @ 2008-01-25 23:00 UTC (permalink / raw)
  To: shemminger, netdev

Hello,

When executing the following command using unprivileged users there is
an infinite loop...
/sbin/ip route flush dev eth1

Execution with -s produces:
*** Round 28153, deleting 2 entries ***

*** Round 28154, deleting 2 entries ***

*** Round 28155, deleting 2 entries ***

*** Round 28156, deleting 2 entries ***

*** Round 28157, deleting 2 entries ***

*** Round 28158, deleting 2 entries ***

*** Round 28159, deleting 2 entries ***

I do not fully understand the sequence, but it may be kernel fault, as
it should have returned EPERM for this request stopping the netlink
request.

Anyway... A simple solution is to store the filter.flushed and fail if
it keeps its value during loop iteration at
ip/ipaddress.c::ipaddr_list_or_flush(), but this is only a
workaround...

Please CC as I am not in netdev list.
Thanks!
Alon.

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-25 23:00 iproute2 (addr flush) infinite loop when unprivileged users Alon Bar-Lev
@ 2008-01-25 23:02 ` Stephen Hemminger
  2008-01-25 23:06   ` Alon Bar-Lev
  2008-01-26  0:12 ` Stephen Hemminger
  1 sibling, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2008-01-25 23:02 UTC (permalink / raw)
  To: Alon Bar-Lev; +Cc: netdev

On Sat, 26 Jan 2008 01:00:34 +0200
"Alon Bar-Lev" <alon.barlev@gmail.com> wrote:

> Hello,
> 
> When executing the following command using unprivileged users there is
> an infinite loop...
> /sbin/ip route flush dev eth1
> 
> Execution with -s produces:
> *** Round 28153, deleting 2 entries ***
> 
> *** Round 28154, deleting 2 entries ***
> 
> *** Round 28155, deleting 2 entries ***
> 
> *** Round 28156, deleting 2 entries ***
> 
> *** Round 28157, deleting 2 entries ***
> 
> *** Round 28158, deleting 2 entries ***
> 
> *** Round 28159, deleting 2 entries ***
> 
> I do not fully understand the sequence, but it may be kernel fault, as
> it should have returned EPERM for this request stopping the netlink
> request.
> 
> Anyway... A simple solution is to store the filter.flushed and fail if
> it keeps its value during loop iteration at
> ip/ipaddress.c::ipaddr_list_or_flush(), but this is only a
> workaround...
> 
> Please CC as I am not in netdev list.
> Thanks!
> Alon.

Non privileged users can't delete routes, but command keeps trying.
The correct way to handle it is to teach flush loop to look at error code.

-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-25 23:02 ` Stephen Hemminger
@ 2008-01-25 23:06   ` Alon Bar-Lev
  0 siblings, 0 replies; 10+ messages in thread
From: Alon Bar-Lev @ 2008-01-25 23:06 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Thanks for quick response!
I tried to figure out how to do this, it looks like the libnelink does
this anyway...
I must missed something.
Can you please help?

On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> On Sat, 26 Jan 2008 01:00:34 +0200
> "Alon Bar-Lev" <alon.barlev@gmail.com> wrote:
>
> > Hello,
> >
> > When executing the following command using unprivileged users there is
> > an infinite loop...
> > /sbin/ip route flush dev eth1
> >
> > Execution with -s produces:
> > *** Round 28153, deleting 2 entries ***
> >
> > *** Round 28154, deleting 2 entries ***
> >
> > *** Round 28155, deleting 2 entries ***
> >
> > *** Round 28156, deleting 2 entries ***
> >
> > *** Round 28157, deleting 2 entries ***
> >
> > *** Round 28158, deleting 2 entries ***
> >
> > *** Round 28159, deleting 2 entries ***
> >
> > I do not fully understand the sequence, but it may be kernel fault, as
> > it should have returned EPERM for this request stopping the netlink
> > request.
> >
> > Anyway... A simple solution is to store the filter.flushed and fail if
> > it keeps its value during loop iteration at
> > ip/ipaddress.c::ipaddr_list_or_flush(), but this is only a
> > workaround...
> >
> > Please CC as I am not in netdev list.
> > Thanks!
> > Alon.
>
> Non privileged users can't delete routes, but command keeps trying.
> The correct way to handle it is to teach flush loop to look at error code.
>
> --
> Stephen Hemminger <stephen.hemminger@vyatta.com>
>

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-25 23:00 iproute2 (addr flush) infinite loop when unprivileged users Alon Bar-Lev
  2008-01-25 23:02 ` Stephen Hemminger
@ 2008-01-26  0:12 ` Stephen Hemminger
  2008-01-26  0:22   ` Alon Bar-Lev
  1 sibling, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2008-01-26  0:12 UTC (permalink / raw)
  To: Alon Bar-Lev; +Cc: netdev

On Sat, 26 Jan 2008 01:00:34 +0200
"Alon Bar-Lev" <alon.barlev@gmail.com> wrote:

> Hello,
> 
> When executing the following command using unprivileged users there is
> an infinite loop...
> /sbin/ip route flush dev eth1
> 
> Execution with -s produces:
> *** Round 28153, deleting 2 entries ***
> 
> *** Round 28154, deleting 2 entries ***
> 
> *** Round 28155, deleting 2 entries ***
> 
> *** Round 28156, deleting 2 entries ***
> 
> *** Round 28157, deleting 2 entries ***
> 
> *** Round 28158, deleting 2 entries ***
> 
> *** Round 28159, deleting 2 entries ***
> 
> I do not fully understand the sequence, but it may be kernel fault, as
> it should have returned EPERM for this request stopping the netlink
> request.
> 
> Anyway... A simple solution is to store the filter.flushed and fail if
> it keeps its value during loop iteration at
> ip/ipaddress.c::ipaddr_list_or_flush(), but this is only a
> workaround...
> 
> Please CC as I am not in netdev list.
> Thanks!
> Alon.

The issue is that iproute is just blindly sending the deletes and
not asking for acknowledgment status. Here is a trivial patch to iproute
to fix that, but the problem is that it means it will slow down bulk removal.

Maybe it should just check the first, or last delete to see if there are
errors?

diff --git a/ip/iproute.c b/ip/iproute.c
index 7a885b0..b2ae879 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -112,11 +112,27 @@ static struct
 
 static int flush_update(void)
 {
+	unsigned long i;
+	struct nlmsghdr *fn;
+
+#ifdef nochecking
 	if (rtnl_send(&rth, filter.flushb, filter.flushp) < 0) {
 		perror("Failed to send flush request\n");
 		return -1;
 	}
+#else
+	for (i = 0; i < filter.flushp; ) {
+		fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(i));
+		fn->nlmsg_flags |= NLM_F_ACK;
+		
+		if (rtnl_talk(&rth, fn, 0, 0, NULL, NULL, NULL) < 0)
+			return -1;
+
+		i = (((char*)fn) + fn->nlmsg_len) - filter.flushb;
+	}
+#endif
 	filter.flushp = 0;
+
 	return 0;
 }
 




-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-26  0:12 ` Stephen Hemminger
@ 2008-01-26  0:22   ` Alon Bar-Lev
  2008-01-26  8:58     ` Alon Bar-Lev
  0 siblings, 1 reply; 10+ messages in thread
From: Alon Bar-Lev @ 2008-01-26  0:22 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> The issue is that iproute is just blindly sending the deletes and
> not asking for acknowledgment status. Here is a trivial patch to iproute
> to fix that, but the problem is that it means it will slow down bulk removal.
>
> Maybe it should just check the first, or last delete to see if there are
> errors?
>
> diff --git a/ip/iproute.c b/ip/iproute.c
> index 7a885b0..b2ae879 100644
> --- a/ip/iproute.c
> +++ b/ip/iproute.c

This should also be applied into ip/ipaddress.c, ip/ipneigh.c
Or even make one common function?

I don't quite understand how "fast" is good if not complete... But
anyway... I will be happy to see this fix in next version... Maybe add
--fast argument? :)

Alon.

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-26  0:22   ` Alon Bar-Lev
@ 2008-01-26  8:58     ` Alon Bar-Lev
  2008-01-26 19:11       ` Stephen Hemminger
                         ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Alon Bar-Lev @ 2008-01-26  8:58 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On 1/26/08, Alon Bar-Lev <alon.barlev@gmail.com> wrote:
> On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> > The issue is that iproute is just blindly sending the deletes and
> > not asking for acknowledgment status. Here is a trivial patch to iproute
> > to fix that, but the problem is that it means it will slow down bulk removal.
> >
> > Maybe it should just check the first, or last delete to see if there are
> > errors?
> >
> > diff --git a/ip/iproute.c b/ip/iproute.c
> > index 7a885b0..b2ae879 100644
> > --- a/ip/iproute.c
> > +++ b/ip/iproute.c
>
> This should also be applied into ip/ipaddress.c, ip/ipneigh.c
> Or even make one common function?
>
> I don't quite understand how "fast" is good if not complete... But
> anyway... I will be happy to see this fix in next version... Maybe add
> --fast argument? :)
>
> Alon.
>

Pulled your latest git head. See some updates but not this one...
Just thought to report the following [new] build error:


gcc -Wl,-export-dynamic  ip.o ipaddress.o iproute.o iprule.o rtm_map.o
iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o
ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o ipxfrm.o xfrm_state.o
xfrm_policy.o xfrm_monitor.o iplink_vlan.o link_veth.o
../lib/libnetlink.a ../lib/libutil.a  -lresolv -L../lib -lnetlink
-lutil -ldl -o ip
iptunnel.o: In function `parse_args':
iptunnel.c:(.text+0x2f6): undefined reference to `__constant_htons'
iptunnel.c:(.text+0x434): undefined reference to `__constant_htons'
iptunnel.c:(.text+0x4c1): undefined reference to `__constant_htons'
iptunnel.c:(.text+0x4da): undefined reference to `__constant_htons'
iptunnel.c:(.text+0x51c): undefined reference to `__constant_htons'
iptunnel.o:iptunnel.c:(.text+0x535): more undefined references to
`__constant_htons' follow
collect2: ld returned 1 exit status
make[1]: *** [ip] Error 1

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-26  8:58     ` Alon Bar-Lev
@ 2008-01-26 19:11       ` Stephen Hemminger
  2008-01-26 19:14       ` Stephen Hemminger
  2008-01-26 19:19       ` Stephen Hemminger
  2 siblings, 0 replies; 10+ messages in thread
From: Stephen Hemminger @ 2008-01-26 19:11 UTC (permalink / raw)
  To: Alon Bar-Lev; +Cc: netdev

On Sat, 26 Jan 2008 10:58:58 +0200
"Alon Bar-Lev" <alon.barlev@gmail.com> wrote:

> On 1/26/08, Alon Bar-Lev <alon.barlev@gmail.com> wrote:
> > On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> > > The issue is that iproute is just blindly sending the deletes and
> > > not asking for acknowledgment status. Here is a trivial patch to iproute
> > > to fix that, but the problem is that it means it will slow down bulk removal.
> > >
> > > Maybe it should just check the first, or last delete to see if there are
> > > errors?
> > >
> > > diff --git a/ip/iproute.c b/ip/iproute.c
> > > index 7a885b0..b2ae879 100644
> > > --- a/ip/iproute.c
> > > +++ b/ip/iproute.c
> >
> > This should also be applied into ip/ipaddress.c, ip/ipneigh.c
> > Or even make one common function?
> >
> > I don't quite understand how "fast" is good if not complete... But
> > anyway... I will be happy to see this fix in next version... Maybe add
> > --fast argument? :)
> >
> > Alon.
> >


I found the correct solution. The kernel will send back an error after a bad
netlink message, even without ACK. so the code now checks.  Should be checked in
and pushed for next version.


-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-26  8:58     ` Alon Bar-Lev
  2008-01-26 19:11       ` Stephen Hemminger
@ 2008-01-26 19:14       ` Stephen Hemminger
  2008-01-26 19:19       ` Stephen Hemminger
  2 siblings, 0 replies; 10+ messages in thread
From: Stephen Hemminger @ 2008-01-26 19:14 UTC (permalink / raw)
  To: Alon Bar-Lev; +Cc: netdev

On Sat, 26 Jan 2008 10:58:58 +0200
"Alon Bar-Lev" <alon.barlev@gmail.com> wrote:

> On 1/26/08, Alon Bar-Lev <alon.barlev@gmail.com> wrote:
> > On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> > > The issue is that iproute is just blindly sending the deletes and
> > > not asking for acknowledgment status. Here is a trivial patch to iproute
> > > to fix that, but the problem is that it means it will slow down bulk removal.
> > >
> > > Maybe it should just check the first, or last delete to see if there are
> > > errors?
> > >
> > > diff --git a/ip/iproute.c b/ip/iproute.c
> > > index 7a885b0..b2ae879 100644
> > > --- a/ip/iproute.c
> > > +++ b/ip/iproute.c
> >
> > This should also be applied into ip/ipaddress.c, ip/ipneigh.c
> > Or even make one common function?
> >
> > I don't quite understand how "fast" is good if not complete... But
> > anyway... I will be happy to see this fix in next version... Maybe add
> > --fast argument? :)
> >
> > Alon.
> >
> 
> Pulled your latest git head. See some updates but not this one...
> Just thought to report the following [new] build error:
> 
> 
> gcc -Wl,-export-dynamic  ip.o ipaddress.o iproute.o iprule.o rtm_map.o
> iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o
> ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o ipxfrm.o xfrm_state.o
> xfrm_policy.o xfrm_monitor.o iplink_vlan.o link_veth.o
> ../lib/libnetlink.a ../lib/libutil.a  -lresolv -L../lib -lnetlink
> -lutil -ldl -o ip
> iptunnel.o: In function `parse_args':
> iptunnel.c:(.text+0x2f6): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x434): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x4c1): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x4da): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x51c): undefined reference to `__constant_htons'
> iptunnel.o:iptunnel.c:(.text+0x535): more undefined references to
> `__constant_htons' follow
> collect2: ld returned 1 exit status
> make[1]: *** [ip] Error 1

What system are you building on.
This is defined in linux/byteorder.h

-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-26  8:58     ` Alon Bar-Lev
  2008-01-26 19:11       ` Stephen Hemminger
  2008-01-26 19:14       ` Stephen Hemminger
@ 2008-01-26 19:19       ` Stephen Hemminger
  2008-01-26 21:48         ` Alon Bar-Lev
  2 siblings, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2008-01-26 19:19 UTC (permalink / raw)
  To: Alon Bar-Lev; +Cc: netdev

On Sat, 26 Jan 2008 10:58:58 +0200
"Alon Bar-Lev" <alon.barlev@gmail.com> wrote:

> On 1/26/08, Alon Bar-Lev <alon.barlev@gmail.com> wrote:
> > On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> > > The issue is that iproute is just blindly sending the deletes and
> > > not asking for acknowledgment status. Here is a trivial patch to iproute
> > > to fix that, but the problem is that it means it will slow down bulk removal.
> > >
> > > Maybe it should just check the first, or last delete to see if there are
> > > errors?
> > >
> > > diff --git a/ip/iproute.c b/ip/iproute.c
> > > index 7a885b0..b2ae879 100644
> > > --- a/ip/iproute.c
> > > +++ b/ip/iproute.c
> >
> > This should also be applied into ip/ipaddress.c, ip/ipneigh.c
> > Or even make one common function?
> >
> > I don't quite understand how "fast" is good if not complete... But
> > anyway... I will be happy to see this fix in next version... Maybe add
> > --fast argument? :)
> >
> > Alon.
> >
> 
> Pulled your latest git head. See some updates but not this one...
> Just thought to report the following [new] build error:
> 
> 
> gcc -Wl,-export-dynamic  ip.o ipaddress.o iproute.o iprule.o rtm_map.o
> iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o
> ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o ipxfrm.o xfrm_state.o
> xfrm_policy.o xfrm_monitor.o iplink_vlan.o link_veth.o
> ../lib/libnetlink.a ../lib/libutil.a  -lresolv -L../lib -lnetlink
> -lutil -ldl -o ip
> iptunnel.o: In function `parse_args':
> iptunnel.c:(.text+0x2f6): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x434): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x4c1): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x4da): undefined reference to `__constant_htons'
> iptunnel.c:(.text+0x51c): undefined reference to `__constant_htons'
> iptunnel.o:iptunnel.c:(.text+0x535): more undefined references to
> `__constant_htons' follow
> collect2: ld returned 1 exit status
> make[1]: *** [ip] Error 1

This is defined via:
  /usr/include/linux/ip.h
  #include <asm/byteorder.h>

-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: iproute2 (addr flush) infinite loop when unprivileged users
  2008-01-26 19:19       ` Stephen Hemminger
@ 2008-01-26 21:48         ` Alon Bar-Lev
  0 siblings, 0 replies; 10+ messages in thread
From: Alon Bar-Lev @ 2008-01-26 21:48 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On 1/26/08, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> > iptunnel.c:(.text+0x51c): undefined reference to `__constant_htons'
> > iptunnel.o:iptunnel.c:(.text+0x535): more undefined references to
> > `__constant_htons' follow
> > collect2: ld returned 1 exit status
> > make[1]: *** [ip] Error 1
>
> This is defined via:
>   /usr/i!vinclude/linux/ip.h
>   #include <asm/byteorder.h>

Trace down the problem to Gentoo patch.
Sorry.

All working now!
Thanks!

Alon.

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

end of thread, other threads:[~2008-01-26 21:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-25 23:00 iproute2 (addr flush) infinite loop when unprivileged users Alon Bar-Lev
2008-01-25 23:02 ` Stephen Hemminger
2008-01-25 23:06   ` Alon Bar-Lev
2008-01-26  0:12 ` Stephen Hemminger
2008-01-26  0:22   ` Alon Bar-Lev
2008-01-26  8:58     ` Alon Bar-Lev
2008-01-26 19:11       ` Stephen Hemminger
2008-01-26 19:14       ` Stephen Hemminger
2008-01-26 19:19       ` Stephen Hemminger
2008-01-26 21:48         ` Alon Bar-Lev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).