sctp: fix copying more bytes than expected in sctp_add_bind_addr
Dmitry reported that sctp_add_bind_addr may read more bytes than expected in case the parameter is a IPv4 addr supplied by the user through calls such as sctp_bindx_add(), because it always copies sizeof(union sctp_addr) while the buffer may be just a struct sockaddr_in, which is smaller. This patch then fixes it by limiting the memcpy to the min between the union size and a (new parameter) provided addr size. Where possible this parameter still is the size of that union, except for reading from user-provided buffers, which then it accounts for protocol type. Reported-by: Dmitry Vyukov <dvyukov@google.com> Tested-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
e2857b8f11
commit
133800d1f0
@@ -386,7 +386,8 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
|
||||
/* Add the address to the bind address list.
|
||||
* Use GFP_ATOMIC since BHs will be disabled.
|
||||
*/
|
||||
ret = sctp_add_bind_addr(bp, addr, SCTP_ADDR_SRC, GFP_ATOMIC);
|
||||
ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len,
|
||||
SCTP_ADDR_SRC, GFP_ATOMIC);
|
||||
|
||||
/* Copy back into socket for getsockname() use. */
|
||||
if (!ret) {
|
||||
@@ -577,6 +578,7 @@ static int sctp_send_asconf_add_ip(struct sock *sk,
|
||||
af = sctp_get_af_specific(addr->v4.sin_family);
|
||||
memcpy(&saveaddr, addr, af->sockaddr_len);
|
||||
retval = sctp_add_bind_addr(bp, &saveaddr,
|
||||
sizeof(saveaddr),
|
||||
SCTP_ADDR_NEW, GFP_ATOMIC);
|
||||
addr_buf += af->sockaddr_len;
|
||||
}
|
||||
|
Reference in New Issue
Block a user