Netdev List
 help / color / mirror / Atom feed
* [PATCH v2] net: dsa: felix: fix possible NULL pointer dereference
@ 2022-03-29  9:08 Zheng Yongjun
  2022-03-29  9:18 ` Vladimir Oltean
  2022-03-30 19:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Zheng Yongjun @ 2022-03-29  9:08 UTC (permalink / raw)
  To: andrew, vivien.didelot, f.fainelli, davem, kuba, netdev,
	linux-kernel
  Cc: vladimir.oltean, claudiu.manoil, alexandre.belloni,
	UNGLinuxDriver

As the possible failure of the allocation, kzalloc() may return NULL
pointer.
Therefore, it should be better to check the 'sgi' in order to prevent
the dereference of NULL pointer.

Fixes: 23ae3a7877718 ("net: dsa: felix: add stream gate settings for psfp").
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
---

v1->v2:Rewrite fixes tag, delete extra 'q'.

 drivers/net/dsa/ocelot/felix_vsc9959.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 33f0ceae381d..2875b5250856 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -1940,6 +1940,10 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port,
 		case FLOW_ACTION_GATE:
 			size = struct_size(sgi, entries, a->gate.num_entries);
 			sgi = kzalloc(size, GFP_KERNEL);
+			if (!sgi) {
+				ret = -ENOMEM;
+				goto err;
+			}
 			vsc9959_psfp_parse_gate(a, sgi);
 			ret = vsc9959_psfp_sgi_table_add(ocelot, sgi);
 			if (ret) {
-- 
2.17.1


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

* Re: [PATCH v2] net: dsa: felix: fix possible NULL pointer dereference
  2022-03-29  9:08 [PATCH v2] net: dsa: felix: fix possible NULL pointer dereference Zheng Yongjun
@ 2022-03-29  9:18 ` Vladimir Oltean
  2022-03-30 19:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Oltean @ 2022-03-29  9:18 UTC (permalink / raw)
  To: Zheng Yongjun
  Cc: andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com,
	davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Claudiu Manoil,
	alexandre.belloni@bootlin.com, UNGLinuxDriver@microchip.com

On Tue, Mar 29, 2022 at 09:08:00AM +0000, Zheng Yongjun wrote:
> As the possible failure of the allocation, kzalloc() may return NULL
> pointer.
> Therefore, it should be better to check the 'sgi' in order to prevent
> the dereference of NULL pointer.
> 
> Fixes: 23ae3a7877718 ("net: dsa: felix: add stream gate settings for psfp").
> Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>

> 
> v1->v2:Rewrite fixes tag, delete extra 'q'.
> 
>  drivers/net/dsa/ocelot/felix_vsc9959.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
> index 33f0ceae381d..2875b5250856 100644
> --- a/drivers/net/dsa/ocelot/felix_vsc9959.c
> +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
> @@ -1940,6 +1940,10 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port,
>  		case FLOW_ACTION_GATE:
>  			size = struct_size(sgi, entries, a->gate.num_entries);
>  			sgi = kzalloc(size, GFP_KERNEL);
> +			if (!sgi) {
> +				ret = -ENOMEM;
> +				goto err;
> +			}
>  			vsc9959_psfp_parse_gate(a, sgi);
>  			ret = vsc9959_psfp_sgi_table_add(ocelot, sgi);
>  			if (ret) {
> -- 
> 2.17.1
>

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

* Re: [PATCH v2] net: dsa: felix: fix possible NULL pointer dereference
  2022-03-29  9:08 [PATCH v2] net: dsa: felix: fix possible NULL pointer dereference Zheng Yongjun
  2022-03-29  9:18 ` Vladimir Oltean
@ 2022-03-30 19:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-30 19:30 UTC (permalink / raw)
  To: zhengyongjun
  Cc: andrew, vivien.didelot, f.fainelli, davem, kuba, netdev,
	linux-kernel, vladimir.oltean, claudiu.manoil, alexandre.belloni,
	UNGLinuxDriver

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 29 Mar 2022 09:08:00 +0000 you wrote:
> As the possible failure of the allocation, kzalloc() may return NULL
> pointer.
> Therefore, it should be better to check the 'sgi' in order to prevent
> the dereference of NULL pointer.
> 
> Fixes: 23ae3a7877718 ("net: dsa: felix: add stream gate settings for psfp").
> Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
> 
> [...]

Here is the summary with links:
  - [v2] net: dsa: felix: fix possible NULL pointer dereference
    https://git.kernel.org/netdev/net/c/866b7a278cdb

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:[~2022-03-30 19:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-29  9:08 [PATCH v2] net: dsa: felix: fix possible NULL pointer dereference Zheng Yongjun
2022-03-29  9:18 ` Vladimir Oltean
2022-03-30 19:30 ` patchwork-bot+netdevbpf

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