* [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch
@ 2021-04-15 0:11 Nathan Chancellor
2021-04-15 0:11 ` [PATCH 2/2] perf/amd/uncore: " Nathan Chancellor
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Nathan Chancellor @ 2021-04-15 0:11 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Sami Tolvanen, Kees Cook
Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Thomas Gleixner, Borislav Petkov, x86, linux-kernel,
clang-built-linux, Nathan Chancellor
dev_attr_show() calls _iommu_event_show() via an indirect call but
_iommu_event_show()'s type does not currently match the type of the
show() member in 'struct device_attribute', resulting in a Control Flow
Integrity violation.
$ cat /sys/devices/amd_iommu_1/events/mem_dte_hit
csource=0x0a
$ dmesg | grep "CFI failure"
[ 3526.735140] CFI failure (target: _iommu_event_show...):
Change _iommu_event_show() and 'struct amd_iommu_event_desc' to
'struct device_attribute' so that there is no more CFI violation.
Link: https://github.com/ClangBuiltLinux/linux/issues/1350
Fixes: 7be6296fdd75 ("perf/x86/amd: AMD IOMMU Performance Counter PERF uncore PMU implementation")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/x86/events/amd/iommu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/iommu.c b/arch/x86/events/amd/iommu.c
index be50ef8572cc..6a98a7651621 100644
--- a/arch/x86/events/amd/iommu.c
+++ b/arch/x86/events/amd/iommu.c
@@ -81,12 +81,12 @@ static struct attribute_group amd_iommu_events_group = {
};
struct amd_iommu_event_desc {
- struct kobj_attribute attr;
+ struct device_attribute attr;
const char *event;
};
-static ssize_t _iommu_event_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t _iommu_event_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
struct amd_iommu_event_desc *event =
container_of(attr, struct amd_iommu_event_desc, attr);
base-commit: d434405aaab7d0ebc516b68a8fc4100922d7f5ef
--
2.31.1.272.g89b43f80a5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] perf/amd/uncore: Fix sysfs type mismatch
2021-04-15 0:11 [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch Nathan Chancellor
@ 2021-04-15 0:11 ` Nathan Chancellor
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Nathan Chancellor
2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
2021-04-15 7:53 ` [PATCH 1/2] x86/events/amd/iommu: " Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 2 replies; 8+ messages in thread
From: Nathan Chancellor @ 2021-04-15 0:11 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Sami Tolvanen, Kees Cook
Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Thomas Gleixner, Borislav Petkov, x86, linux-kernel,
clang-built-linux, Nathan Chancellor
dev_attr_show() calls the __uncore_*_show() functions via an indirect
call but their type does not currently match the type of the show()
member in 'struct device_attribute', resulting in a Control Flow
Integrity violation.
$ cat /sys/devices/amd_l3/format/umask
config:8-15
$ dmesg | grep "CFI failure"
[ 1258.174653] CFI failure (target: __uncore_umask_show...):
Update the type in the DEFINE_UNCORE_FORMAT_ATTR macro to match
'struct device_attribute' so that there is no more CFI violation.
Link: https://github.com/ClangBuiltLinux/linux/issues/1350
Fixes: 06f2c24584f3 ("perf/amd/uncore: Prepare to scale for more attributes that vary per family")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/x86/events/amd/uncore.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
index 7f014d450bc2..582c0ffb5e98 100644
--- a/arch/x86/events/amd/uncore.c
+++ b/arch/x86/events/amd/uncore.c
@@ -275,14 +275,14 @@ static struct attribute_group amd_uncore_attr_group = {
};
#define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \
-static ssize_t __uncore_##_var##_show(struct kobject *kobj, \
- struct kobj_attribute *attr, \
+static ssize_t __uncore_##_var##_show(struct device *dev, \
+ struct device_attribute *attr, \
char *page) \
{ \
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
return sprintf(page, _format "\n"); \
} \
-static struct kobj_attribute format_attr_##_var = \
+static struct device_attribute format_attr_##_var = \
__ATTR(_name, 0444, __uncore_##_var##_show, NULL)
DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");
--
2.31.1.272.g89b43f80a5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch
2021-04-15 0:11 [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch Nathan Chancellor
2021-04-15 0:11 ` [PATCH 2/2] perf/amd/uncore: " Nathan Chancellor
@ 2021-04-15 7:53 ` Christoph Hellwig
2021-04-15 14:47 ` Nathan Chancellor
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Nathan Chancellor
2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-04-15 7:53 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Sami Tolvanen, Kees Cook, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Thomas Gleixner, Borislav Petkov, x86,
linux-kernel, clang-built-linux
On Wed, Apr 14, 2021 at 05:11:11PM -0700, Nathan Chancellor wrote:
> dev_attr_show() calls _iommu_event_show() via an indirect call but
> _iommu_event_show()'s type does not currently match the type of the
> show() member in 'struct device_attribute', resulting in a Control Flow
> Integrity violation.
While the fix looks fine I think we need to solve this kind of problem
by better type checking. The fact that we can use the wong type here
without a compiler warning is the real issue.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch
2021-04-15 7:53 ` [PATCH 1/2] x86/events/amd/iommu: " Christoph Hellwig
@ 2021-04-15 14:47 ` Nathan Chancellor
0 siblings, 0 replies; 8+ messages in thread
From: Nathan Chancellor @ 2021-04-15 14:47 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Sami Tolvanen, Kees Cook, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Thomas Gleixner, Borislav Petkov, x86,
linux-kernel, clang-built-linux
On Thu, Apr 15, 2021 at 08:53:35AM +0100, Christoph Hellwig wrote:
> On Wed, Apr 14, 2021 at 05:11:11PM -0700, Nathan Chancellor wrote:
> > dev_attr_show() calls _iommu_event_show() via an indirect call but
> > _iommu_event_show()'s type does not currently match the type of the
> > show() member in 'struct device_attribute', resulting in a Control Flow
> > Integrity violation.
>
> While the fix looks fine I think we need to solve this kind of problem
> by better type checking. The fact that we can use the wong type here
> without a compiler warning is the real issue.
I agree. Unfortunately, it seems that is going to be a much longer tail
project because of how pervasive this is (using container_of() +
attributes to get callbacks).
https://lore.kernel.org/r/202006112217.2E6CE093@keescook/
https://lore.kernel.org/r/202104021823.64FA6119@keescook/
Cheers,
Nathan
^ permalink raw reply [flat|nested] 8+ messages in thread
* [tip: perf/core] perf/amd/uncore: Fix sysfs type mismatch
2021-04-15 0:11 ` [PATCH 2/2] perf/amd/uncore: " Nathan Chancellor
@ 2021-04-16 15:01 ` tip-bot2 for Nathan Chancellor
2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
1 sibling, 0 replies; 8+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2021-04-16 15:01 UTC (permalink / raw)
To: linux-tip-commits
Cc: Nathan Chancellor, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: b04c0cddff6d1d6656c7f7c08c0b8f07eb287564
Gitweb: https://git.kernel.org/tip/b04c0cddff6d1d6656c7f7c08c0b8f07eb287564
Author: Nathan Chancellor <nathan@kernel.org>
AuthorDate: Wed, 14 Apr 2021 17:11:12 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 16 Apr 2021 16:32:44 +02:00
perf/amd/uncore: Fix sysfs type mismatch
dev_attr_show() calls the __uncore_*_show() functions via an indirect
call but their type does not currently match the type of the show()
member in 'struct device_attribute', resulting in a Control Flow
Integrity violation.
$ cat /sys/devices/amd_l3/format/umask
config:8-15
$ dmesg | grep "CFI failure"
[ 1258.174653] CFI failure (target: __uncore_umask_show...):
Update the type in the DEFINE_UNCORE_FORMAT_ATTR macro to match
'struct device_attribute' so that there is no more CFI violation.
Fixes: 06f2c24584f3 ("perf/amd/uncore: Prepare to scale for more attributes that vary per family")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210415001112.3024673-2-nathan@kernel.org
---
arch/x86/events/amd/uncore.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
index 7f014d4..582c0ff 100644
--- a/arch/x86/events/amd/uncore.c
+++ b/arch/x86/events/amd/uncore.c
@@ -275,14 +275,14 @@ static struct attribute_group amd_uncore_attr_group = {
};
#define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \
-static ssize_t __uncore_##_var##_show(struct kobject *kobj, \
- struct kobj_attribute *attr, \
+static ssize_t __uncore_##_var##_show(struct device *dev, \
+ struct device_attribute *attr, \
char *page) \
{ \
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
return sprintf(page, _format "\n"); \
} \
-static struct kobj_attribute format_attr_##_var = \
+static struct device_attribute format_attr_##_var = \
__ATTR(_name, 0444, __uncore_##_var##_show, NULL)
DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip: perf/core] x86/events/amd/iommu: Fix sysfs type mismatch
2021-04-15 0:11 [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch Nathan Chancellor
2021-04-15 0:11 ` [PATCH 2/2] perf/amd/uncore: " Nathan Chancellor
2021-04-15 7:53 ` [PATCH 1/2] x86/events/amd/iommu: " Christoph Hellwig
@ 2021-04-16 15:01 ` tip-bot2 for Nathan Chancellor
2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
3 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2021-04-16 15:01 UTC (permalink / raw)
To: linux-tip-commits
Cc: Nathan Chancellor, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: bccae9d7b013bd708ece414f74defaee56790e1d
Gitweb: https://git.kernel.org/tip/bccae9d7b013bd708ece414f74defaee56790e1d
Author: Nathan Chancellor <nathan@kernel.org>
AuthorDate: Wed, 14 Apr 2021 17:11:11 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 16 Apr 2021 16:32:44 +02:00
x86/events/amd/iommu: Fix sysfs type mismatch
dev_attr_show() calls _iommu_event_show() via an indirect call but
_iommu_event_show()'s type does not currently match the type of the
show() member in 'struct device_attribute', resulting in a Control Flow
Integrity violation.
$ cat /sys/devices/amd_iommu_1/events/mem_dte_hit
csource=0x0a
$ dmesg | grep "CFI failure"
[ 3526.735140] CFI failure (target: _iommu_event_show...):
Change _iommu_event_show() and 'struct amd_iommu_event_desc' to
'struct device_attribute' so that there is no more CFI violation.
Fixes: 7be6296fdd75 ("perf/x86/amd: AMD IOMMU Performance Counter PERF uncore PMU implementation")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210415001112.3024673-1-nathan@kernel.org
---
arch/x86/events/amd/iommu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/iommu.c b/arch/x86/events/amd/iommu.c
index be50ef8..6a98a76 100644
--- a/arch/x86/events/amd/iommu.c
+++ b/arch/x86/events/amd/iommu.c
@@ -81,12 +81,12 @@ static struct attribute_group amd_iommu_events_group = {
};
struct amd_iommu_event_desc {
- struct kobj_attribute attr;
+ struct device_attribute attr;
const char *event;
};
-static ssize_t _iommu_event_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t _iommu_event_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
struct amd_iommu_event_desc *event =
container_of(attr, struct amd_iommu_event_desc, attr);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip: perf/core] perf/amd/uncore: Fix sysfs type mismatch
2021-04-15 0:11 ` [PATCH 2/2] perf/amd/uncore: " Nathan Chancellor
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Nathan Chancellor
@ 2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
1 sibling, 0 replies; 8+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2021-04-16 17:13 UTC (permalink / raw)
To: linux-tip-commits
Cc: Nathan Chancellor, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 5deac80d4571dffb51f452f0027979d72259a1b9
Gitweb: https://git.kernel.org/tip/5deac80d4571dffb51f452f0027979d72259a1b9
Author: Nathan Chancellor <nathan@kernel.org>
AuthorDate: Wed, 14 Apr 2021 17:11:12 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 16 Apr 2021 18:58:52 +02:00
perf/amd/uncore: Fix sysfs type mismatch
dev_attr_show() calls the __uncore_*_show() functions via an indirect
call but their type does not currently match the type of the show()
member in 'struct device_attribute', resulting in a Control Flow
Integrity violation.
$ cat /sys/devices/amd_l3/format/umask
config:8-15
$ dmesg | grep "CFI failure"
[ 1258.174653] CFI failure (target: __uncore_umask_show...):
Update the type in the DEFINE_UNCORE_FORMAT_ATTR macro to match
'struct device_attribute' so that there is no more CFI violation.
Fixes: 06f2c24584f3 ("perf/amd/uncore: Prepare to scale for more attributes that vary per family")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210415001112.3024673-2-nathan@kernel.org
---
arch/x86/events/amd/uncore.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
index 7f014d4..582c0ff 100644
--- a/arch/x86/events/amd/uncore.c
+++ b/arch/x86/events/amd/uncore.c
@@ -275,14 +275,14 @@ static struct attribute_group amd_uncore_attr_group = {
};
#define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \
-static ssize_t __uncore_##_var##_show(struct kobject *kobj, \
- struct kobj_attribute *attr, \
+static ssize_t __uncore_##_var##_show(struct device *dev, \
+ struct device_attribute *attr, \
char *page) \
{ \
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
return sprintf(page, _format "\n"); \
} \
-static struct kobj_attribute format_attr_##_var = \
+static struct device_attribute format_attr_##_var = \
__ATTR(_name, 0444, __uncore_##_var##_show, NULL)
DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35");
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip: perf/core] x86/events/amd/iommu: Fix sysfs type mismatch
2021-04-15 0:11 [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch Nathan Chancellor
` (2 preceding siblings ...)
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Nathan Chancellor
@ 2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
3 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2021-04-16 17:13 UTC (permalink / raw)
To: linux-tip-commits
Cc: Nathan Chancellor, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: de5bc7b425d4c27ae5faa00ea7eb6b9780b9a355
Gitweb: https://git.kernel.org/tip/de5bc7b425d4c27ae5faa00ea7eb6b9780b9a355
Author: Nathan Chancellor <nathan@kernel.org>
AuthorDate: Wed, 14 Apr 2021 17:11:11 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 16 Apr 2021 18:58:52 +02:00
x86/events/amd/iommu: Fix sysfs type mismatch
dev_attr_show() calls _iommu_event_show() via an indirect call but
_iommu_event_show()'s type does not currently match the type of the
show() member in 'struct device_attribute', resulting in a Control Flow
Integrity violation.
$ cat /sys/devices/amd_iommu_1/events/mem_dte_hit
csource=0x0a
$ dmesg | grep "CFI failure"
[ 3526.735140] CFI failure (target: _iommu_event_show...):
Change _iommu_event_show() and 'struct amd_iommu_event_desc' to
'struct device_attribute' so that there is no more CFI violation.
Fixes: 7be6296fdd75 ("perf/x86/amd: AMD IOMMU Performance Counter PERF uncore PMU implementation")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210415001112.3024673-1-nathan@kernel.org
---
arch/x86/events/amd/iommu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/iommu.c b/arch/x86/events/amd/iommu.c
index be50ef8..6a98a76 100644
--- a/arch/x86/events/amd/iommu.c
+++ b/arch/x86/events/amd/iommu.c
@@ -81,12 +81,12 @@ static struct attribute_group amd_iommu_events_group = {
};
struct amd_iommu_event_desc {
- struct kobj_attribute attr;
+ struct device_attribute attr;
const char *event;
};
-static ssize_t _iommu_event_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t _iommu_event_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
struct amd_iommu_event_desc *event =
container_of(attr, struct amd_iommu_event_desc, attr);
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-04-16 17:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-15 0:11 [PATCH 1/2] x86/events/amd/iommu: Fix sysfs type mismatch Nathan Chancellor
2021-04-15 0:11 ` [PATCH 2/2] perf/amd/uncore: " Nathan Chancellor
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Nathan Chancellor
2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
2021-04-15 7:53 ` [PATCH 1/2] x86/events/amd/iommu: " Christoph Hellwig
2021-04-15 14:47 ` Nathan Chancellor
2021-04-16 15:01 ` [tip: perf/core] " tip-bot2 for Nathan Chancellor
2021-04-16 17:13 ` tip-bot2 for Nathan Chancellor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).