Skip to contentSkip to conversation

ipv4: inet_bind: check the addr_len first

PATCH In review Denis Kirjanov 2 participants 5 messages Jun 2, 2015 – Jun 3, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ipv4: inet_bind: check the addr_len first

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

v2: add the proper tag tp the subject

---
 net/ipv4/af_inet.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/af_inet.c +4 -3
index 6ad0f7a..333e2fa 100644
@@ -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)
Signature · 1 line
1.7.10.4
#1 lore raw

Hello,

Quoted 2 lines · Denis Kirjanov

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

#2 lore raw
Quoted 7 lines · Hannes Frederic Sowa

Hello,

Quoted 2 lines · Denis Kirjanov

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.

Quoted 4 lines

Thanks,
Hannes

#3 lore raw
Quoted 10 lines · Denis Kirjanov
Quoted 7 lines · Hannes Frederic Sowa

Hello,

Quoted 2 lines · Denis Kirjanov

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

#4 lore raw
Quoted 11 lines · Hannes Frederic Sowa
Quoted 8 lines · Denis Kirjanov
Quoted 7 lines · Hannes Frederic Sowa

Hello,

Quoted 2 lines · Denis Kirjanov

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?

Quoted 8 lines
Quoted 2 lines

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

Quoted 4 lines

Thanks,
Hannes