[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABBYNZLoJtUpAR-yKpq9a1NCTjhdgWMNSdwGd7f9jtFR0LuEAA@mail.gmail.com>
Date: Wed, 12 Jul 2023 13:29:47 -0700
From: Luiz Augusto von Dentz <luiz.dentz@...il.com>
To: Chris Lu <chris.lu@...iatek.com>
Cc: Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Sean Wang <sean.wang@...iatek.com>,
Aaron Hou <aaron.hou@...iatek.com>,
Steve Lee <steve.lee@...iatek.com>,
linux-bluetooth <linux-bluetooth@...r.kernel.org>,
linux-kernel <linux-kernel@...r.kernel.org>,
linux-mediatek <linux-mediatek@...ts.infradead.org>
Subject: Re: [PATCH v4] Bluetooth: btmtk: Fix null pointer when processing coredump
Hi Chris,
On Wed, Jul 12, 2023 at 6:03 AM Chris Lu <chris.lu@...iatek.com> wrote:
>
> There may be a potential null pointer risk if offset value is
> less than 0 when doing memcmp in btmtk_process_coredump().
> Check offset is valid before doing memcmp.
>
> Signed-off-by: Chris Lu <chris.lu@...iatek.com>
> Co-developed-by: Sean Wang <sean.wang@...iatek.com>
> Signed-off-by: Sean Wang <sean.wang@...iatek.com>
You should probably include the Fixes tag of the patch that introduced
the problem.
> ---
> v2: fix typo
> v3: fix bot checking error
> v4: reduce variable 'offset' declaration in v3
> ---
> drivers/bluetooth/btmtk.c | 12 ++++++------
> drivers/bluetooth/btmtk.h | 1 +
> 2 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
> index 786f775196ae..9cc789272ab7 100644
> --- a/drivers/bluetooth/btmtk.c
> +++ b/drivers/bluetooth/btmtk.c
> @@ -395,12 +395,12 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
>
> /* Mediatek coredump data would be more than MTK_COREDUMP_NUM */
> if (data->cd_info.cnt > MTK_COREDUMP_NUM &&
> - skb->len > sizeof(MTK_COREDUMP_END) &&
> - !memcmp((char *)&skb->data[skb->len - sizeof(MTK_COREDUMP_END)],
> - MTK_COREDUMP_END, sizeof(MTK_COREDUMP_END) - 1)) {
> - bt_dev_info(hdev, "Mediatek coredump end");
> - hci_devcd_complete(hdev);
> - }
> + skb->len > MTK_COREDUMP_END_LEN)
> + if (!memcmp((char *)&skb->data[skb->len - MTK_COREDUMP_END_LEN],
> + MTK_COREDUMP_END, MTK_COREDUMP_END_LEN - 1)) {
> + bt_dev_info(hdev, "Mediatek coredump end");
> + hci_devcd_complete(hdev);
> + }
>
> break;
> }
> diff --git a/drivers/bluetooth/btmtk.h b/drivers/bluetooth/btmtk.h
> index 68309dfe076a..56f5502baadf 100644
> --- a/drivers/bluetooth/btmtk.h
> +++ b/drivers/bluetooth/btmtk.h
> @@ -24,6 +24,7 @@
>
> #define MTK_COREDUMP_SIZE (1024 * 1000)
> #define MTK_COREDUMP_END "coredump end"
> +#define MTK_COREDUMP_END_LEN (sizeof(MTK_COREDUMP_END))
> #define MTK_COREDUMP_NUM 255
>
> enum {
> --
> 2.18.0
>
--
Luiz Augusto von Dentz
Powered by blists - more mailing lists