Skip to content

Commit 2bc6262

Browse files
nathanchancerafaeljw
authored andcommitted
ACPI: CPPC: Replace cppc_attr with kobj_attribute
All of the CPPC sysfs show functions are called via indirect call in kobj_attr_show(), where they should be of type ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf); because that is the type of the ->show() member in 'struct kobj_attribute' but they are actually of type ssize_t (*show)(struct kobject *kobj, struct attribute *attr, char *buf); because of the ->show() member in 'struct cppc_attr', resulting in a Control Flow Integrity violation [1]. $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/highest_perf 3400 $ dmesg | grep "CFI failure" [ 175.970559] CFI failure (target: show_highest_perf+0x0/0x8): As far as I can tell, the only difference between 'struct cppc_attr' and 'struct kobj_attribute' aside from the type of the attr parameter is the type of the count parameter in the ->store() member (ssize_t vs. size_t), which does not actually matter because all of these nodes are read-only. Eliminate 'struct cppc_attr' in favor of 'struct kobj_attribute' to fix the violation. [1]: https://lore.kernel.org/r/20210401233216.2540591-1-samitolvanen@google.com/ Fixes: 158c998 ("ACPI / CPPC: add sysfs support to compute delivered performance") Link: ClangBuiltLinux#1343 Signed-off-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8a02d99 commit 2bc6262

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

drivers/acpi/cppc_acpi.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,15 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
118118
*/
119119
#define NUM_RETRIES 500ULL
120120

121-
struct cppc_attr {
122-
struct attribute attr;
123-
ssize_t (*show)(struct kobject *kobj,
124-
struct attribute *attr, char *buf);
125-
ssize_t (*store)(struct kobject *kobj,
126-
struct attribute *attr, const char *c, ssize_t count);
127-
};
128-
129121
#define define_one_cppc_ro(_name) \
130-
static struct cppc_attr _name = \
122+
static struct kobj_attribute _name = \
131123
__ATTR(_name, 0444, show_##_name, NULL)
132124

133125
#define to_cpc_desc(a) container_of(a, struct cpc_desc, kobj)
134126

135127
#define show_cppc_data(access_fn, struct_name, member_name) \
136128
static ssize_t show_##member_name(struct kobject *kobj, \
137-
struct attribute *attr, char *buf) \
129+
struct kobj_attribute *attr, char *buf) \
138130
{ \
139131
struct cpc_desc *cpc_ptr = to_cpc_desc(kobj); \
140132
struct struct_name st_name = {0}; \
@@ -160,7 +152,7 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf);
160152
show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
161153

162154
static ssize_t show_feedback_ctrs(struct kobject *kobj,
163-
struct attribute *attr, char *buf)
155+
struct kobj_attribute *attr, char *buf)
164156
{
165157
struct cpc_desc *cpc_ptr = to_cpc_desc(kobj);
166158
struct cppc_perf_fb_ctrs fb_ctrs = {0};

0 commit comments

Comments
 (0)