public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: Sahil Chandna <chandna.linuxkernel@gmail.com>,
	epomozov@marvell.com, irusskikh@marvell.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, kuba@kernel.org,
	pabeni@redhat.com, richardcochran@gmail.com,
	linux-kernel-mentees@lists.linuxfoundation.org,
	skhan@linuxfoundation.org, david.hunter.linux@gmail.com
Subject: Re: [PATCH] net: atlantic: Use kmalloc_array to prevent overflow of dynamic size calculation
Date: Tue, 30 Sep 2025 18:42:10 +0530	[thread overview]
Message-ID: <c1ac5c9b-9089-4bc3-be0b-27cc9468d05b@gmail.com> (raw)
In-Reply-To: <CANn89iJpvsB55vbTmZiDV=8H6xQ=dVtAZJsGo9f_4nrfZfCcJA@mail.gmail.com>

On 30/09/25 17:47, Eric Dumazet wrote:
> On Tue, Sep 30, 2025 at 4:39 AM bhanuseshukumar
> <bhanuseshukumar@gmail.com> wrote:
>>
>> On 30/09/25 16:54, Sahil Chandna wrote:
>>> On 30/09/2025 16:49, Bhanu Seshu Kumar Valluri wrote:
>>>> Use kmalloc_array to avoid potential overflow during dynamic size calculation
>>>> inside kmalloc.
>>>>
>>>> Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
>>>> ---
>>>>   Note: Patch is tested for compilation.
>>>>   drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 2 +-
>>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ptp.c b/drivers/net/ethernet/aquantia/atlantic/aq_ptp.c
>>>> index 5acb3e16b567..f445d449f80f 100644
>>>> --- a/drivers/net/ethernet/aquantia/atlantic/aq_ptp.c
>>>> +++ b/drivers/net/ethernet/aquantia/atlantic/aq_ptp.c
>>>> @@ -182,7 +182,7 @@ static unsigned int aq_ptp_skb_buf_len(struct ptp_skb_ring *ring)
>>>>     static int aq_ptp_skb_ring_init(struct ptp_skb_ring *ring, unsigned int size)
>>>>   {
>>>> -    struct sk_buff **buff = kmalloc(sizeof(*buff) * size, GFP_KERNEL);
>>>> +    struct sk_buff **buff = kmalloc_array(sizeof(*buff), size, GFP_KERNEL);
>>>>
>>> Shouldn't this be kmalloc_array(size, sizeof(*buff), GFP_KERNEL); ?
>>
>> I didn't change the order of arguments to make it easier to review.
> 
> I think this NIC limits the number of skbs per queue to less than 8192.
> 
> Also sizeof(struct sk_buff *) is quite small (a pointer is 8 or 4 bytes)
> 
> So your patch would probably target net-next as a cleanup, in about
> two weeks when the merge window is over.
> 
> More details in
> https://www.kernel.org/doc/Documentation/process/maintainer-netdev.rst
> 
> Thanks.

Thank you for sharing helpful documentation. I will send a cleanup patch designated with net-next once
net-next reopens.

Thanks.

      reply	other threads:[~2025-09-30 13:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-30 11:19 [PATCH] net: atlantic: Use kmalloc_array to prevent overflow of dynamic size calculation Bhanu Seshu Kumar Valluri
2025-09-30 11:24 ` Sahil Chandna
2025-09-30 11:37   ` bhanuseshukumar
2025-09-30 12:17     ` Eric Dumazet
2025-09-30 13:12       ` Bhanu Seshu Kumar Valluri [this message]

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=c1ac5c9b-9089-4bc3-be0b-27cc9468d05b@gmail.com \
    --to=bhanuseshukumar@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=chandna.linuxkernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=david.hunter.linux@gmail.com \
    --cc=edumazet@google.com \
    --cc=epomozov@marvell.com \
    --cc=irusskikh@marvell.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=skhan@linuxfoundation.org \
    /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