* [PATCH] net: Check the argument for listen(2)
@ 2013-06-28 16:14 Changli Gao
2013-06-28 16:29 ` Eric Dumazet
2013-06-28 16:30 ` Stephen Hemminger
0 siblings, 2 replies; 6+ messages in thread
From: Changli Gao @ 2013-06-28 16:14 UTC (permalink / raw)
To: David S. Miller; +Cc: Changli Gao, netdev
As we use u16 to save the value of the argument for listen(2),
we'd better check if the value is larger than SINT_MAX other
than cut it down silently on error.
---
net/ipv4/af_inet.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index b4d0be2..35aaf00 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -198,6 +198,9 @@ int inet_listen(struct socket *sock, int backlog)
unsigned char old_state;
int err;
+ if (backlog >= (1 << 16))
+ return EINVAL;
+
lock_sock(sk);
err = -EINVAL;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] net: Check the argument for listen(2)
2013-06-28 16:14 [PATCH] net: Check the argument for listen(2) Changli Gao
@ 2013-06-28 16:29 ` Eric Dumazet
2013-06-28 16:32 ` Hannes Frederic Sowa
2013-06-28 16:30 ` Stephen Hemminger
1 sibling, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2013-06-28 16:29 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, netdev
On Sat, 2013-06-29 at 00:14 +0800, Changli Gao wrote:
> As we use u16 to save the value of the argument for listen(2),
> we'd better check if the value is larger than SINT_MAX other
> than cut it down silently on error.
> ---
> net/ipv4/af_inet.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index b4d0be2..35aaf00 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -198,6 +198,9 @@ int inet_listen(struct socket *sock, int backlog)
> unsigned char old_state;
> int err;
>
> + if (backlog >= (1 << 16))
> + return EINVAL;
> +
> lock_sock(sk);
>
> err = -EINVAL;
This seems pretty buggy to me.
1) EINVAL is not -EINVAL
2) This might break existing applications.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: Check the argument for listen(2)
2013-06-28 16:14 [PATCH] net: Check the argument for listen(2) Changli Gao
2013-06-28 16:29 ` Eric Dumazet
@ 2013-06-28 16:30 ` Stephen Hemminger
1 sibling, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2013-06-28 16:30 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, netdev
On Sat, 29 Jun 2013 00:14:36 +0800
Changli Gao <xiaosuo@gmail.com> wrote:
> As we use u16 to save the value of the argument for listen(2),
> we'd better check if the value is larger than SINT_MAX other
> than cut it down silently on error.
> ---
> net/ipv4/af_inet.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index b4d0be2..35aaf00 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -198,6 +198,9 @@ int inet_listen(struct socket *sock, int backlog)
> unsigned char old_state;
> int err;
>
> + if (backlog >= (1 << 16))
> + return EINVAL;
> +
> lock_sock(sk);
>
> err = -EINVAL;
Is this just a theoretical problem or is there an example?
Since this is a user API, you should check related standards, it maybe
that the kernel should just silently truncate. Returning errors
to legacy applications makes people really angry.
If you decide that returning an error is the correct behaviour
then the return value should be negative in order to follow kernel practice
and other parts of same code.
Rather than open coding >= (1<<16) might be better to > USHRT_MAX.
Lastly, a test like this deserves a comment like:
/* since sk_max_ack_backlog is ushort */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: Check the argument for listen(2)
2013-06-28 16:29 ` Eric Dumazet
@ 2013-06-28 16:32 ` Hannes Frederic Sowa
2013-06-28 16:34 ` Hannes Frederic Sowa
0 siblings, 1 reply; 6+ messages in thread
From: Hannes Frederic Sowa @ 2013-06-28 16:32 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Changli Gao, David S. Miller, netdev
On Fri, Jun 28, 2013 at 09:29:02AM -0700, Eric Dumazet wrote:
> On Sat, 2013-06-29 at 00:14 +0800, Changli Gao wrote:
> > --- a/net/ipv4/af_inet.c
> > +++ b/net/ipv4/af_inet.c
> > @@ -198,6 +198,9 @@ int inet_listen(struct socket *sock, int backlog)
> > unsigned char old_state;
> > int err;
> >
> > + if (backlog >= (1 << 16))
> > + return EINVAL;
> > +
> > lock_sock(sk);
> >
> > err = -EINVAL;
>
> This seems pretty buggy to me.
>
> 1) EINVAL is not -EINVAL
>
> 2) This might break existing applications.
Yes, we should clamp the value to netdev_max_backlog.
Greetings,
Hannes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: Check the argument for listen(2)
2013-06-28 16:32 ` Hannes Frederic Sowa
@ 2013-06-28 16:34 ` Hannes Frederic Sowa
2013-06-28 16:48 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: Hannes Frederic Sowa @ 2013-06-28 16:34 UTC (permalink / raw)
To: Eric Dumazet, Changli Gao, David S. Miller, netdev
On Fri, Jun 28, 2013 at 06:32:34PM +0200, Hannes Frederic Sowa wrote:
> On Fri, Jun 28, 2013 at 09:29:02AM -0700, Eric Dumazet wrote:
> > On Sat, 2013-06-29 at 00:14 +0800, Changli Gao wrote:
> > > --- a/net/ipv4/af_inet.c
> > > +++ b/net/ipv4/af_inet.c
> > > @@ -198,6 +198,9 @@ int inet_listen(struct socket *sock, int backlog)
> > > unsigned char old_state;
> > > int err;
> > >
> > > + if (backlog >= (1 << 16))
> > > + return EINVAL;
> > > +
> > > lock_sock(sk);
> > >
> > > err = -EINVAL;
> >
> > This seems pretty buggy to me.
> >
> > 1) EINVAL is not -EINVAL
> >
> > 2) This might break existing applications.
>
> Yes, we should clamp the value to netdev_max_backlog.
Nonsense, somaxconn would make more sense.
Sorry,
Hannes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: Check the argument for listen(2)
2013-06-28 16:34 ` Hannes Frederic Sowa
@ 2013-06-28 16:48 ` Eric Dumazet
0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2013-06-28 16:48 UTC (permalink / raw)
To: Hannes Frederic Sowa; +Cc: Changli Gao, David S. Miller, netdev
On Fri, 2013-06-28 at 18:34 +0200, Hannes Frederic Sowa wrote:
> Nonsense, somaxconn would make more sense.
>
If we keep u16, we could limit the sysctl (somaxconn,
tcp_max_syn_backlog) limits to 65535
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-06-28 16:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-28 16:14 [PATCH] net: Check the argument for listen(2) Changli Gao
2013-06-28 16:29 ` Eric Dumazet
2013-06-28 16:32 ` Hannes Frederic Sowa
2013-06-28 16:34 ` Hannes Frederic Sowa
2013-06-28 16:48 ` Eric Dumazet
2013-06-28 16:30 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox