ipv4: inet_bind: check the addr_len first
Subsystems (2)
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
@@ -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
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
Quoted 7 lines · Hannes Frederic Sowa
Hello,
Quoted 2 lines · Denis Kirjanov
Perform the address length check first, before calling the proto specific
bind()functionCan 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
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()functionCan 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
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()functionCan 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->bindhandlers have to take care of the check themselves. You could argue that we should do the checks always ininet_bindbut then you have to remove theaddr_lenchecks 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