All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI / CPPC: Replace cppc_attr with kobj_attribute
@ 2021-04-07 21:30 Nathan Chancellor
  2021-04-08 17:59 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2021-04-07 21:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Kees Cook, Sami Tolvanen
  Cc: linux-acpi, linux-kernel, clang-built-linux, Nathan Chancellor

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 different 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: 158c998ea44b ("ACPI / CPPC: add sysfs support to compute delivered performance")
Link: https://github.com/ClangBuiltLinux/linux/issues/1343
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/acpi/cppc_acpi.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 69057fcd2c04..a5e6fd0bafa1 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -119,23 +119,15 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
  */
 #define NUM_RETRIES 500ULL
 
-struct cppc_attr {
-	struct attribute attr;
-	ssize_t (*show)(struct kobject *kobj,
-			struct attribute *attr, char *buf);
-	ssize_t (*store)(struct kobject *kobj,
-			struct attribute *attr, const char *c, ssize_t count);
-};
-
 #define define_one_cppc_ro(_name)		\
-static struct cppc_attr _name =			\
+static struct kobj_attribute _name =		\
 __ATTR(_name, 0444, show_##_name, NULL)
 
 #define to_cpc_desc(a) container_of(a, struct cpc_desc, kobj)
 
 #define show_cppc_data(access_fn, struct_name, member_name)		\
 	static ssize_t show_##member_name(struct kobject *kobj,		\
-					struct attribute *attr,	char *buf) \
+				struct kobj_attribute *attr, char *buf)	\
 	{								\
 		struct cpc_desc *cpc_ptr = to_cpc_desc(kobj);		\
 		struct struct_name st_name = {0};			\
@@ -161,7 +153,7 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf);
 show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
 
 static ssize_t show_feedback_ctrs(struct kobject *kobj,
-		struct attribute *attr, char *buf)
+		struct kobj_attribute *attr, char *buf)
 {
 	struct cpc_desc *cpc_ptr = to_cpc_desc(kobj);
 	struct cppc_perf_fb_ctrs fb_ctrs = {0};

base-commit: 454859c552da78b0f587205d308401922b56863e
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ACPI / CPPC: Replace cppc_attr with kobj_attribute
  2021-04-07 21:30 [PATCH] ACPI / CPPC: Replace cppc_attr with kobj_attribute Nathan Chancellor
@ 2021-04-08 17:59 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-04-08 17:59 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Rafael J. Wysocki, Len Brown, Kees Cook, Sami Tolvanen,
	ACPI Devel Maling List, Linux Kernel Mailing List,
	clang-built-linux

On Wed, Apr 7, 2021 at 11:32 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> 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 different 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: 158c998ea44b ("ACPI / CPPC: add sysfs support to compute delivered performance")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1343
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  drivers/acpi/cppc_acpi.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index 69057fcd2c04..a5e6fd0bafa1 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -119,23 +119,15 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
>   */
>  #define NUM_RETRIES 500ULL
>
> -struct cppc_attr {
> -       struct attribute attr;
> -       ssize_t (*show)(struct kobject *kobj,
> -                       struct attribute *attr, char *buf);
> -       ssize_t (*store)(struct kobject *kobj,
> -                       struct attribute *attr, const char *c, ssize_t count);
> -};
> -
>  #define define_one_cppc_ro(_name)              \
> -static struct cppc_attr _name =                        \
> +static struct kobj_attribute _name =           \
>  __ATTR(_name, 0444, show_##_name, NULL)
>
>  #define to_cpc_desc(a) container_of(a, struct cpc_desc, kobj)
>
>  #define show_cppc_data(access_fn, struct_name, member_name)            \
>         static ssize_t show_##member_name(struct kobject *kobj,         \
> -                                       struct attribute *attr, char *buf) \
> +                               struct kobj_attribute *attr, char *buf) \
>         {                                                               \
>                 struct cpc_desc *cpc_ptr = to_cpc_desc(kobj);           \
>                 struct struct_name st_name = {0};                       \
> @@ -161,7 +153,7 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf);
>  show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
>
>  static ssize_t show_feedback_ctrs(struct kobject *kobj,
> -               struct attribute *attr, char *buf)
> +               struct kobj_attribute *attr, char *buf)
>  {
>         struct cpc_desc *cpc_ptr = to_cpc_desc(kobj);
>         struct cppc_perf_fb_ctrs fb_ctrs = {0};
>
> base-commit: 454859c552da78b0f587205d308401922b56863e
> --

Applied as 5.13 material, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-08 17:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 21:30 [PATCH] ACPI / CPPC: Replace cppc_attr with kobj_attribute Nathan Chancellor
2021-04-08 17:59 ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.