Skip to contentSkip to conversation

cpu/hotplug: Reset node state after operation

PATCH In review Thomas Gleixner 5 participants 5 messages Oct 21, 2017 – Oct 23, 2017 CPU hotplug

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu/hotplug: Reset node state after operation

The recent rework of the cpu hotplug internals changed the usage of the per cpu state->node field, but missed to clean it up after usage.

So subsequent hotplug operations use the stale pointer from a previous operation and hand it into the callback functions. The callbacks then dereference a pointer which either belongs to a different facility or points to freed and potentially reused memory. In either case data corruption and crashes are the obvious consequence.

Reset the node and the last pointers in the per cpu state to NULL after the operation which set them has completed.

Fixes 96abb968549c ("smp/hotplug: Allow external multi-instance rollback")
---
 kernel/cpu.c |    5 +++++
 1 file changed, 5 insertions(+)
kernel/cpu.c +5 -0
@@ -632,6 +632,11 @@ cpuhp_invoke_ap_callback(int cpu, enum c
 		__cpuhp_kick_ap(st);
 	}
 
+	/*
+	 * Clean up the leftovers so the next hotplug operation wont use stale
+	 * data.
+	 */
+	st->node = st->last = NULL;
 	return ret;
 }
 
#1 lore raw
cpu/hotplug: Reset node state after operation
Commit-ID:  1f7c70d6b2bc5de301f30456621e1161fddf4242
Gitweb:     https://git.kernel.org/tip/1f7c70d6b2bc5de301f30456621e1161fddf4242
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 21 Oct 2017 16:06:52 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 21 Oct 2017 16:11:30 +0200

cpu/hotplug: Reset node state after operation

The recent rework of the cpu hotplug internals changed the usage of the per cpu state->node field, but missed to clean it up after usage.

So subsequent hotplug operations use the stale pointer from a previous operation and hand it into the callback functions. The callbacks then dereference a pointer which either belongs to a different facility or points to freed and potentially reused memory. In either case data corruption and crashes are the obvious consequence.

Reset the node and the last pointers in the per cpu state to NULL after the operation which set them has completed.

Fixes 96abb968549c ("smp/hotplug: Allow external multi-instance rollback")
Cc Peter Zijlstra <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
---
 kernel/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/cpu.c +5 -0
index d851df2..04892a8 100644
@@ -632,6 +632,11 @@ cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, bool bringup,
 		__cpuhp_kick_ap(st);
 	}
 
+	/*
+	 * Clean up the leftovers so the next hotplug operation wont use stale
+	 * data.
+	 */
+	st->node = st->last = NULL;
 	return ret;
 }
 
Tested-by on v1 1/1
#2 lore raw
In reply to Thomas Gleixner
Quoted 9 lines · Thomas Gleixner

The recent rework of the cpu hotplug internals changed the usage of the per cpu state->node field, but missed to clean it up after usage.

So subsequent hotplug operations use the stale pointer from a previous operation and hand it into the callback functions. The callbacks then dereference a pointer which either belongs to a different facility or points to freed and potentially reused memory. In either case data corruption and crashes are the obvious consequence.

Quoted 6 lines

Reset the node and the last pointers in the per cpu state to NULL after the operation which set them has completed.

Fixes 96abb968549c ("smp/hotplug: Allow external multi-instance rollback")

This does fine with rcutorture, though it does not fix the lost (or egregiously delayed) timer problem that is still eluding me. Nevertheless, for whatever it is worth:

Quoted 19 lines
---
 kernel/cpu.c |    5 +++++
 1 file changed, 5 insertions(+)
kernel/cpu.c +5 -0
@@ -632,6 +632,11 @@ cpuhp_invoke_ap_callback(int cpu, enum c
 		__cpuhp_kick_ap(st);
 	}
 
+	/*
+	 * Clean up the leftovers so the next hotplug operation wont use stale
+	 * data.
+	 */
+	st->node = st->last = NULL;
 	return ret;
 }
 
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Thomas Gleixner
Quoted 9 lines · Thomas Gleixner

The recent rework of the cpu hotplug internals changed the usage of the per cpu state->node field, but missed to clean it up after usage.

So subsequent hotplug operations use the stale pointer from a previous operation and hand it into the callback functions. The callbacks then dereference a pointer which either belongs to a different facility or points to freed and potentially reused memory. In either case data corruption and crashes are the obvious consequence.

Quoted 6 lines

Reset the node and the last pointers in the per cpu state to NULL after the operation which set them has completed.

Fixes 96abb968549c ("smp/hotplug: Allow external multi-instance rollback")

Thanks for digging into that during the conf :-) And sorry for wrecking that.

Quoted 18 lines
---
 kernel/cpu.c |    5 +++++
 1 file changed, 5 insertions(+)
kernel/cpu.c +5 -0
@@ -632,6 +632,11 @@ cpuhp_invoke_ap_callback(int cpu, enum c
 		__cpuhp_kick_ap(st);
 	}
 
+	/*
+	 * Clean up the leftovers so the next hotplug operation wont use stale
+	 * data.
+	 */
+	st->node = st->last = NULL;
 	return ret;
 }
 
Tested-by on v1 1/1
#4 lore raw
In reply to Thomas Gleixner
Quoted 24 lines · Thomas Gleixner

The recent rework of the cpu hotplug internals changed the usage of the per cpu state->node field, but missed to clean it up after usage.

So subsequent hotplug operations use the stale pointer from a previous operation and hand it into the callback functions. The callbacks then dereference a pointer which either belongs to a different facility or points to freed and potentially reused memory. In either case data corruption and crashes are the obvious consequence.

Reset the node and the last pointers in the per cpu state to NULL after the operation which set them has completed.

Fixes 96abb968549c ("smp/hotplug: Allow external multi-instance rollback")
---
  kernel/cpu.c |    5 +++++
  1 file changed, 5 insertions(+)
kernel/cpu.c +0 -0
@@ -632,6 +632,11 @@ cpuhp_invoke_ap_callback(int cpu, enum c
  		__cpuhp_kick_ap(st);

kernel/cpu.c cpuhp_invoke_ap_callback(int cpu, enum c · line 642

Quoted 10 lines
kernel/cpu.c +5 -0
  	}
 
+	/*
+	 * Clean up the leftovers so the next hotplug operation wont use stale
+	 * data.
+	 */
+	st->node = st->last = NULL;
  	return ret;
  }
 

Our CI farm is happy with this fix, so:

Thanks for looking into is so quickly!

Regards,

Tvrtko