net: microchip: Fix potential null-ptr-deref due to create_singlethread_workqueue()
Subsystems (4)
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
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-derefCheck the ret value and return -ENOMEM if it is NULL.
--- drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c +3 -0
@@ -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
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()callscreate_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-derefCheck the ret value and return
-ENOMEMif it is NULL.
It looks good to me.
Quoted 24 lines
Fixes 12c2d0a5b8e2 ("net: lan966x: add ethtool configuration and statistics")Signed-off-by Shang XiaoJing <[email protected]>--- drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c +3
-1@@ -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
PATCH 2/2 net: microchip: sparx5: Fix potential null-ptr-deref in sparx_stats_init() and sparx5_start()
In reply to Shang XiaoJingsparx_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-derefCheck the ret value and return -ENOMEM if it is NULL. So as sparx5_start().
--- 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
@@ -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
@@ -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
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 NULLworkqueue_structpointer may causes null-ptr-deref. Will be fixed by this patch.Shang XiaoJing (2):
net: lan966x: Fix potential null-ptr-deref inlan966x_stats_init()
net: microchip: sparx5: Fix potential null-ptr-deref in
sparx_stats_init()andsparx5_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