Skip to contentSkip to conversation

net: microchip: Fix potential null-ptr-deref due to create_singlethread_workqueue()

PATCH Applied Shang XiaoJing 3 participants 5 messages Nov 14, 2022 – Nov 16, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover net: microchip: Fix potential null-ptr-deref due to create_singlethread_workqueue()

There are some functions call create_singlethread_workqueue() without checking ret value, and the NULL workqueue_struct pointer may causes null-ptr-deref. Will be fixed by this patch.

Shang XiaoJing (2):
net: lan966x: Fix potential null-ptr-deref in lan966x_stats_init()
net: microchip: sparx5: Fix potential null-ptr-deref in
sparx_stats_init() and sparx5_start()

 drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c | 3 +++
 drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c   | 3 +++
 drivers/net/ethernet/microchip/sparx5/sparx5_main.c      | 3 +++
 3 files changed, 9 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 net: lan966x: Fix potential null-ptr-deref in lan966x_stats_init()

lan966x_stats_init() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:

lan966x_stats_init()

    create_singlethread_workqueue() # failed, lan966x->stats_queue is NULL
    queue_delayed_work()
        queue_delayed_work_on()
            __queue_delayed_work()  # warning here, but continue
                __queue_work()      # access wq->flags, null-ptr-deref

Check the ret value and return -ENOMEM if it is NULL.

Fixes 12c2d0a5b8e2 ("net: lan966x: add ethtool configuration and statistics")
---
 drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c +3 -0
index e58a27fd8b50..0fb0efc224be 100644
@@ -708,6 +708,9 @@ int lan966x_stats_init(struct lan966x *lan966x)
 	snprintf(queue_name, sizeof(queue_name), "%s-stats",
 		 dev_name(lan966x->dev));
 	lan966x->stats_queue = create_singlethread_workqueue(queue_name);
+	if (!lan966x->stats_queue)
+		return -ENOMEM;
+
 	INIT_DELAYED_WORK(&lan966x->stats_work, lan966x_check_stats_work);
 	queue_delayed_work(lan966x->stats_queue, &lan966x->stats_work,
 			   LAN966X_STATS_CHECK_DELAY);
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net: lan966x: Fix potential null-ptr-deref in lan966x_stats_init()

Quoted 6 lines · Shang XiaoJing

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

lan966x_stats_init() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:

Quoted 8 lines

lan966x_stats_init()

    create_singlethread_workqueue() # failed, lan966x->stats_queue is NULL
    queue_delayed_work()
        queue_delayed_work_on()
            __queue_delayed_work()  # warning here, but continue
                __queue_work()      # access wq->flags, null-ptr-deref

Check the ret value and return -ENOMEM if it is NULL.

It looks good to me.

Quoted 24 lines
Fixes 12c2d0a5b8e2 ("net: lan966x: add ethtool configuration and statistics")
---
 drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c +3 -1
index e58a27fd8b50..0fb0efc224be 100644
@@ -708,6 +708,9 @@ int lan966x_stats_init(struct lan966x *lan966x)
        snprintf(queue_name, sizeof(queue_name), "%s-stats",
                 dev_name(lan966x->dev));
        lan966x->stats_queue = create_singlethread_workqueue(queue_name);
+       if (!lan966x->stats_queue)
+               return -ENOMEM;
+
        INIT_DELAYED_WORK(&lan966x->stats_work, lan966x_check_stats_work);
        queue_delayed_work(lan966x->stats_queue, &lan966x->stats_work,
                           LAN966X_STATS_CHECK_DELAY);
--

2.17.1

Signature · 1 line
/Horatiu
#3 lore raw

PATCH 2/2 net: microchip: sparx5: Fix potential null-ptr-deref in sparx_stats_init() and sparx5_start()

In reply to Shang XiaoJing

sparx_stats_init() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:

sparx_stats_init()

    create_singlethread_workqueue() # failed, sparx5->stats_queue is NULL
    queue_delayed_work()
        queue_delayed_work_on()
            __queue_delayed_work()  # warning here, but continue
                __queue_work()      # access wq->flags, null-ptr-deref

Check the ret value and return -ENOMEM if it is NULL. So as sparx5_start().

Fixes af4b11022e2d ("net: sparx5: add ethtool configuration and statistics support")
Fixes b37a1bae742f ("net: sparx5: add mactable support")
---
 drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c | 3 +++
 drivers/net/ethernet/microchip/sparx5/sparx5_main.c    | 3 +++
 2 files changed, 6 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c +3 -0
index 6b0febcb7fa9..01f3a3a41cdb 100644
@@ -1253,6 +1253,9 @@ int sparx_stats_init(struct sparx5 *sparx5)
 	snprintf(queue_name, sizeof(queue_name), "%s-stats",
 		 dev_name(sparx5->dev));
 	sparx5->stats_queue = create_singlethread_workqueue(queue_name);
+	if (!sparx5->stats_queue)
+		return -ENOMEM;
+
 	INIT_DELAYED_WORK(&sparx5->stats_work, sparx5_check_stats_work);
 	queue_delayed_work(sparx5->stats_queue, &sparx5->stats_work,
 			   SPX5_STATS_CHECK_DELAY);
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3 -0
index 62a325e96345..eeac04b84638 100644
@@ -659,6 +659,9 @@ static int sparx5_start(struct sparx5 *sparx5)
 	snprintf(queue_name, sizeof(queue_name), "%s-mact",
 		 dev_name(sparx5->dev));
 	sparx5->mact_queue = create_singlethread_workqueue(queue_name);
+	if (!sparx5->mact_queue)
+		return -ENOMEM;
+
 	INIT_DELAYED_WORK(&sparx5->mact_work, sparx5_mact_pull_work);
 	queue_delayed_work(sparx5->mact_queue, &sparx5->mact_work,
 			   SPX5_MACT_PULL_DELAY);
Signature · 1 line
2.17.1
#4 lore raw
In reply to Shang XiaoJing
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 10 lines · On Mon, 14 Nov 2022 21:38:51 +0800 you wrote:

There are some functions call create_singlethread_workqueue() without checking ret value, and the NULL workqueue_struct pointer may causes null-ptr-deref. Will be fixed by this patch.

Shang XiaoJing (2):
net: lan966x: Fix potential null-ptr-deref in lan966x_stats_init()
net: microchip: sparx5: Fix potential null-ptr-deref in
sparx_stats_init() and sparx5_start()

[...]

Here is the summary with links:
- [1/2] net: lan966x: Fix potential null-ptr-deref in lan966x_stats_init()

    https://git.kernel.org/netdev/net/c/ba86af3733ae
  - [2/2] net: microchip: sparx5: Fix potential null-ptr-deref in sparx_stats_init() and sparx5_start()
    https://git.kernel.org/netdev/net/c/639f5d006e36

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html