-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CFI failure at kobj_attr_show (target: platform_profile_choices_show) #2047
Comments
Can you test this patch? diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index d2f7fd7743a1..11278f785526 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -22,8 +22,8 @@ static const char * const profile_names[] = {
};
static_assert(ARRAY_SIZE(profile_names) == PLATFORM_PROFILE_LAST);
-static ssize_t platform_profile_choices_show(struct device *dev,
- struct device_attribute *attr,
+static ssize_t platform_profile_choices_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
char *buf)
{
int len = 0;
@@ -49,8 +49,8 @@ static ssize_t platform_profile_choices_show(struct device *dev,
return len;
}
-static ssize_t platform_profile_show(struct device *dev,
- struct device_attribute *attr,
+static ssize_t platform_profile_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
char *buf)
{
enum platform_profile_option profile = PLATFORM_PROFILE_BALANCED;
@@ -77,8 +77,8 @@ static ssize_t platform_profile_show(struct device *dev,
return sysfs_emit(buf, "%s\n", profile_names[profile]);
}
-static ssize_t platform_profile_store(struct device *dev,
- struct device_attribute *attr,
+static ssize_t platform_profile_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
const char *buf, size_t count)
{
int err, i;
@@ -115,12 +115,12 @@ static ssize_t platform_profile_store(struct device *dev,
return count;
}
-static DEVICE_ATTR_RO(platform_profile_choices);
-static DEVICE_ATTR_RW(platform_profile);
+static struct kobj_attribute attr_platform_profile_choices = __ATTR_RO(platform_profile_choices);
+static struct kobj_attribute attr_platform_profile = __ATTR_RW(platform_profile);
static struct attribute *platform_profile_attrs[] = {
- &dev_attr_platform_profile_choices.attr,
- &dev_attr_platform_profile.attr,
+ &attr_platform_profile_choices.attr,
+ &attr_platform_profile.attr,
NULL
};
I've put it on paste.debian.net too since copying from GitHub does not always work well: https://paste.debian.net/downloadh/747d3f6b
If it works, please let me know if you would like a |
Looks to be working perfectly now! I can cat both of the aforementioned files, and also set the platform profile by echoing 'low-power', 'balanced', or 'performance' to Please use Many thanks for the prompt fix (and the kudos). 😄 |
Thanks a lot for the quick testing! I have sent a formal patch: https://lore.kernel.org/20240819-acpi-platform_profile-fix-cfi-violation-v1-1-479365d848f6@kernel.org/ |
When an attribute group is created with sysfs_create_group(), the ->sysfs_ops() callback is set to kobj_sysfs_ops, which sets the ->show() and ->store() callbacks to kobj_attr_show() and kobj_attr_store() respectively. These functions use container_of() to get the respective callback from the passed attribute, meaning that these callbacks need to be the same type as the callbacks in 'struct kobj_attribute'. However, the platform_profile sysfs functions have the type of the ->show() and ->store() callbacks in 'struct device_attribute', which results a CFI violation when accessing platform_profile or platform_profile_choices under /sys/firmware/acpi because the types do not match: CFI failure at kobj_attr_show+0x19/0x30 (target: platform_profile_choices_show+0x0/0x140; expected type: 0x7a69590c) This happens to work because the layout of 'struct kobj_attribute' and 'struct device_attribute' are the same, so the container_of() cast happens to allow the callbacks to still work. Change the type of platform_profile_choices_show() and platform_profile_{show,store}() to match the callbacks in 'struct kobj_attribute' and update the attribute variables to match, which resolves the CFI violation. Cc: [email protected] Fixes: a2ff95e ("ACPI: platform: Add platform profile support") Reported-by: John Rowley <[email protected]> Closes: ClangBuiltLinux#2047 Tested-by: John Rowley <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]>
What is the status of this patch? We had similiar issues - one I can remember was (2020 - early days of Clang-CFI): "perf/x86: fix sysfs type mismatches" |
Per the thread, I was waiting for Greg to give me some guidance on his proposed solution but I'll consider just sending v2 with the wording changes I mentioned if he does not reply by the end of the week. |
Hi @nathanchance, sorry for the ping but has there been any movement on this? I'm still seeing this issue in the just-released 6.12. Happy to test any v2 patches if you have them lying around. Thanks. :) |
Sorry for dropping the ball on the resend, I have sent v2 now: |
All good! You're doing an amazing job in this project. 👌😊
I can give this patch a try later on.
----------------------------------------
*From: *Nathan Chancellor ***@***.***>
*To: *ClangBuiltLinux/linux ***@***.***>
*CC: *flukeeey ***@***.***>; Author ***@***.***>
*Date: *18 Nov 2024 14:41:34
*Subject: *Re: [ClangBuiltLinux/linux] CFI failure at kobj_attr_show (target: platform_profile_choices_show) (Issue #2047)
…
Sorry for dropping the ball on the resend, I have sent v2 now:
***@***.***/
—
Reply to this email directly, view it on GitHub[#2047 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/BASZQVSRRKVHGJIT3FPZSBT2BH4BXAVCNFSM6AAAAABMYJ5PISVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBTGI2DQNBXGA].
You are receiving this because you authored the thread.
[Tracking image][https://github.com/notifications/beacon/BASZQVQQJQLIG4JANJUQEU32BH4BXA5CNFSM6AAAAABMYJ5PISWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUUANOVM.gif]
|
v2 is working well for me. 👍 |
How to reproduce?
Link: https://cateee.net/lkddb/web-lkddb/ACPI_PLATFORM_PROFILE.html |
Seems like you do not have a platform that actually supports platform profiles. You can grep around for |
I noticed a series on the mailing list that appears to massively update this driver, such that my patch may not apply (or be necessary) anymore (but I have not looked too closely). @flukeeey could you see if applying that series resolves this issue? If it does, I can potentially request that my patch be applied only to 6.13 and earlier, while that series can be the solution for 6.14 and beyond. |
I checked out
|
Thanks a lot for verifying! I think my patch is still going to be needed then. They are keeping |
Looking good! I did the following:
And everything is working well, including:
I will move to using the latter set of files in future, and look into submitting a patch/issue to the TLP power management project, which I'm using to switch between profiles (amongst other things) when moving battery<->AC. Thanks. :) |
That above commit removed important information in |
Hi!
When attempting to read
/sys/firmware/acpi/platform_profile
or/sys/firmware/acpi/platform_profile_choices
I receive a "SIGSEGV (Address boundary error)" error, with the following oops:System is an AMD Framework Laptop 13 running Arch Linux, kernel version 6.11.0-rc4 (commit: 20e8b2f2a6b2).
/proc/version:
Apologies if this is the incorrect place to report a CFI violation, and please let me know if I can assist further in investigation.
config.txt
The text was updated successfully, but these errors were encountered: