In the Linux kernel, the following vulnerability has been resolved:
net/mlx5: Fix command bitmask initialization
Command bitmask have a dedicated bit for MANAGEPAGES command, this bit isn't Initialize during command bitmask Initialization, only during MANAGEPAGES.
In addition, mlx5cmdtriggercompletions() is trying to trigger completion for MANAGEPAGES command as well.
Hence, in case health error occurred before any MANAGEPAGES command have been invoke (for example, during mlx5enablehca()), mlx5cmdtriggercompletions() will try to trigger completion for MANAGE_PAGES command, which will result in null-ptr-deref error.[1]
Fix it by Initialize command bitmask correctly.
While at it, re-write the code for better understanding.
[1] BUG: KASAN: null-ptr-deref in mlx5cmdtriggercompletions+0x1db/0x600 [mlx5core] Write of size 4 at addr 0000000000000214 by task kworker/u96:2/12078 CPU: 10 PID: 12078 Comm: kworker/u96:2 Not tainted 6.9.0-rc2forupstreamdebug202404071901 #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Workqueue: mlx5health0000:08:00.0 mlx5fwfatalreportererrwork [mlx5core] Call Trace: <TASK> dumpstacklvl+0x7e/0xc0 kasanreport+0xb9/0xf0 kasancheckrange+0xec/0x190 mlx5cmdtriggercompletions+0x1db/0x600 [mlx5core] mlx5cmdflush+0x94/0x240 [mlx5core] entererrorstate+0x6c/0xd0 [mlx5core] mlx5fwfatalreportererrwork+0xf3/0x480 [mlx5core] processonework+0x787/0x1490 ? lockdephardirqsonprepare+0x400/0x400 ? pwqdecnrinflight+0xda0/0xda0 ? assignwork+0x168/0x240 workerthread+0x586/0xd30 ? rescuerthread+0xae0/0xae0 kthread+0x2df/0x3b0 ? kthreadcompleteandexit+0x20/0x20 retfromfork+0x2d/0x70 ? kthreadcompleteandexit+0x20/0x20 retfromfork_asm+0x11/0x20 </TASK>