Skip to content

Commit 7005fdc

Browse files
nathanchancegregkh
authored andcommitted
ACPI: platform-profile: Fix CFI violation when accessing sysfs files
commit dd4f730 upstream. 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 of the same type as the callbacks in 'struct kobj_attribute'. However, ->show() and ->store() in the platform_profile driver are defined for struct device_attribute with the help of DEVICE_ATTR_RO() and DEVICE_ATTR_RW(), which results in 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) There is no functional issue from the type mismatch because the layout of 'struct kobj_attribute' and 'struct device_attribute' are the same, so the container_of() cast does not break anything aside from CFI. 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: All applicable <[email protected]> Fixes: a2ff95e ("ACPI: platform: Add platform profile support") Reported-by: John Rowley <[email protected]> Closes: ClangBuiltLinux/linux#2047 Tested-by: John Rowley <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Mark Pearson <[email protected]> Tested-by: Mark Pearson <[email protected]> Link: https://patch.msgid.link/20250210-acpi-platform_profile-fix-cfi-violation-v3-1-ed9e9901c33a@kernel.org [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]> [nathan: Fix conflicts in older stable branches] Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 20867f0 commit 7005fdc

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/acpi/platform_profile.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ static const char * const profile_names[] = {
2222
};
2323
static_assert(ARRAY_SIZE(profile_names) == PLATFORM_PROFILE_LAST);
2424

25-
static ssize_t platform_profile_choices_show(struct device *dev,
26-
struct device_attribute *attr,
25+
static ssize_t platform_profile_choices_show(struct kobject *kobj,
26+
struct kobj_attribute *attr,
2727
char *buf)
2828
{
2929
int len = 0;
@@ -49,8 +49,8 @@ static ssize_t platform_profile_choices_show(struct device *dev,
4949
return len;
5050
}
5151

52-
static ssize_t platform_profile_show(struct device *dev,
53-
struct device_attribute *attr,
52+
static ssize_t platform_profile_show(struct kobject *kobj,
53+
struct kobj_attribute *attr,
5454
char *buf)
5555
{
5656
enum platform_profile_option profile = PLATFORM_PROFILE_BALANCED;
@@ -77,8 +77,8 @@ static ssize_t platform_profile_show(struct device *dev,
7777
return sysfs_emit(buf, "%s\n", profile_names[profile]);
7878
}
7979

80-
static ssize_t platform_profile_store(struct device *dev,
81-
struct device_attribute *attr,
80+
static ssize_t platform_profile_store(struct kobject *kobj,
81+
struct kobj_attribute *attr,
8282
const char *buf, size_t count)
8383
{
8484
int err, i;
@@ -115,12 +115,12 @@ static ssize_t platform_profile_store(struct device *dev,
115115
return count;
116116
}
117117

118-
static DEVICE_ATTR_RO(platform_profile_choices);
119-
static DEVICE_ATTR_RW(platform_profile);
118+
static struct kobj_attribute attr_platform_profile_choices = __ATTR_RO(platform_profile_choices);
119+
static struct kobj_attribute attr_platform_profile = __ATTR_RW(platform_profile);
120120

121121
static struct attribute *platform_profile_attrs[] = {
122-
&dev_attr_platform_profile_choices.attr,
123-
&dev_attr_platform_profile.attr,
122+
&attr_platform_profile_choices.attr,
123+
&attr_platform_profile.attr,
124124
NULL
125125
};
126126

0 commit comments

Comments
 (0)