2024-04-09 13:53:22

by Edward Adam Davis

[permalink] [raw]
Subject: [PATCH] Bluetooth: fix oob in hci_sock_setsockopt

If len < sizeof(opt) it will trigger oob, so take the min of them.

Reported-by: [email protected]
Signed-off-by: Edward Adam Davis <[email protected]>
---
net/bluetooth/hci_sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 4ee1b976678b..cee7ec1adbd2 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1946,7 +1946,7 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,

switch (optname) {
case HCI_DATA_DIR:
- if (copy_from_sockptr(&opt, optval, sizeof(opt))) {
+ if (copy_from_sockptr(&opt, optval, min_t(int, sizeof(opt), len))) {
err = -EFAULT;
break;
}
--
2.43.0



2024-04-09 14:13:41

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: fix oob in hci_sock_setsockopt

Hi Edward,

On Tue, Apr 9, 2024 at 9:42 AM Edward Adam Davis <[email protected]> wrote:
>
> If len < sizeof(opt) it will trigger oob, so take the min of them.
>
> Reported-by: [email protected]
> Signed-off-by: Edward Adam Davis <[email protected]>
> ---
> net/bluetooth/hci_sock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> index 4ee1b976678b..cee7ec1adbd2 100644
> --- a/net/bluetooth/hci_sock.c
> +++ b/net/bluetooth/hci_sock.c
> @@ -1946,7 +1946,7 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,
>
> switch (optname) {
> case HCI_DATA_DIR:
> - if (copy_from_sockptr(&opt, optval, sizeof(opt))) {
> + if (copy_from_sockptr(&opt, optval, min_t(int, sizeof(opt), len))) {
> err = -EFAULT;
> break;
> }
> --
> 2.43.0

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=35d2c39b23fffa3d5a216142cc51d86354024363


--
Luiz Augusto von Dentz