public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
To: Paul Menzel <pmenzel@molgen.mpg.de>
Cc: marcel@holtmann.org, luiz.dentz@gmail.com,
	linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] drivers/bluetooth: btbcm: Use kmalloc_array() to prevent overflow
Date: Wed, 12 Nov 2025 00:54:41 +0530	[thread overview]
Message-ID: <aRONeQcfWA_YvzTe@ideapad> (raw)
In-Reply-To: <78ccae43-731d-4cee-868d-50d3c5842ea8@molgen.mpg.de>

On Tue, Nov 11, 2025 at 04:20:14PM +0100, Paul Menzel wrote:
> > Replace the open-coded multiplication in kmalloc() with a call
> > to kmalloc_array() to prevent potential integer overflows.
> 
> Excuse my ignorance, how would that overflow happen? How is the generated
> code different?

Hi Paul,

The compiler firstly calculates the size then calles kmalloc().
If BCM_FW_NAME_COUNT_MAX and BCM_FW_NAME_LEN are two large unsigned numbers,
their product can le larget than SIZE_T_MAX, this then leads to it wrapping
to a modulo of SIZE_T_MAX.

kmalloc() then gets called with this tiny, wrapped size.
It allocates a small buffer, and the when the code is executed further,
believing it has a large buffer, writes past the end of the tiny buffer
causing a heap buffer overflow.


> I’d add a dot/period at the end of the sentence.

Thanks! I'll keep that in mind for the future.

Regards,
Ayaan Mirza Baig

---
P.S. By the way, I'm a second year engineering student and
I apologize for any stupid-ish thing I might have done.
Also I would love to learn from my mistakes, any tips and pointers are highly appreciated.

  reply	other threads:[~2025-11-11 19:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11 14:20 [PATCH] drivers/bluetooth: btbcm: Use kmalloc_array() to prevent overflow Ayaan Mirza Baig
2025-11-11 15:05 ` bluez.test.bot
2025-11-11 15:20 ` [PATCH] " Paul Menzel
2025-11-11 19:24   ` Ayaan Mirza Baig [this message]
2025-11-13 16:10 ` patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aRONeQcfWA_YvzTe@ideapad \
    --to=ayaanmirzabaig85@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=pmenzel@molgen.mpg.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox