netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net-next v2] ipv4: inet_bind: check the addr_len first
@ 2015-06-02 12:21 Denis Kirjanov
  2015-06-02 14:33 ` Hannes Frederic Sowa
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Kirjanov @ 2015-06-02 12:21 UTC (permalink / raw)
  To: netdev; +Cc: Denis Kirjanov

Perform the address length check first, before calling
the proto specific bind() function

Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>

v2: add the proper tag tp the subject
---
 net/ipv4/af_inet.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 6ad0f7a..333e2fa 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -426,14 +426,15 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 	int chk_addr_ret;
 	int err;
 
+	err = -EINVAL;
+	if (addr_len < sizeof(struct sockaddr_in))
+		goto out;
+
 	/* If the socket has its own bind function then use it. (RAW) */
 	if (sk->sk_prot->bind) {
 		err = sk->sk_prot->bind(sk, uaddr, addr_len);
 		goto out;
 	}
-	err = -EINVAL;
-	if (addr_len < sizeof(struct sockaddr_in))
-		goto out;
 
 	if (addr->sin_family != AF_INET) {
 		/* Compatibility games : accept AF_UNSPEC (mapped to AF_INET)
-- 
1.7.10.4

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

* Re: [net-next v2] ipv4: inet_bind: check the addr_len first
  2015-06-02 12:21 [net-next v2] ipv4: inet_bind: check the addr_len first Denis Kirjanov
@ 2015-06-02 14:33 ` Hannes Frederic Sowa
  2015-06-02 15:13   ` Denis Kirjanov
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Frederic Sowa @ 2015-06-02 14:33 UTC (permalink / raw)
  To: Denis Kirjanov, netdev

Hello,

On Tue, Jun 2, 2015, at 14:21, Denis Kirjanov wrote:
> Perform the address length check first, before calling
> the proto specific bind() function

Can you give more detail why you did this change and what bug it fixes?

Thanks,
Hannes

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

* Re: [net-next v2] ipv4: inet_bind: check the addr_len first
  2015-06-02 14:33 ` Hannes Frederic Sowa
@ 2015-06-02 15:13   ` Denis Kirjanov
  2015-06-02 21:30     ` Hannes Frederic Sowa
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Kirjanov @ 2015-06-02 15:13 UTC (permalink / raw)
  To: Hannes Frederic Sowa; +Cc: netdev

On 6/2/15, Hannes Frederic Sowa <hannes@stressinduktion.org> wrote:
> Hello,
>
> On Tue, Jun 2, 2015, at 14:21, Denis Kirjanov wrote:
>> Perform the address length check first, before calling
>> the proto specific bind() function
>
> Can you give more detail why you did this change and what bug it fixes?
I've sent the v2 version with the net-next tag. The idea is simple:
check the error condition first and then do the useful work.

>
> Thanks,
> Hannes
>

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

* Re: [net-next v2] ipv4: inet_bind: check the addr_len first
  2015-06-02 15:13   ` Denis Kirjanov
@ 2015-06-02 21:30     ` Hannes Frederic Sowa
  2015-06-03  6:56       ` Denis Kirjanov
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Frederic Sowa @ 2015-06-02 21:30 UTC (permalink / raw)
  To: Denis Kirjanov; +Cc: netdev



On Tue, Jun 2, 2015, at 17:13, Denis Kirjanov wrote:
> On 6/2/15, Hannes Frederic Sowa <hannes@stressinduktion.org> wrote:
> > Hello,
> >
> > On Tue, Jun 2, 2015, at 14:21, Denis Kirjanov wrote:
> >> Perform the address length check first, before calling
> >> the proto specific bind() function
> >
> > Can you give more detail why you did this change and what bug it fixes?
> I've sent the v2 version with the net-next tag. The idea is simple:
> check the error condition first and then do the useful work.

Hmm, IMHO the specific proto->bind handlers have to take care of the
check themselves. You could argue that we should do the checks always in
inet_bind but then you have to remove the addr_len checks from the raw
and ping bind handlers, otherwise people become confused if they modify
the code. I am in favor of leaving the current logic as is, sorry.

Thanks,
Hannes

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

* Re: [net-next v2] ipv4: inet_bind: check the addr_len first
  2015-06-02 21:30     ` Hannes Frederic Sowa
@ 2015-06-03  6:56       ` Denis Kirjanov
  0 siblings, 0 replies; 5+ messages in thread
From: Denis Kirjanov @ 2015-06-03  6:56 UTC (permalink / raw)
  To: Hannes Frederic Sowa; +Cc: netdev

On 6/3/15, Hannes Frederic Sowa <hannes@stressinduktion.org> wrote:
>
>
> On Tue, Jun 2, 2015, at 17:13, Denis Kirjanov wrote:
>> On 6/2/15, Hannes Frederic Sowa <hannes@stressinduktion.org> wrote:
>> > Hello,
>> >
>> > On Tue, Jun 2, 2015, at 14:21, Denis Kirjanov wrote:
>> >> Perform the address length check first, before calling
>> >> the proto specific bind() function
>> >
>> > Can you give more detail why you did this change and what bug it fixes?
>> I've sent the v2 version with the net-next tag. The idea is simple:
>> check the error condition first and then do the useful work.
>
> Hmm, IMHO the specific proto->bind handlers have to take care of the
> check themselves. You could argue that we should do the checks always in
> inet_bind but then you have to remove the addr_len checks from the raw
> and ping bind handlers, otherwise people become confused if they modify
> the code. I am in favor of leaving the current logic as is, sorry.

Yeah, right, but if we can do the check a bit earlier, why not..

>
> Thanks,
> Hannes
>

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

end of thread, other threads:[~2015-06-03  6:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-02 12:21 [net-next v2] ipv4: inet_bind: check the addr_len first Denis Kirjanov
2015-06-02 14:33 ` Hannes Frederic Sowa
2015-06-02 15:13   ` Denis Kirjanov
2015-06-02 21:30     ` Hannes Frederic Sowa
2015-06-03  6:56       ` Denis Kirjanov

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).