lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zr4rosIiK2a0sGhc@DUT025-TGLU.fm.intel.com>
Date: Thu, 15 Aug 2024 16:24:02 +0000
From: Matthew Brost <matthew.brost@...el.com>
To: Sergey Senozhatsky <senozhatsky@...omium.org>
CC: Tejun Heo <tj@...nel.org>, Lai Jiangshan <jiangshanlai@...il.com>,
	<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] workqueue: fix null-ptr-deref on __alloc_workqueue()
 error

On Thu, Aug 15, 2024 at 03:56:39PM +0000, Matthew Brost wrote:
> On Thu, Aug 15, 2024 at 04:24:27PM +0900, Sergey Senozhatsky wrote:
> > 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@intel.com/
> > 
> > Matthew, did you mean to do something like below instead?
> > Otherwise it breaks boot for me.
> > 
> 
> Yikes, my bad. My change worked locally and in Intel's CI for Xe [2]. So
> I did not realize this was an issue the way I had it coded. 
> 
> I believe you when you say this is an issue.
> 
> With that, the way I coded alloc_ordered_workqueue_lockdep_map could
> also be dangerous. Thinking that also should also be changed back to a
> macro too.
> 

Sergey,

Sorry double reply. Looked into this and va_start / va_end should only
be called once, so I think the change you have is correct.

The change wrt to alloc_ordered_workqueue_lockdep_map should look like
this I think:

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 8ccbf510880b..5e818eae092d 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -534,7 +534,7 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,
  * @fmt: printf format for the name of the workqueue
  * @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful)
  * @lockdep_map: user-defined lockdep_map
- * @args: args for @fmt
+ * @...: args for @fmt
  *
  * Same as alloc_ordered_workqueue but with the a user-define lockdep_map.
  * Useful for workqueues created with the same purpose and to avoid leaking a
@@ -543,20 +543,9 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,
  * RETURNS:
  * Pointer to the allocated workqueue on success, %NULL on failure.
  */
-__printf(1, 4) static inline struct workqueue_struct *
-alloc_ordered_workqueue_lockdep_map(const char *fmt, unsigned int flags,
-                                   struct lockdep_map *lockdep_map, ...)
-{
-       struct workqueue_struct *wq;
-       va_list args;
-
-       va_start(args, lockdep_map);
-       wq = alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | flags,
-                                        1, lockdep_map, args);
-       va_end(args);
+#define alloc_ordered_workqueue_lockdep_map(fmt, flags, lockdep_map, args...)  \
+       alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, lockdep_map, ##args)

-       return wq;
-}
 #endif

Matt

> Let's see what Tejon thinks?
> 
> Matt
> 
> [2] https://patchwork.freedesktop.org/series/136701/ 
> 
> > ---
> > 
> > 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",

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ