hazptr: handle NULL address in hazptr_detach
Subsystems (5)
Mathieu Desnoyers
reviewerPATCH 1/1 hazptr: handle NULL address in hazptr_detach
When hazptr_acquire loads a NULL pointer, it sets:
- slot_item->slot.addr = NULL,
- slot_item->ctx.ctx = ctx
- ctx->slot = slot
And it returns NULL.
Then hazptr_detach is called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.
Looking at what hazptr_note_context_switch() does before promoting to backup slot, it checks for a NULL slot->addr, which is exactly what is missing from hazptr_detach.
With this in place there would be no need to explicitly check the hazptr_acquire() return value before calling hazptr_detach().
hazptr_release() has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.
--- include/linux/hazptr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +3 -1
@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;guard (preempt)(); + slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);
Signature · 1 line
2.43.0
Quoted 15 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.
Quoted 6 lines
With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.
You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
Quoted 23 lines
Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")Reported-by kernel test robot <[email protected]>Signed-off-by Mathieu Desnoyers <[email protected]>Reviewed-by Bradley Morgan <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Boqun Feng <[email protected]>Cc Bradley Morgan <[email protected]>Cc <[email protected]>Cc <[email protected]>---
include/linux/hazptr.h| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)include/linux/hazptr.h +0
-0@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;guard (preempt)();
include/linux/hazptr.h void hazptr_detach(struct hazptr_ctx *ctx) · line 171
Quoted 10 lines
include/linux/hazptr.h +3
-1+ slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);
Mathieu Desnoyers
reviewerQuoted 20 lines · Bradley Morgan
Quoted 18 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
Quoted 7 lines
Quoted 3 lines
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
The splat is available at the "Closes" URL below. I'm not sure whether we should duplicate this verbose information ?
Paul ?
Thanks,
Mathieu
Quoted 38 lines
Quoted 25 lines
Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")Reported-by kernel test robot <[email protected]>Signed-off-by Mathieu Desnoyers <[email protected]>Reviewed-by Bradley Morgan <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Boqun Feng <[email protected]>Cc Bradley Morgan <[email protected]>Cc <[email protected]>Cc <[email protected]>---
include/linux/hazptr.h| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)include/linux/hazptr.h +0
-0@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;guard (preempt)();include/linux/hazptr.h void hazptr_detach(struct hazptr_ctx *ctx) · line 171
Quoted 10 lines
include/linux/hazptr.h +3
-1+ slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Quoted 25 lines · Mathieu Desnoyers
Quoted 24 lines · Bradley Morgan
Quoted 21 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.
Quoted 9 lines
Quoted 3 lines
You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
The splat is available at the "Closes" URL below. I'm not sure whether we should duplicate this verbose information ?
Paul ?
This is a example of what I did.
From 8861f6d5c0678a7c5089c7b272509fc5931b8437 Mon Sep 17 00:00:00 2001
From: Bradley Morgan <[email protected]>
Date: Thu, 27 Aug 2026 17:43:38 +0000
Subject: ima: Check for ERR_PTR from dentry_path() in validate_hash_algo()
From: Bradley Morgan <[email protected]>
commit 8861f6d5c0678a7c5089c7b272509fc5931b8437 upstream.
dentry_path() returns ERR_PTR(-ENAMETOOLONG) when the path exceeds the buffer. validate_hash_algo() passes the result straight to integrity_audit_msg() without checking. ERR_PTR is not NULL, so integrity_audit_message() sees a valid pointer and calls strlen() on it, which faults:
BUG: unable to handle page fault for address: ffffffffffffffdc
RIP: 0010:strlen+0x30/0xa0
Call Trace:
audit_log_untrustedstring+0x19/0x30
integrity_audit_message+0x366/0x4f0
ima_inode_setxattr+0x512/0x5f0Check for IS_ERR() and use NULL instead, which makes the audit message skip the name= field instead of crashing.
security/integrity/ima/ima_appraise.c | 2 ++ 1 file changed, 2 insertions(+)
security/integrity/ima/ima_appraise.c +2 -0
@@ -754,6 +754,8 @@ static int validate_hash_algo(struct denreturn -EACCES ; path =dentry_path (dentry, pathbuf,PATH_MAX ); +if (IS_ERR (path)) + path =NULL ;integrity_audit_msg (AUDIT_INTEGRITY_DATA ,d_inode (dentry), path,"set_data" , errmsg, -EACCES ,0 );
Quoted 43 lines
Thanks,
Mathieu
Quoted 5 lines
Quoted 5 lines
Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")Reported-by kernel test robot <[email protected]>Closes:
https://lore.kernel.org/oe-lkp/[email protected]
Quoted 18 lines
Quoted 18 lines
Signed-off-by Mathieu Desnoyers <[email protected]>Reviewed-by Bradley Morgan <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Boqun Feng <[email protected]>Cc Bradley Morgan <[email protected]>Cc <[email protected]>Cc <[email protected]>---
include/linux/hazptr.h| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)include/linux/hazptr.h +0
-0@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;Quoted 15 lines
include/linux/hazptr.h void hazptr_detach(struct hazptr_ctx *ctx) · line 171
Quoted 12 lines
include/linux/hazptr.h +3
-1guard (preempt)(); + slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);--- Thanks!
Quoted 4 lines
Paul E. McKenney
maintainerQuoted 25 lines · Mathieu Desnoyers
Quoted 24 lines · Bradley Morgan
Quoted 21 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.
Quoted 8 lines
Quoted 3 lines
You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
The splat is available at the "Closes" URL below. I'm not sure whether we should duplicate this verbose information ?
Paul ?
I am fine either way, as long as the information is reasonably easily accessible. Which is the case either way. ;-)
Thanx, Paul
Quoted 48 lines
Thanks,
Mathieu
Quoted 38 lines
Quoted 25 lines
Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")Reported-by kernel test robot <[email protected]>Signed-off-by Mathieu Desnoyers <[email protected]>Reviewed-by Bradley Morgan <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Boqun Feng <[email protected]>Cc Bradley Morgan <[email protected]>Cc <[email protected]>Cc <[email protected]>---
include/linux/hazptr.h| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)include/linux/hazptr.h +0
-0@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;guard (preempt)();include/linux/hazptr.h void hazptr_detach(struct hazptr_ctx *ctx) · line 171
Quoted 10 lines
include/linux/hazptr.h +3
-1+ slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Quoted 36 lines · Paul E. McKenney
Quoted 5 lines · Mathieu Desnoyers
Quoted 4 lines · Bradley Morgan
Quoted 2 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx asif
Quoted 1 line
Quoted 1 line
Quoted 1 line
needed to be promoted to backup slot, even though it has a NULL
addr.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
hazptr_release()has a early return check for NULL addr as well, soit
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
makes sense that detach does an early return (no-op) similarly.
You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
The splat is available at the "Closes" URL below. I'm not sure whether we should duplicate this verbose information ?
Quoted 7 lines
Quoted 1 line
Paul ?
I am fine either way, as long as the information is reasonably easily accessible. Which is the case either way. ;-)
Thanx, Paul
Hi, what do you reckon, do you wanna merge it?
I can co develop hazptr if u want, it's school season for me but oh well. Commit to Linux anyway!
Quoted 43 lines
Quoted 9 lines
Thanks,
Mathieu
Quoted 5 lines
Quoted 5 lines
Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")Reported-by kernel test robot <[email protected]>Closes:
https://lore.kernel.org/oe-lkp/[email protected]
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Signed-off-by Mathieu Desnoyers <[email protected]>Reviewed-by Bradley Morgan <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Boqun Feng <[email protected]>Cc Bradley Morgan <[email protected]>Cc <[email protected]>Cc <[email protected]>---
include/linux/hazptr.h| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)include/linux/hazptr.h +0
-0@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
include/linux/hazptr.h +3
-0guard (preempt)(); + slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;Quoted 9 lines
include/linux/hazptr.h void hazptr_detach(struct hazptr_ctx *ctx) · line 171
Quoted 6 lines
include/linux/hazptr.h +0
-1#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);--- Thanks!
Quoted 7 lines
https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
Signature · 4 lines
-- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Mathieu Desnoyers
reviewerQuoted 30 lines · Paul E. McKenney
Quoted 29 lines · Mathieu Desnoyers
Quoted 27 lines · Bradley Morgan
Quoted 15 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.Quoted 6 lines
With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
Quoted 7 lines
Quoted 4 lines
The splat is available at the "Closes" URL below. I'm not sure whether we should duplicate this verbose information ?
Paul ?
I am fine either way, as long as the information is reasonably easily accessible. Which is the case either way. ;-)
Then I favor a concise commit message, leaving the splat details to the "Closes" link. Feel free to pick up this patch for testing.
Thank you!
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Paul E. McKenney
maintainerQuoted 36 lines · Mathieu Desnoyers
Quoted 35 lines · Paul E. McKenney
Quoted 33 lines · Mathieu Desnoyers
Quoted 20 lines · Bradley Morgan
Quoted 18 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().Quoted 7 lines
Quoted 3 lines
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.You shall kill me for this!!
Could you perhaps do a splat in ze commit description pls?
The splat is available at the "Closes" URL below. I'm not sure whether we should duplicate this verbose information ?
Paul ?
Quoted 7 lines
Quoted 2 lines
I am fine either way, as long as the information is reasonably easily accessible. Which is the case either way. ;-)
Then I favor a concise commit message, leaving the splat details to the "Closes" link. Feel free to pick up this patch for testing.
Thank you!
Done, thank you! With this applied, the CPU-hotplug-related failures are gone. Or at least much lower probability. ;-)
Thanx, Paul
Applied this fix patch on top of Pual's v2 RFC patch series. The issue cannot be reproduce.
On Tue, Sep 08, 2026 at 11:22:14AM -0400, Mathieu Desnoyers wrote:
> When hazptr_acquire loads a NULL pointer, it sets:
>
> - slot_item->slot.addr = NULL,
> - slot_item->ctx.ctx = ctx
> - ctx->slot = slot
>
> And it returns NULL.
>
> Then hazptr_detach is called on this ctx, it will act on the ctx as if
> needed to be promoted to backup slot, even though it has a NULL addr.
>
> Looking at what hazptr_note_context_switch() does before promoting
> to backup slot, it checks for a NULL slot->addr, which is exactly
> what is missing from hazptr_detach.
>
> With this in place there would be no need to explicitly check the
> hazptr_acquire() return value before calling hazptr_detach().
>
> hazptr_release() has a early return check for NULL addr as well, so it
> makes sense that detach does an early return (no-op) similarly.
>
> Fixes: 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")
> Reported-by: kernel test robot <[email protected]>
> Closes: https://lore.kernel.org/oe-lkp/[email protected]
> Signed-off-by: Mathieu Desnoyers <[email protected]>
> Reviewed-by: Bradley Morgan <[email protected]>
> Cc: Paul E. McKenney <[email protected]>
> Cc: Boqun Feng <[email protected]>
> Cc: Bradley Morgan <[email protected]>
> Cc: <[email protected]>
> Cc: <[email protected]>
> ---
> include/linux/hazptr.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/hazptr.h b/include/linux/hazptr.h
> index 43122c5673bd..d1670121947a 100644
> --- a/include/linux/hazptr.h
> +++ b/include/linux/hazptr.h
> @@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)
> struct hazptr_slot *slot;
>
> guard(preempt)();
> + slot = ctx->slot;
> + if (!slot->addr)
> + return;
> #ifdef CONFIG_HAZPTR_DEBUG
> ctx->detach_task = ctx->detach_cpu = true;
> #endif
> - slot = ctx->slot;
> if (unlikely(hazptr_slot_is_backup(ctx, slot)))
> return;
> hazptr_promote_to_backup_slot(ctx, slot);
> --
> 2.43.0
> Applied this fix patch on top of Pual's v2 RFC patch series. The issue cannot be reproduce.
Paul E. McKenney
maintainerQuoted 61 lines · kernel test robot
Quoted 56 lines · Mathieu Desnoyers
When
hazptr_acquireloads a NULL pointer, it sets:-
slot_item->slot.addr= NULL,
-slot_item->ctx.ctx= ctx
-ctx->slot= slotAnd it returns NULL.
Then
hazptr_detachis called on this ctx, it will act on the ctx as if needed to be promoted to backup slot, even though it has a NULL addr.Looking at what
hazptr_note_context_switch()does before promoting to backup slot, it checks for a NULLslot->addr, which is exactly what is missing fromhazptr_detach.With this in place there would be no need to explicitly check the
hazptr_acquire()return value before callinghazptr_detach().
hazptr_release()has a early return check for NULL addr as well, so it makes sense that detach does an early return (no-op) similarly.Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")Reported-by kernel test robot <[email protected]>Signed-off-by Mathieu Desnoyers <[email protected]>Reviewed-by Bradley Morgan <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Boqun Feng <[email protected]>Cc Bradley Morgan <[email protected]>Cc <[email protected]>Cc <[email protected]>--- include/linux/hazptr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)include/linux/hazptr.h +3
-1@@ -160,10 +160,12 @@ void hazptr_detach(struct hazptr_ctx *ctx)struct hazptr_slot *slot;guard (preempt)(); + slot = ctx->slot; +if (!slot->addr) +return ;#ifdef CONFIG_HAZPTR_DEBUG ctx->detach_task = ctx->detach_cpu = true;#endif - slot = ctx->slot;if (unlikely (hazptr_slot_is_backup (ctx, slot)))return ;hazptr_promote_to_backup_slot (ctx, slot);Signature · 1 line
2.43.0Applied this fix patch on top of Pual's v2 RFC patch series. The issue cannot be reproduce.
Quoted 1 line
Tested-by kernel test robot <[email protected]>
Thank you! I will apply this on my next rebase.
Thanx, Paul