Skip to contentSkip to conversation

hazptr: handle NULL address in hazptr_detach

PATCH In review Mathieu Desnoyers 4 participants 10 messages Sep 8 – Sep 10

Subsystems (5)
lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

PATCH 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.

Fixes 6357ec235c59 ("hazptrtorture: Fix hazptr ownership issue")
Cc Paul E. McKenney <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Bradley Morgan <[email protected]>
---
 include/linux/hazptr.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +3 -1
index 43122c5673bd..d1670121947a 100644
@@ -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
#1 lore raw
Quoted 15 lines · Mathieu Desnoyers

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.

Quoted 6 lines

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.

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")
Cc Paul E. McKenney <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Bradley Morgan <[email protected]>

---
include/linux/hazptr.h | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +0 -0
index 43122c5673bd..d1670121947a 100644
@@ -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);

--- Thanks!
https://lore.kernel.org/all/[email protected]/

author reviewer
#2 lore raw
Quoted 20 lines · Bradley Morgan
Quoted 18 lines · Mathieu Desnoyers

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().

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")
Cc Paul E. McKenney <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Bradley Morgan <[email protected]>

---
include/linux/hazptr.h | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +0 -0
index 43122c5673bd..d1670121947a 100644
@@ -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);

--- Thanks!
https://lore.kernel.org/all/[email protected]/

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#3 lore raw
Quoted 25 lines · Mathieu Desnoyers
Quoted 24 lines · Bradley Morgan
Quoted 21 lines · Mathieu Desnoyers

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.

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/0x5f0

Check for IS_ERR() and use NULL instead, which makes the audit message skip the name= field instead of crashing.

Fixes 4f2946aa0c45 ("IMA: introduce a new policy option func=SETXATTR_CHECK")
Reported-by [email protected]
 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 den
 		return -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")

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Quoted 18 lines
Quoted 18 lines

---
include/linux/hazptr.h | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +0 -0
index 43122c5673bd..d1670121947a 100644
@@ -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 -1
 	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);

--- Thanks!

Quoted 4 lines

https://lore.kernel.org/all/[email protected]/

--- Thanks!
https://lore.kernel.org/all/[email protected]/

maintainer
#4 lore raw
In reply to Mathieu Desnoyers
Quoted 25 lines · Mathieu Desnoyers
Quoted 24 lines · Bradley Morgan
Quoted 21 lines · Mathieu Desnoyers

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.

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")
Cc Paul E. McKenney <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Bradley Morgan <[email protected]>

---
include/linux/hazptr.h | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +0 -0
index 43122c5673bd..d1670121947a 100644
@@ -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);

--- Thanks!
https://lore.kernel.org/all/[email protected]/

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#5 lore raw
Quoted 36 lines · Paul E. McKenney
Quoted 5 lines · Mathieu Desnoyers
Quoted 4 lines · Bradley Morgan
Quoted 2 lines · Mathieu Desnoyers

When hazptr_acquire loads 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 = slot

And it returns NULL.

Then hazptr_detach is called on this ctx, it will act on the ctx as

if

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 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

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")

Closes:

https://lore.kernel.org/oe-lkp/[email protected]

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

---
include/linux/hazptr.h | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +0 -0
index 43122c5673bd..d1670121947a 100644
@@ -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 -0
 	guard(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

--- Thanks!
https://lore.kernel.org/all/[email protected]/

author reviewer
#6 lore raw
In reply to Paul E. McKenney
Quoted 30 lines · Paul E. McKenney
Quoted 29 lines · Mathieu Desnoyers
Quoted 27 lines · Bradley Morgan
Quoted 15 lines · Mathieu Desnoyers

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.

Quoted 6 lines

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.

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
maintainer
#7 lore raw
Quoted 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_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().

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

build bot Tested-by on v1 1/1
#8 lore raw
In reply to Mathieu Desnoyers
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.

maintainer
#9 lore raw
Quoted 61 lines · kernel test robot
Quoted 56 lines · Mathieu Desnoyers

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")
Cc Paul E. McKenney <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Bradley Morgan <[email protected]>
---
 include/linux/hazptr.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/hazptr.h +3 -1
index 43122c5673bd..d1670121947a 100644
@@ -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

Applied this fix patch on top of Pual's v2 RFC patch series. The issue cannot be reproduce.

Quoted 1 line

Thank you! I will apply this on my next rebase.

Thanx, Paul