Skip to content

Commit 14c6998

Browse files
committed
ACPI: platform-profile: Fix CFI violation when accessing sysfs files
JIRA: https://issues.redhat.com/browse/RHEL-89362 commit dd4f730 Author: Nathan Chancellor <nathan@kernel.org> Date: Tue, 18 Feb 2025 18:59:39 +0000 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 <stable@vger.kernel.org> Fixes: a2ff95e ("ACPI: platform: Add platform profile support") Reported-by: John Rowley <lkml@johnrowley.me> Closes: ClangBuiltLinux/linux#2047 Tested-by: John Rowley <lkml@johnrowley.me> Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Nathan Chancellor <nathan@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca> 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 <rafael.j.wysocki@intel.com> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent 9df80b1 commit 14c6998

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/acpi/platform_profile.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ static int _remove_hidden_choices(struct device *dev, void *arg)
289289

290290
/**
291291
* platform_profile_choices_show - Show the available profile choices for legacy sysfs interface
292-
* @dev: The device
292+
* @kobj: The kobject
293293
* @attr: The attribute
294294
* @buf: The buffer to write to
295295
*
296296
* Return: The number of bytes written
297297
*/
298-
static ssize_t platform_profile_choices_show(struct device *dev,
299-
struct device_attribute *attr,
298+
static ssize_t platform_profile_choices_show(struct kobject *kobj,
299+
struct kobj_attribute *attr,
300300
char *buf)
301301
{
302302
struct aggregate_choices_data data = {
@@ -371,14 +371,14 @@ static int _store_and_notify(struct device *dev, void *data)
371371

372372
/**
373373
* platform_profile_show - Show the current profile for legacy sysfs interface
374-
* @dev: The device
374+
* @kobj: The kobject
375375
* @attr: The attribute
376376
* @buf: The buffer to write to
377377
*
378378
* Return: The number of bytes written
379379
*/
380-
static ssize_t platform_profile_show(struct device *dev,
381-
struct device_attribute *attr,
380+
static ssize_t platform_profile_show(struct kobject *kobj,
381+
struct kobj_attribute *attr,
382382
char *buf)
383383
{
384384
enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
@@ -400,15 +400,15 @@ static ssize_t platform_profile_show(struct device *dev,
400400

401401
/**
402402
* platform_profile_store - Set the profile for legacy sysfs interface
403-
* @dev: The device
403+
* @kobj: The kobject
404404
* @attr: The attribute
405405
* @buf: The buffer to read from
406406
* @count: The number of bytes to read
407407
*
408408
* Return: The number of bytes read
409409
*/
410-
static ssize_t platform_profile_store(struct device *dev,
411-
struct device_attribute *attr,
410+
static ssize_t platform_profile_store(struct kobject *kobj,
411+
struct kobj_attribute *attr,
412412
const char *buf, size_t count)
413413
{
414414
struct aggregate_choices_data data = {
@@ -442,12 +442,12 @@ static ssize_t platform_profile_store(struct device *dev,
442442
return count;
443443
}
444444

445-
static DEVICE_ATTR_RO(platform_profile_choices);
446-
static DEVICE_ATTR_RW(platform_profile);
445+
static struct kobj_attribute attr_platform_profile_choices = __ATTR_RO(platform_profile_choices);
446+
static struct kobj_attribute attr_platform_profile = __ATTR_RW(platform_profile);
447447

448448
static struct attribute *platform_profile_attrs[] = {
449-
&dev_attr_platform_profile_choices.attr,
450-
&dev_attr_platform_profile.attr,
449+
&attr_platform_profile_choices.attr,
450+
&attr_platform_profile.attr,
451451
NULL
452452
};
453453

0 commit comments

Comments
 (0)