diff options
author | Jaganath Kanakkassery <jaganath.k@samsung.com> | 2015-05-14 12:58:08 +0530 |
---|---|---|
committer | Ziyan <jaraidaniel@gmail.com> | 2016-10-29 01:33:56 +0200 |
commit | 312071967d769709d23048a5fc8e715649ca72e9 (patch) | |
tree | 481c7838e265a0298a0f74fdc3f98cb64d8ba8b6 | |
parent | 6a89544efa4518c8cfc4ebbacab8c914748951f3 (diff) | |
download | kernel_samsung_tuna-312071967d769709d23048a5fc8e715649ca72e9.zip kernel_samsung_tuna-312071967d769709d23048a5fc8e715649ca72e9.tar.gz kernel_samsung_tuna-312071967d769709d23048a5fc8e715649ca72e9.tar.bz2 |
BACKPORT: Bluetooth: Fix potential NULL dereference in RFCOMM bind callback
(cherry picked from 951b6a0717db97ce420547222647bcc40bf1eacd)
addr can be NULL and it should not be dereferenced before NULL checking.
Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Change-Id: I18bda54bb1427d9443a39a04a5c551720118dc26
Bug: 30149612
-rw-r--r-- | net/bluetooth/rfcomm/sock.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 56fcfd1..e169a2c 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -346,15 +346,19 @@ static int rfcomm_sock_create(struct net *net, struct socket *sock, static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) { - struct sockaddr_rc *sa = (struct sockaddr_rc *) addr; + struct sockaddr_rc sa; struct sock *sk = sock->sk; - int err = 0; - - BT_DBG("sk %p %s", sk, batostr(&sa->rc_bdaddr)); + int len, err = 0; if (!addr || addr->sa_family != AF_BLUETOOTH) return -EINVAL; + memset(&sa, 0, sizeof(sa)); + len = min_t(unsigned int, sizeof(sa), addr_len); + memcpy(&sa, addr, len); + + BT_DBG("sk %p %s", sk, batostr(&sa.rc_bdaddr)); + lock_sock(sk); if (sk->sk_state != BT_OPEN) { @@ -369,12 +373,12 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr write_lock_bh(&rfcomm_sk_list.lock); - if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) { + if (sa.rc_channel && __rfcomm_get_sock_by_addr(sa.rc_channel, &sa.rc_bdaddr)) { err = -EADDRINUSE; } else { /* Save source address */ - bacpy(&bt_sk(sk)->src, &sa->rc_bdaddr); - rfcomm_pi(sk)->channel = sa->rc_channel; + bacpy(&bt_sk(sk)->src, &sa.rc_bdaddr); + rfcomm_pi(sk)->channel = sa.rc_channel; sk->sk_state = BT_BOUND; } |