Re: [PATCH] workqueue: fix null-ptr-deref on __alloc_workqueue() error

From: Sergey Senozhatsky
Date: Thu Aug 15 2024 - 03:24:42 EST


On (24/08/15 16:09), Sergey Senozhatsky wrote:
> On (24/08/15 16:02), Sergey Senozhatsky wrote:
> Oh, okay, so this is related to [1]
>
> workqueue: Split alloc_workqueue into internal function and lockdep init
>
> Cc-ing Matthew on this.
>
> [1] https://lore.kernel.org/all/20240809222827.3211998-2-matthew.brost@xxxxxxxxx/

Matthew, did you mean to do something like below instead?
Otherwise it breaks boot for me.

---

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7a2f4cbbe8b2..55e0e69ee604 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5615,12 +5615,11 @@ static void wq_adjust_max_active(struct workqueue_struct *wq)
} while (activated);
}

-__printf(1, 4)
static struct workqueue_struct *__alloc_workqueue(const char *fmt,
unsigned int flags,
- int max_active, ...)
+ int max_active,
+ va_list args)
{
- va_list args;
struct workqueue_struct *wq;
size_t wq_size;
int name_len;
@@ -5652,9 +5651,7 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
goto err_free_wq;
}

- va_start(args, max_active);
name_len = vsnprintf(wq->name, sizeof(wq->name), fmt, args);
- va_end(args);

if (name_len >= WQ_NAME_LEN)
pr_warn_once("workqueue: name exceeds WQ_NAME_LEN. Truncating to: %s\n",