* [PATCH] Bluetooth: L2CAP: uninitialized variables in l2cap_sock_setsockopt()
@ 2022-01-07 7:16 Dan Carpenter
2022-01-07 7:40 ` Marcel Holtmann
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-01-07 7:16 UTC (permalink / raw)
To: Marcel Holtmann, hch
Cc: Johan Hedberg, Luiz Augusto von Dentz, Stefan Schmidt,
Matthieu Baerts, linux-bluetooth, kernel-janitors
The "opt" variable is a u32, but on some paths only the top bytes
were initialized and the others contained random stack data.
Fixes: a7b75c5a8c41 ("net: pass a sockptr_t into ->setsockopt")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
net/bluetooth/l2cap_sock.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 188e4d4813b0..ca8f07f3542b 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -904,6 +904,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
struct l2cap_conn *conn;
int len, err = 0;
u32 opt;
+ u16 mtu;
+ u8 mode;
BT_DBG("sk %p", sk);
@@ -1086,16 +1088,16 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
break;
}
- if (copy_from_sockptr(&opt, optval, sizeof(u16))) {
+ if (copy_from_sockptr(&mtu, optval, sizeof(u16))) {
err = -EFAULT;
break;
}
if (chan->mode == L2CAP_MODE_EXT_FLOWCTL &&
sk->sk_state == BT_CONNECTED)
- err = l2cap_chan_reconfigure(chan, opt);
+ err = l2cap_chan_reconfigure(chan, mtu);
else
- chan->imtu = opt;
+ chan->imtu = mtu;
break;
@@ -1117,14 +1119,14 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
break;
}
- if (copy_from_sockptr(&opt, optval, sizeof(u8))) {
+ if (copy_from_sockptr(&mode, optval, sizeof(u8))) {
err = -EFAULT;
break;
}
- BT_DBG("opt %u", opt);
+ BT_DBG("mode %u", mode);
- err = l2cap_set_mode(chan, opt);
+ err = l2cap_set_mode(chan, mode);
if (err)
break;
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] Bluetooth: L2CAP: uninitialized variables in l2cap_sock_setsockopt()
2022-01-07 7:16 [PATCH] Bluetooth: L2CAP: uninitialized variables in l2cap_sock_setsockopt() Dan Carpenter
@ 2022-01-07 7:40 ` Marcel Holtmann
0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2022-01-07 7:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: Christoph Hellwig, Johan Hedberg, Luiz Augusto von Dentz,
Stefan Schmidt, Matthieu Baerts, linux-bluetooth, kernel-janitors
Hi Dan,
> The "opt" variable is a u32, but on some paths only the top bytes
> were initialized and the others contained random stack data.
>
> Fixes: a7b75c5a8c41 ("net: pass a sockptr_t into ->setsockopt")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> net/bluetooth/l2cap_sock.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-07 7:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-07 7:16 [PATCH] Bluetooth: L2CAP: uninitialized variables in l2cap_sock_setsockopt() Dan Carpenter
2022-01-07 7:40 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox