Skip to content

Commit 2b70d4f

Browse files
Dan Carpenterholtmann
authored andcommitted
Bluetooth: L2CAP: uninitialized variables in l2cap_sock_setsockopt()
The "opt" variable is a u32, but on some paths only the top bytes were initialized and the others contained random stack data. Fixes: a7b75c5 ("net: pass a sockptr_t into ->setsockopt") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 4fac8a7 commit 2b70d4f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/bluetooth/l2cap_sock.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
904904
struct l2cap_conn *conn;
905905
int len, err = 0;
906906
u32 opt;
907+
u16 mtu;
908+
u8 mode;
907909

908910
BT_DBG("sk %p", sk);
909911

@@ -1086,16 +1088,16 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
10861088
break;
10871089
}
10881090

1089-
if (copy_from_sockptr(&opt, optval, sizeof(u16))) {
1091+
if (copy_from_sockptr(&mtu, optval, sizeof(u16))) {
10901092
err = -EFAULT;
10911093
break;
10921094
}
10931095

10941096
if (chan->mode == L2CAP_MODE_EXT_FLOWCTL &&
10951097
sk->sk_state == BT_CONNECTED)
1096-
err = l2cap_chan_reconfigure(chan, opt);
1098+
err = l2cap_chan_reconfigure(chan, mtu);
10971099
else
1098-
chan->imtu = opt;
1100+
chan->imtu = mtu;
10991101

11001102
break;
11011103

@@ -1117,14 +1119,14 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
11171119
break;
11181120
}
11191121

1120-
if (copy_from_sockptr(&opt, optval, sizeof(u8))) {
1122+
if (copy_from_sockptr(&mode, optval, sizeof(u8))) {
11211123
err = -EFAULT;
11221124
break;
11231125
}
11241126

1125-
BT_DBG("opt %u", opt);
1127+
BT_DBG("mode %u", mode);
11261128

1127-
err = l2cap_set_mode(chan, opt);
1129+
err = l2cap_set_mode(chan, mode);
11281130
if (err)
11291131
break;
11301132

0 commit comments

Comments
 (0)