The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: btrtl: Prevent potential NULL dereference
@ 2025-04-02 11:01 Dan Carpenter
  2025-04-02 11:55 ` Hans de Goede
  2025-04-02 21:10 ` patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-04-02 11:01 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, Jeremy Cline,
	Hans de Goede, linux-bluetooth, linux-kernel, kernel-janitors

The btrtl_initialize() function checks that rtl_load_file() either
had an error or it loaded a zero length file.  However, if it loaded
a zero length file then the error code is not set correctly.  It
results in an error pointer vs NULL bug, followed by a NULL pointer
dereference.  This was detected by Smatch:

drivers/bluetooth/btrtl.c:592 btrtl_initialize() warn: passing zero to 'ERR_PTR'

Fixes: 26503ad25de8 ("Bluetooth: btrtl: split the device initialization into smaller parts")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/bluetooth/btrtl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index d3eba0d4a57d..7838c89e529e 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -1215,6 +1215,8 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
 			rtl_dev_err(hdev, "mandatory config file %s not found",
 				    btrtl_dev->ic_info->cfg_name);
 			ret = btrtl_dev->cfg_len;
+			if (!ret)
+				ret = -EINVAL;
 			goto err_free;
 		}
 	}
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Bluetooth: btrtl: Prevent potential NULL dereference
  2025-04-02 11:01 [PATCH] Bluetooth: btrtl: Prevent potential NULL dereference Dan Carpenter
@ 2025-04-02 11:55 ` Hans de Goede
  2025-04-02 21:10 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2025-04-02 11:55 UTC (permalink / raw)
  To: Dan Carpenter, Martin Blumenstingl
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, Jeremy Cline,
	linux-bluetooth, linux-kernel, kernel-janitors

Hi,

On 2-Apr-25 1:01 PM, Dan Carpenter wrote:
> The btrtl_initialize() function checks that rtl_load_file() either
> had an error or it loaded a zero length file.  However, if it loaded
> a zero length file then the error code is not set correctly.  It
> results in an error pointer vs NULL bug, followed by a NULL pointer
> dereference.  This was detected by Smatch:
> 
> drivers/bluetooth/btrtl.c:592 btrtl_initialize() warn: passing zero to 'ERR_PTR'
> 
> Fixes: 26503ad25de8 ("Bluetooth: btrtl: split the device initialization into smaller parts")
> S

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


igned-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/bluetooth/btrtl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
> index d3eba0d4a57d..7838c89e529e 100644
> --- a/drivers/bluetooth/btrtl.c
> +++ b/drivers/bluetooth/btrtl.c
> @@ -1215,6 +1215,8 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
>  			rtl_dev_err(hdev, "mandatory config file %s not found",
>  				    btrtl_dev->ic_info->cfg_name);
>  			ret = btrtl_dev->cfg_len;
> +			if (!ret)
> +				ret = -EINVAL;
>  			goto err_free;
>  		}
>  	}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Bluetooth: btrtl: Prevent potential NULL dereference
  2025-04-02 11:01 [PATCH] Bluetooth: btrtl: Prevent potential NULL dereference Dan Carpenter
  2025-04-02 11:55 ` Hans de Goede
@ 2025-04-02 21:10 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2025-04-02 21:10 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: martin.blumenstingl, marcel, luiz.dentz, jeremy, hdegoede,
	linux-bluetooth, linux-kernel, kernel-janitors

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Wed, 2 Apr 2025 14:01:41 +0300 you wrote:
> The btrtl_initialize() function checks that rtl_load_file() either
> had an error or it loaded a zero length file.  However, if it loaded
> a zero length file then the error code is not set correctly.  It
> results in an error pointer vs NULL bug, followed by a NULL pointer
> dereference.  This was detected by Smatch:
> 
> drivers/bluetooth/btrtl.c:592 btrtl_initialize() warn: passing zero to 'ERR_PTR'
> 
> [...]

Here is the summary with links:
  - Bluetooth: btrtl: Prevent potential NULL dereference
    https://git.kernel.org/bluetooth/bluetooth-next/c/113f1345ce0c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-02 21:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 11:01 [PATCH] Bluetooth: btrtl: Prevent potential NULL dereference Dan Carpenter
2025-04-02 11:55 ` Hans de Goede
2025-04-02 21:10 ` patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox