Skip to content

Commit

Permalink
net: check the length of the socket address passed to connect(2)
Browse files Browse the repository at this point in the history
check the length of the socket address passed to connect(2).

Check the length of the socket address passed to connect(2). If the
length is invalid, -EINVAL will be returned.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
net/bluetooth/l2cap.c | 3 ++-
net/bluetooth/rfcomm/sock.c | 3 ++-
net/bluetooth/sco.c | 3 ++-
net/can/bcm.c | 3 +++
net/ieee802154/af_ieee802154.c | 3 +++
net/ipv4/af_inet.c | 5 +++++
net/netlink/af_netlink.c | 3 +++
7 files changed, 20 insertions(+), 3 deletions(-)
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
xiaosuo authored and davem330 committed Apr 2, 2010
1 parent a1d6f3f commit 6503d96
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al

BT_DBG("sk %p", sk);

if (!addr || addr->sa_family != AF_BLUETOOTH)
if (!addr || alen < sizeof(addr->sa_family) ||
addr->sa_family != AF_BLUETOOTH)
return -EINVAL;

memset(&la, 0, sizeof(la));
Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/rfcomm/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ static int rfcomm_sock_connect(struct socket *sock, struct sockaddr *addr, int a

BT_DBG("sk %p", sk);

if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_rc))
if (alen < sizeof(struct sockaddr_rc) ||
addr->sa_family != AF_BLUETOOTH)
return -EINVAL;

lock_sock(sk);
Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen

BT_DBG("sk %p", sk);

if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_sco))
if (alen < sizeof(struct sockaddr_sco) ||
addr->sa_family != AF_BLUETOOTH)
return -EINVAL;

if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
Expand Down
3 changes: 3 additions & 0 deletions net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,9 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
struct sock *sk = sock->sk;
struct bcm_sock *bo = bcm_sk(sk);

if (len < sizeof(*addr))
return -EINVAL;

if (bo->bound)
return -EISCONN;

Expand Down
3 changes: 3 additions & 0 deletions net/ieee802154/af_ieee802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ static int ieee802154_sock_connect(struct socket *sock, struct sockaddr *uaddr,
{
struct sock *sk = sock->sk;

if (addr_len < sizeof(uaddr->sa_family))
return -EINVAL;

if (uaddr->sa_family == AF_UNSPEC)
return sk->sk_prot->disconnect(sk, flags);

Expand Down
5 changes: 5 additions & 0 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
{
struct sock *sk = sock->sk;

if (addr_len < sizeof(uaddr->sa_family))
return -EINVAL;
if (uaddr->sa_family == AF_UNSPEC)
return sk->sk_prot->disconnect(sk, flags);

Expand Down Expand Up @@ -573,6 +575,9 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
int err;
long timeo;

if (addr_len < sizeof(uaddr->sa_family))
return -EINVAL;

lock_sock(sk);

if (uaddr->sa_family == AF_UNSPEC) {
Expand Down
3 changes: 3 additions & 0 deletions net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
struct netlink_sock *nlk = nlk_sk(sk);
struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;

if (alen < sizeof(addr->sa_family))
return -EINVAL;

if (addr->sa_family == AF_UNSPEC) {
sk->sk_state = NETLINK_UNCONNECTED;
nlk->dst_pid = 0;
Expand Down

0 comments on commit 6503d96

Please sign in to comment.