• Nathan Chancellor's avatar
    ACPI: CPPC: Replace cppc_attr with kobj_attribute · 2bc6262c
    Nathan Chancellor authored
    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: 158c998e ("ACPI / CPPC: add sysfs support to compute delivered performance")
    Link: https://github.com/ClangBuiltLinux/linux/issues/1343Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
    Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    2bc6262c
cppc_acpi.c 40.2 KB