All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
@ 2021-11-30 11:08 ` Zhou Qingyang
  0 siblings, 0 replies; 6+ messages in thread
From: Zhou Qingyang @ 2021-11-30 11:08 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Shahed Shaikh, Manish Chopra, GR-Linux-NIC-Dev,
	David S. Miller, Jakub Kicinski, Matthias Brugger,
	Sucheta Chakraborty, Sritej Velaga, Sony Chacko,
	Anirban Chakraborty, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

In qlcnic_83xx_add_rings(), the indirect function of
ahw->hw_ops->alloc_mbx_args will be called to allocate memory for
cmd.req.arg, and there is a dereference of it in qlcnic_83xx_add_rings(),
which could lead to a NULL pointer dereference on failure of the
indirect function like qlcnic_83xx_alloc_mbx_args().

Fix this bug by adding a check of alloc_mbx_args(), this patch
imitates the logic of mbx_cmd()'s failure handling.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_QLCNIC=m show no new warnings, and our
static analyzer no longer warns about this code.

Fixes: 7f9664525f9c ("qlcnic: 83xx memory map and HW access routine")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index d51bac7ba5af..bd0607680329 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -1077,8 +1077,14 @@ static int qlcnic_83xx_add_rings(struct qlcnic_adapter *adapter)
 	sds_mbx_size = sizeof(struct qlcnic_sds_mbx);
 	context_id = recv_ctx->context_id;
 	num_sds = adapter->drv_sds_rings - QLCNIC_MAX_SDS_RINGS;
-	ahw->hw_ops->alloc_mbx_args(&cmd, adapter,
-				    QLCNIC_CMD_ADD_RCV_RINGS);
+	err = ahw->hw_ops->alloc_mbx_args(&cmd, adapter,
+					QLCNIC_CMD_ADD_RCV_RINGS);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Failed to alloc mbx args %d\n", err);
+		return err;
+	}
+
 	cmd.req.arg[1] = 0 | (num_sds << 8) | (context_id << 16);
 
 	/* set up status rings, mbx 2-81 */
-- 
2.25.1


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

* [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
@ 2021-11-30 11:08 ` Zhou Qingyang
  0 siblings, 0 replies; 6+ messages in thread
From: Zhou Qingyang @ 2021-11-30 11:08 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Shahed Shaikh, Manish Chopra, GR-Linux-NIC-Dev,
	David S. Miller, Jakub Kicinski, Matthias Brugger,
	Sucheta Chakraborty, Sritej Velaga, Sony Chacko,
	Anirban Chakraborty, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

In qlcnic_83xx_add_rings(), the indirect function of
ahw->hw_ops->alloc_mbx_args will be called to allocate memory for
cmd.req.arg, and there is a dereference of it in qlcnic_83xx_add_rings(),
which could lead to a NULL pointer dereference on failure of the
indirect function like qlcnic_83xx_alloc_mbx_args().

Fix this bug by adding a check of alloc_mbx_args(), this patch
imitates the logic of mbx_cmd()'s failure handling.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_QLCNIC=m show no new warnings, and our
static analyzer no longer warns about this code.

Fixes: 7f9664525f9c ("qlcnic: 83xx memory map and HW access routine")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index d51bac7ba5af..bd0607680329 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -1077,8 +1077,14 @@ static int qlcnic_83xx_add_rings(struct qlcnic_adapter *adapter)
 	sds_mbx_size = sizeof(struct qlcnic_sds_mbx);
 	context_id = recv_ctx->context_id;
 	num_sds = adapter->drv_sds_rings - QLCNIC_MAX_SDS_RINGS;
-	ahw->hw_ops->alloc_mbx_args(&cmd, adapter,
-				    QLCNIC_CMD_ADD_RCV_RINGS);
+	err = ahw->hw_ops->alloc_mbx_args(&cmd, adapter,
+					QLCNIC_CMD_ADD_RCV_RINGS);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Failed to alloc mbx args %d\n", err);
+		return err;
+	}
+
 	cmd.req.arg[1] = 0 | (num_sds << 8) | (context_id << 16);
 
 	/* set up status rings, mbx 2-81 */
-- 
2.25.1


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
@ 2021-11-30 11:08 ` Zhou Qingyang
  0 siblings, 0 replies; 6+ messages in thread
From: Zhou Qingyang @ 2021-11-30 11:08 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Shahed Shaikh, Manish Chopra, GR-Linux-NIC-Dev,
	David S. Miller, Jakub Kicinski, Matthias Brugger,
	Sucheta Chakraborty, Sritej Velaga, Sony Chacko,
	Anirban Chakraborty, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

In qlcnic_83xx_add_rings(), the indirect function of
ahw->hw_ops->alloc_mbx_args will be called to allocate memory for
cmd.req.arg, and there is a dereference of it in qlcnic_83xx_add_rings(),
which could lead to a NULL pointer dereference on failure of the
indirect function like qlcnic_83xx_alloc_mbx_args().

Fix this bug by adding a check of alloc_mbx_args(), this patch
imitates the logic of mbx_cmd()'s failure handling.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_QLCNIC=m show no new warnings, and our
static analyzer no longer warns about this code.

Fixes: 7f9664525f9c ("qlcnic: 83xx memory map and HW access routine")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index d51bac7ba5af..bd0607680329 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -1077,8 +1077,14 @@ static int qlcnic_83xx_add_rings(struct qlcnic_adapter *adapter)
 	sds_mbx_size = sizeof(struct qlcnic_sds_mbx);
 	context_id = recv_ctx->context_id;
 	num_sds = adapter->drv_sds_rings - QLCNIC_MAX_SDS_RINGS;
-	ahw->hw_ops->alloc_mbx_args(&cmd, adapter,
-				    QLCNIC_CMD_ADD_RCV_RINGS);
+	err = ahw->hw_ops->alloc_mbx_args(&cmd, adapter,
+					QLCNIC_CMD_ADD_RCV_RINGS);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Failed to alloc mbx args %d\n", err);
+		return err;
+	}
+
 	cmd.req.arg[1] = 0 | (num_sds << 8) | (context_id << 16);
 
 	/* set up status rings, mbx 2-81 */
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
  2021-11-30 11:08 ` Zhou Qingyang
  (?)
@ 2021-12-02  3:00   ` patchwork-bot+netdevbpf
  -1 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-02  3:00 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, shshaikh, manishc, GR-Linux-NIC-Dev, davem, kuba,
	matthias.bgg, sucheta.chakraborty, sritej.velaga, sony.chacko,
	anirban.chakraborty, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

Hello:

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

On Tue, 30 Nov 2021 19:08:48 +0800 you wrote:
> In qlcnic_83xx_add_rings(), the indirect function of
> ahw->hw_ops->alloc_mbx_args will be called to allocate memory for
> cmd.req.arg, and there is a dereference of it in qlcnic_83xx_add_rings(),
> which could lead to a NULL pointer dereference on failure of the
> indirect function like qlcnic_83xx_alloc_mbx_args().
> 
> Fix this bug by adding a check of alloc_mbx_args(), this patch
> imitates the logic of mbx_cmd()'s failure handling.
> 
> [...]

Here is the summary with links:
  - clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
    https://git.kernel.org/netdev/net/c/e2dabc4f7e7b

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] 6+ messages in thread

* Re: [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
@ 2021-12-02  3:00   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-02  3:00 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, shshaikh, manishc, GR-Linux-NIC-Dev, davem, kuba,
	matthias.bgg, sucheta.chakraborty, sritej.velaga, sony.chacko,
	anirban.chakraborty, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

Hello:

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

On Tue, 30 Nov 2021 19:08:48 +0800 you wrote:
> In qlcnic_83xx_add_rings(), the indirect function of
> ahw->hw_ops->alloc_mbx_args will be called to allocate memory for
> cmd.req.arg, and there is a dereference of it in qlcnic_83xx_add_rings(),
> which could lead to a NULL pointer dereference on failure of the
> indirect function like qlcnic_83xx_alloc_mbx_args().
> 
> Fix this bug by adding a check of alloc_mbx_args(), this patch
> imitates the logic of mbx_cmd()'s failure handling.
> 
> [...]

Here is the summary with links:
  - clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
    https://git.kernel.org/netdev/net/c/e2dabc4f7e7b

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



_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
@ 2021-12-02  3:00   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-02  3:00 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, shshaikh, manishc, GR-Linux-NIC-Dev, davem, kuba,
	matthias.bgg, sucheta.chakraborty, sritej.velaga, sony.chacko,
	anirban.chakraborty, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

Hello:

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

On Tue, 30 Nov 2021 19:08:48 +0800 you wrote:
> In qlcnic_83xx_add_rings(), the indirect function of
> ahw->hw_ops->alloc_mbx_args will be called to allocate memory for
> cmd.req.arg, and there is a dereference of it in qlcnic_83xx_add_rings(),
> which could lead to a NULL pointer dereference on failure of the
> indirect function like qlcnic_83xx_alloc_mbx_args().
> 
> Fix this bug by adding a check of alloc_mbx_args(), this patch
> imitates the logic of mbx_cmd()'s failure handling.
> 
> [...]

Here is the summary with links:
  - clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
    https://git.kernel.org/netdev/net/c/e2dabc4f7e7b

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



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-12-02  3:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 11:08 [PATCH] clk: mediatek: net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings() Zhou Qingyang
2021-11-30 11:08 ` Zhou Qingyang
2021-11-30 11:08 ` Zhou Qingyang
2021-12-02  3:00 ` patchwork-bot+netdevbpf
2021-12-02  3:00   ` patchwork-bot+netdevbpf
2021-12-02  3:00   ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.