Skip to contentSkip to conversation

x86/bugs: Don't warn when overwriting retbleed_return_thunk with srso_return_thunk

PATCH In review Suraj Jitindar Singh 4 participants 13 messages May 14, 2025 – May 16, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/bugs: Don't warn when overwriting retbleed_return_thunk with srso_return_thunk

A warning is emitted in set_return_thunk() when the return thunk is overwritten since this is likely a bug and will result in mitigations not functioning and the mitigation information displayed in sysfs being incorrect.

There is a special case when the return thunk is overwritten from retbleed_return_thunk to srso_return_thunk since srso_return_thunk provides a superset of the functionality of retbleed_return_thunk, and this is handled correctly in entry_untrain_ret(). Avoid emitting the warning in this scenario to clarify that this is not an issue.

This situation occurs on certain AMD processors (e.g. Zen2) which are affected by both retbleed and srso.

Fixes f4818881c47fd ("x86/its: Enable Indirect Target Selection mitigation")
Cc [email protected] # 5.15.x-
---
 arch/x86/kernel/cpu/bugs.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +10 -1
index 8596ce85026c..b7797636140f 100644
@@ -69,7 +69,16 @@ void (*x86_return_thunk)(void) __ro_after_init = __x86_return_thunk;
 
 static void __init set_return_thunk(void *thunk)
 {
-	if (x86_return_thunk != __x86_return_thunk)
+	/*
+	 * There can only be one return thunk enabled at a time, so issue a
+	 * warning when overwriting it. retbleed_return_thunk is a special case
+	 * which is safe to be overwritten with srso_return_thunk since it
+	 * provides a superset of the functionality and is handled correctly in
+	 * entry_untrain_ret().
+	 */
+	if ((x86_return_thunk != __x86_return_thunk) &&
+	    (thunk != srso_return_thunk ||
+	     x86_return_thunk != retbleed_return_thunk))
 		pr_warn("x86/bugs: return thunk changed\n");
 
 	x86_return_thunk = thunk;
Signature · 1 line
2.34.1
maintainer
#1 lore raw

arch/x86/kernel/cpu/bugs.c void (*x86_return_thunk)(void) __ro_after_init = __x86_return_thunk; · line 81

Quoted 11 lines · Suraj Jitindar Singh
arch/x86/kernel/cpu/bugs.c +10 -1
-	if (x86_return_thunk != __x86_return_thunk)
+	/*
+	 * There can only be one return thunk enabled at a time, so issue a
+	 * warning when overwriting it. retbleed_return_thunk is a special case
+	 * which is safe to be overwritten with srso_return_thunk since it
+	 * provides a superset of the functionality and is handled correctly in
+	 * entry_untrain_ret().
+	 */
+	if ((x86_return_thunk != __x86_return_thunk) &&
+	    (thunk != srso_return_thunk ||
+	     x86_return_thunk != retbleed_return_thunk))

Instead of making this an unreadable conditional, why don't we ...

Quoted 1 line

pr_warn("x86/bugs: return thunk changed\n");

... turn this into a

	pr_info("set return thunk to: %ps\n", ...)

and simply say which thunk was set?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#2 lore raw
Quoted 15 lines · Borislav Petkov

arch/x86/kernel/cpu/bugs.c void (*x86_return_thunk)(void) __ro_after_init = __x86_return_thunk; · line 81

Quoted 11 lines · Suraj Jitindar Singh
arch/x86/kernel/cpu/bugs.c +10 -1
-	if (x86_return_thunk != __x86_return_thunk)
+	/*
+	 * There can only be one return thunk enabled at a time, so issue a
+	 * warning when overwriting it. retbleed_return_thunk is a special case
+	 * which is safe to be overwritten with srso_return_thunk since it
+	 * provides a superset of the functionality and is handled correctly in
+	 * entry_untrain_ret().
+	 */
+	if ((x86_return_thunk != __x86_return_thunk) &&
+	    (thunk != srso_return_thunk ||
+	     x86_return_thunk != retbleed_return_thunk))

Instead of making this an unreadable conditional, why don't we ...

Quoted 7 lines
Quoted 1 line

pr_warn("x86/bugs: return thunk changed\n");

... turn this into a

	pr_info("set return thunk to: %ps\n", ...)

and simply say which thunk was set?

This was discussed during the mitigation, and pr_warn() was chosen because it was not obvious that srso mitigation also mitigates retbleed. (On a retrospect, there should have been a comment about it).

The conclusion was to make the srso and retbleed relationship clear and then take care of the pr_warn().

maintainer
#3 lore raw
Quoted 3 lines · Pawan Gupta

This was discussed during the mitigation, and pr_warn() was chosen because it was not obvious that srso mitigation also mitigates retbleed. (On a retrospect, there should have been a comment about it).

Why is that important?

We have multiple cases where a mitigation strategy addresses multiple attacks.

Quoted 2 lines

The conclusion was to make the srso and retbleed relationship clear and then take care of the pr_warn().

So let's ask ourselves: who is really going to see what single-line warning?

What are we *actually* trying to prevent here?

How about a big fat splat at least if we're really trying to prevent something nasty which causes a panic on warn...?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#4 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Pawan Gupta

This was discussed during the mitigation, and pr_warn() was chosen because it was not obvious that srso mitigation also mitigates retbleed. (On a retrospect, there should have been a comment about it).

Why is that important?

There are 4 mitigations that currently use return thunks, retbleed=stuff(Call Depth Tracking), retbleed=unret, SRSO and ITS. They all set the return thunks they want without checking if return thunks are already set by another mitigation. I understand the SRSO mitigates retbleed(BTC), but the same is not true for retbleed(RSB underflow mitigated by CDT) and ITS. If ITS overrides CDT return thunk, it will make CDT ineffective.

Quoted 1 line

We have multiple cases where a mitigation strategy addresses multiple attacks.

Agree, but here we are talking about the opposite case where a mitigation unintentionally renders a previously set mitigation ineffective.

Quoted 4 lines
Quoted 2 lines

The conclusion was to make the srso and retbleed relationship clear and then take care of the pr_warn().

So let's ask ourselves: who is really going to see what single-line warning?

Don't know. I guess some do, hence this patch.

Quoted 1 line

What are we *actually* trying to prevent here?

As I said above, a mitigation unintentionally make another mitigation ineffective.

Quoted 2 lines

How about a big fat splat at least if we're really trying to prevent something nasty which causes a panic on warn...?

Yes, maybe a WARN_ON() conditional to sanity checks for retbleed/SRSO.

maintainer
#5 lore raw
Quoted 2 lines · Pawan Gupta

As I said above, a mitigation unintentionally make another mitigation ineffective.

I actually didn't need an analysis - my point is: if you're going to warn about it, then make it big so that it gets caught.

Quoted 1 line

Yes, maybe a WARN_ON() conditional to sanity checks for retbleed/SRSO.

Yes, that.

At least.

The next step would be if this whole "let's set a thunk without overwriting a previously set one" can be fixed differently.

For now, though, the *least* what should be done here is catch the critical cases where a mitigation is rendered ineffective. And warning Joe Normal User about it doesn't bring anything. We do decide for the user what is safe or not, practically. At least this has been the strategy until now.

So the goal here should be to make Joe catch this and tell us to fix it.

Makes sense?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#6 lore raw
Quoted 16 lines · Borislav Petkov
Quoted 2 lines · Pawan Gupta

As I said above, a mitigation unintentionally make another mitigation ineffective.

I actually didn't need an analysis - my point is: if you're going to warn about it, then make it big so that it gets caught.

Quoted 1 line

Yes, maybe a WARN_ON() conditional to sanity checks for retbleed/SRSO.

Yes, that.

At least.

The next step would be if this whole "let's set a thunk without overwriting a previously set one" can be fixed differently.

Quoted 8 lines

For now, though, the *least* what should be done here is catch the critical cases where a mitigation is rendered ineffective. And warning Joe Normal User about it doesn't bring anything. We do decide for the user what is safe or not, practically. At least this has been the strategy until now.

So the goal here should be to make Joe catch this and tell us to fix it.

Makes sense?

Absolutely makes sense.

Suraj, do want to revise this patch? Or else I can do it too.

#7 lore raw
Quoted 35 lines · Pawan Gupta

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 28 lines · Borislav Petkov
Quoted 3 lines · Pawan Gupta

As I said above, a mitigation unintentionally make another mitigation
ineffective.

I actually didn't need an analysis - my point is: if you're going to warn
about it, then make it big so that it gets caught.

Quoted 2 lines

Yes, maybe a WARN_ON() conditional to sanity checks for retbleed/SRSO.

Yes, that.

At least.

The next step would be if this whole "let's set a thunk without overwriting
a previously set one" can be fixed differently.

For now, though, the *least* what should be done here is catch the critical
cases where a mitigation is rendered ineffective. And warning Joe Normal User
about it doesn't bring anything. We do decide for the user what is safe or
not, practically. At least this has been the strategy until now.

Quoted 8 lines
Quoted 4 lines

So the goal here should be to make Joe catch this and tell us to fix it.

Makes sense?

Absolutely makes sense.

Suraj, do want to revise this patch? Or else I can do it too.

Happy to revise it.

To be clear, based on my understanding the request is to make the warning more obvious with a WARN()?

#8 lore raw

PATCH 1/2 x86/bugs: WARN() when overwriting x86_return_thunk

In reply to Pawan Gupta

A warning message is emitted in set_return_thunk() when the return thunk is overwritten since this is likely a bug and will result in a mitigation not functioning and the mitigation information displayed in sysfs being incorrect.

Make this louder by using a WARN().

---
 arch/x86/kernel/cpu/bugs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/bugs.c +9 -2
index 8596ce85026c..9679fa30563c 100644
@@ -69,8 +69,15 @@ void (*x86_return_thunk)(void) __ro_after_init = __x86_return_thunk;
 
 static void __init set_return_thunk(void *thunk)
 {
-	if (x86_return_thunk != __x86_return_thunk)
-		pr_warn("x86/bugs: return thunk changed\n");
+	/*
+	 * There can only be one return thunk enabled at a time, so issue a
+	 * warning when overwriting it as this is likely a bug which will
+	 * result in a mitigation getting disabled and a vulnerability being
+	 * incorrectly reported in sysfs.
+	 */
+	WARN(x86_return_thunk != __x86_return_thunk,
+	     "x86/bugs: return thunk changed from %ps to %ps\n",
+	     x86_return_thunk, thunk);
 
 	x86_return_thunk = thunk;
 }
Signature · 1 line
2.34.1
#9 lore raw

PATCH 2/2 x86/bugs: Don't WARN() when overwriting retbleed_return_thunk with srso_return_thunk

There is a special case when the return thunk is overwritten from retbleed_return_thunk to srso_return_thunk since srso_return_thunk provides a superset of the functionality of retbleed_return_thunk, and this is handled correctly in entry_untrain_ret(). Avoid emitting the warning in this scenario to clarify that this is not an issue.

This situation occurs on certain AMD processors (e.g. Zen2) which are affected by both retbleed and srso.

Fixes f4818881c47fd ("x86/its: Enable Indirect Target Selection mitigation")
Cc [email protected] # 5.15.x-
---
 arch/x86/kernel/cpu/bugs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/bugs.c +7 -2
index 9679fa30563c..840902cee670 100644
@@ -73,9 +73,14 @@ static void __init set_return_thunk(void *thunk)
 	 * There can only be one return thunk enabled at a time, so issue a
 	 * warning when overwriting it as this is likely a bug which will
 	 * result in a mitigation getting disabled and a vulnerability being
-	 * incorrectly reported in sysfs.
+	 * incorrectly reported in sysfs. retbleed_return_thunk is a special
+	 * case which is safe to be overwritten with srso_return_thunk since it
+	 * provides a superset of the functionality and is handled correctly in
+	 * entry_untrain_ret().
 	 */
-	WARN(x86_return_thunk != __x86_return_thunk,
+	WARN((x86_return_thunk != __x86_return_thunk) &&
+	     (thunk != srso_return_thunk ||
+	      x86_return_thunk != retbleed_return_thunk),
 	     "x86/bugs: return thunk changed from %ps to %ps\n",
 	     x86_return_thunk, thunk);
 
Signature · 1 line
2.34.1
maintainer
#10 lore raw

Re: [PATCH 2/2] x86/bugs: Don't WARN() when overwriting retbleed_return_thunk with srso_return_thunk

arch/x86/kernel/cpu/bugs.c static void __init set_return_thunk(void *thunk) · line 85

Quoted 6 lines · Suraj Jitindar Singh
arch/x86/kernel/cpu/bugs.c +3 -1
-	WARN(x86_return_thunk != __x86_return_thunk,
+	WARN((x86_return_thunk != __x86_return_thunk) &&
+	     (thunk != srso_return_thunk ||
+	      x86_return_thunk != retbleed_return_thunk),
 	     "x86/bugs: return thunk changed from %ps to %ps\n",
 	     x86_return_thunk, thunk);

This is still adding that nasty conditional which I'd like to avoid.

And I just had this other idea: we're switching to select/update/apply logic with the mitigations and I'm sure we can use that new ability to select the proper mitigation when other mitigations are influencing the decision, to select the proper return thunk.

I'm thinking for retbleed and SRSO we could set it only once, perhaps in srso_select_mitigation() as it runs last.

I don't want to introduce an amd_return_thunk... :-)

But David might have a better idea...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#11 lore raw

RE: [PATCH 2/2] x86/bugs: Don't WARN() when overwriting retbleed_return_thunk with srso_return_thunk

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 32 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Friday, May 16, 2025 2:48 AM
To: Suraj Jitindar Singh <[email protected]>; Kaplan, David <[email protected]>
Cc: [email protected]; [email protected]; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Pawan Gupta <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] x86/bugs: Don't WARN() when overwriting retbleed_return_thunk with srso_return_thunk

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

arch/x86/kernel/cpu/bugs.c static void __init set_return_thunk(void *thunk) · line 85

Quoted 6 lines · Suraj Jitindar Singh
arch/x86/kernel/cpu/bugs.c +3 -1
-     WARN(x86_return_thunk != __x86_return_thunk,
+     WARN((x86_return_thunk != __x86_return_thunk) &&
+          (thunk != srso_return_thunk ||
+           x86_return_thunk != retbleed_return_thunk),
           "x86/bugs: return thunk changed from %ps to %ps\n",
           x86_return_thunk, thunk);

This is still adding that nasty conditional which I'd like to avoid.

And I just had this other idea: we're switching to select/update/apply logic with the mitigations and I'm sure we can use that new ability to select the proper mitigation when other mitigations are influencing the decision, to select the proper return thunk.

Quoted 7 lines

I'm thinking for retbleed and SRSO we could set it only once, perhaps in srso_select_mitigation() as it runs last.

I don't want to introduce an amd_return_thunk... :-)

But David might have a better idea...

Hmm. Since SRSO is kind of a superset of retbleed, it might make sense to create a new mitigation, RETBLEED_MITIGATION_SAFE_RET.

retbleed_update_mitigation() can change its mitigation to this if srso_mitigation is SAFE_RET (or SAFE_RET_UCODE_NEEDED). RETBLEED_MITIGATION_SAFE_RET can do nothing in retbleed_apply_mitigation() because it means that srso is taking care of things. Thoughts?

This also made me realize there's another minor missing interaction here, which is that if spec_rstack_overflow=ibpb, then that should set retbleed_mitigation to IBPB as well.

--David Kaplan

maintainer
#12 lore raw

Re: [PATCH 2/2] x86/bugs: Don't WARN() when overwriting retbleed_return_thunk with srso_return_thunk

Quoted 11 lines · David

Hmm. Since SRSO is kind of a superset of retbleed, it might make sense to create a new mitigation, RETBLEED_MITIGATION_SAFE_RET.

retbleed_update_mitigation() can change its mitigation to this if srso_mitigation is SAFE_RET (or SAFE_RET_UCODE_NEEDED). RETBLEED_MITIGATION_SAFE_RET can do nothing in retbleed_apply_mitigation() because it means that srso is taking care of things. Thoughts?

This also made me realize there's another minor missing interaction here, which is that if spec_rstack_overflow=ibpb, then that should set retbleed_mitigation to IBPB as well.

Ok, this sounds like we should expedite our srso mitigation cleanup intentions. :-)

Lemme find you on chat...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette