From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>,
Douglas RAILLARD <douglas.raillard@arm.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Sasha Levin <sashal@kernel.org>,
vschneid@redhat.com, linux-trace-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 15/17] tracing: Error if a trace event has an array for a __field()
Date: Wed, 12 Apr 2023 22:36:43 -0400 [thread overview]
Message-ID: <20230413023647.74661-15-sashal@kernel.org> (raw)
In-Reply-To: <20230413023647.74661-1-sashal@kernel.org>
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
[ Upstream commit f82e7ca019dfad3b006fd3b772f7ac569672db55 ]
A __field() in the TRACE_EVENT() macro is used to set up the fields of the
trace event data. It is for single storage units (word, char, int,
pointer, etc) and not for complex structures or arrays. Unfortunately,
there's nothing preventing the build from accepting:
__field(int, arr[5]);
from building. It will turn into a array value. This use to work fine, as
the offset and size use to be determined by the macro using the field name,
but things have changed and the offset and size are now determined by the
type. So the above would only be size 4, and the next field will be
located 4 bytes from it (instead of 20).
The proper way to declare static arrays is to use the __array() macro.
Instead of __field(int, arr[5]) it should be __array(int, arr, 5).
Add some macro tricks to the building of a trace event from the
TRACE_EVENT() macro such that __field(int, arr[5]) will fail to build. A
comment by the failure will explain why the build failed.
Link: https://lore.kernel.org/lkml/20230306122549.236561-1-douglas.raillard@arm.com/
Link: https://lore.kernel.org/linux-trace-kernel/20230309221302.642e82d9@gandalf.local.home
Reported-by: Douglas RAILLARD <douglas.raillard@arm.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/trace/stages/stage5_get_offsets.h | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/include/trace/stages/stage5_get_offsets.h b/include/trace/stages/stage5_get_offsets.h
index fba4c24ed9e60..def36fbb8c5cd 100644
--- a/include/trace/stages/stage5_get_offsets.h
+++ b/include/trace/stages/stage5_get_offsets.h
@@ -9,17 +9,30 @@
#undef __entry
#define __entry entry
+/*
+ * Fields should never declare an array: i.e. __field(int, arr[5])
+ * If they do, it will cause issues in parsing and possibly corrupt the
+ * events. To prevent that from happening, test the sizeof() a fictitious
+ * type called "struct _test_no_array_##item" which will fail if "item"
+ * contains array elements (like "arr[5]").
+ *
+ * If you hit this, use __array(int, arr, 5) instead.
+ */
#undef __field
-#define __field(type, item)
+#define __field(type, item) \
+ { (void)sizeof(struct _test_no_array_##item *); }
#undef __field_ext
-#define __field_ext(type, item, filter_type)
+#define __field_ext(type, item, filter_type) \
+ { (void)sizeof(struct _test_no_array_##item *); }
#undef __field_struct
-#define __field_struct(type, item)
+#define __field_struct(type, item) \
+ { (void)sizeof(struct _test_no_array_##item *); }
#undef __field_struct_ext
-#define __field_struct_ext(type, item, filter_type)
+#define __field_struct_ext(type, item, filter_type) \
+ { (void)sizeof(struct _test_no_array_##item *); }
#undef __array
#define __array(type, item, len)
--
2.39.2
next prev parent reply other threads:[~2023-04-13 2:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 2:36 [PATCH AUTOSEL 6.1 01/17] ASOC: Intel: sof_sdw: add quirk for Intel 'Rooks County' NUC M15 Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 02/17] ASoC: Intel: soc-acpi: add table " Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 03/17] ASoC: soc-pcm: fix hw->formats cleared by soc_pcm_hw_init() for dpcm Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 04/17] x86/hyperv: Block root partition functionality in a Confidential VM Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 05/17] ASoC: amd: yc: Add DMI entries to support Victus by HP Laptop 16-e1xxx (8A22) Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 06/17] iio: adc: palmas_gpadc: fix NULL dereference on rmmod Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 07/17] ASoC: Intel: bytcr_rt5640: Add quirk for the Acer Iconia One 7 B1-750 Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 08/17] ASoC: da7213.c: add missing pm_runtime_disable() Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 09/17] net: wwan: t7xx: do not compile with -Werror Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 10/17] selftests mount: Fix mount_setattr_test builds failed Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 11/17] scsi: mpi3mr: Handle soft reset in progress fault code (0xF002) Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 12/17] net: sfp: add quirk enabling 2500Base-x for HG MXPD-483II Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 13/17] platform/x86: thinkpad_acpi: Add missing T14s Gen1 type to s2idle quirk list Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 14/17] wifi: ath11k: reduce the MHI timeout to 20s Sasha Levin
2023-04-13 2:36 ` Sasha Levin [this message]
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 16/17] asm-generic/io.h: suppress endianness warnings for readq() and writeq() Sasha Levin
2023-04-13 2:36 ` [PATCH AUTOSEL 6.1 17/17] x86/cpu: Add model number for Intel Arrow Lake processor Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230413023647.74661-15-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=douglas.raillard@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox