net: atlantic: Use kmalloc_array to prevent overflow of dynamic size calculation
PATCH 1/1 net: atlantic: Use kmalloc_array to prevent overflow of dynamic size calculation
Use kmalloc_array to avoid potential overflow during dynamic size calculation inside kmalloc.
---
Note: Patch is tested for compilation.
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1 -1
@@ -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 );if (!buff)return -ENOMEM ;
Signature · 1 line
2.34.1
Quoted 14 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.Signed-off-by Bhanu Seshu Kumar Valluri <[email protected]>---
Note: Patch is tested for compilation.drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-0
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c static unsigned int aq_ptp_skb_buf_len(struct ptp_skb_ring *ring) · line 186
Quoted 6 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1
-1@@ -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); ?
Quoted 2 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-0if (!buff)return -ENOMEM ;
Quoted 10 lines · Sahil Chandna
Quoted 9 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.Signed-off-by Bhanu Seshu Kumar Valluri <[email protected]>---
Note: Patch is tested for compilation.drivers/net/ethernet/aquantia/atlantic/aq_ptp.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1
-1@@ -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.
Quoted 4 lines
Quoted 3 lines
if (!buff)
return-ENOMEM;
Quoted 24 lines · bhanuseshukumar
Quoted 10 lines · Sahil Chandna
Quoted 9 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.Signed-off-by Bhanu Seshu Kumar Valluri <[email protected]>---
Note: Patch is tested for compilation.drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 11 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c static unsigned int aq_ptp_skb_buf_len(struct ptp_skb_ring *ring) · line 185
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1
-1@@ -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); ?
Quoted 1 line
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.
Quoted 32 lines · Eric Dumazet
Quoted 24 lines · bhanuseshukumar
Quoted 10 lines · Sahil Chandna
Quoted 9 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.Signed-off-by Bhanu Seshu Kumar Valluri <[email protected]>---
Note: Patch is tested for compilation.drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 11 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c static unsigned int aq_ptp_skb_buf_len(struct ptp_skb_ring *ring) · line 185
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1
-1@@ -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); ?Quoted 1 line
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)
Quoted 7 lines
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.rstThanks.
Thank you for sharing helpful documentation. I will send a cleanup patch designated with net-next once net-next reopens.
Thanks.