From 5772deecca0646b5d5b03af516198041c8038fa2 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Aug 2022 13:09:28 +0200 Subject: [PATCH] 5.10-stable patches added patches: tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch --- queue-5.10/series | 2 + ...-mismatch-for-debug_section_mismatch.patch | 42 +++++++++++ ...etermine-trace-event-field-alignment.patch | 74 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 queue-5.10/tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch create mode 100644 queue-5.10/tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch diff --git a/queue-5.10/series b/queue-5.10/series index 139d8ad7489..c3f69209f74 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -518,3 +518,5 @@ xen-blkback-fix-persistent-grants-negotiation.patch xen-blkback-apply-feature_persistent-parameter-when-connect.patch xen-blkfront-apply-feature_persistent-parameter-when-connect.patch keys-asymmetric-enforce-sm2-signature-use-pkey-algo.patch +tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch +tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch diff --git a/queue-5.10/tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch b/queue-5.10/tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch new file mode 100644 index 00000000000..31b186f7799 --- /dev/null +++ b/queue-5.10/tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch @@ -0,0 +1,42 @@ +From bed4593645366ad7362a3aa7bc0d100d8d8236a8 Mon Sep 17 00:00:00 2001 +From: Huacai Chen +Date: Mon, 11 Jul 2022 09:17:38 +0800 +Subject: tpm: eventlog: Fix section mismatch for DEBUG_SECTION_MISMATCH + +From: Huacai Chen + +commit bed4593645366ad7362a3aa7bc0d100d8d8236a8 upstream. + +If DEBUG_SECTION_MISMATCH enabled, __calc_tpm2_event_size() will not be +inlined, this cause section mismatch like this: + +WARNING: modpost: vmlinux.o(.text.unlikely+0xe30c): Section mismatch in reference from the variable L0 to the function .init.text:early_ioremap() +The function L0() references +the function __init early_memremap(). +This is often because L0 lacks a __init +annotation or the annotation of early_ioremap is wrong. + +Fix it by using __always_inline instead of inline for the called-once +function __calc_tpm2_event_size(). + +Fixes: 44038bc514a2 ("tpm: Abstract crypto agile event size calculations") +Cc: stable@vger.kernel.org # v5.3 +Reported-by: WANG Xuerui +Signed-off-by: Huacai Chen +Signed-off-by: Jarkko Sakkinen +Signed-off-by: Greg Kroah-Hartman +--- + include/linux/tpm_eventlog.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/include/linux/tpm_eventlog.h ++++ b/include/linux/tpm_eventlog.h +@@ -157,7 +157,7 @@ struct tcg_algorithm_info { + * Return: size of the event on success, 0 on failure + */ + +-static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, ++static __always_inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, + struct tcg_pcr_event *event_header, + bool do_mapping) + { diff --git a/queue-5.10/tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch b/queue-5.10/tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch new file mode 100644 index 00000000000..526ccba65a5 --- /dev/null +++ b/queue-5.10/tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch @@ -0,0 +1,74 @@ +From 4c3d2f9388d36eb28640a220a6f908328442d873 Mon Sep 17 00:00:00 2001 +From: "Steven Rostedt (Google)" +Date: Sun, 31 Jul 2022 01:59:28 -0400 +Subject: tracing: Use a struct alignof to determine trace event field alignment + +From: Steven Rostedt (Google) + +commit 4c3d2f9388d36eb28640a220a6f908328442d873 upstream. + +alignof() gives an alignment of types as they would be as standalone +variables. But alignment in structures might be different, and when +building the fields of events, the alignment must be the actual +alignment otherwise the field offsets may not match what they actually +are. + +This caused trace-cmd to crash, as libtraceevent did not check if the +field offset was bigger than the event. The write_msr and read_msr +events on 32 bit had their fields incorrect, because it had a u64 field +between two ints. alignof(u64) would give 8, but the u64 field was at a +4 byte alignment. + +Define a macro as: + + ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b))) + +which gives the actual alignment of types in a structure. + +Link: https://lkml.kernel.org/r/20220731015928.7ab3a154@rorschach.local.home + +Cc: Ingo Molnar +Cc: Andrew Morton +Cc: Peter Zijlstra +Cc: Thomas Gleixner +Cc: Masami Hiramatsu +Cc: stable@vger.kernel.org +Fixes: 04ae87a52074e ("ftrace: Rework event_create_dir()") +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Greg Kroah-Hartman +--- + include/trace/trace_events.h | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +--- a/include/trace/trace_events.h ++++ b/include/trace/trace_events.h +@@ -400,16 +400,18 @@ static struct trace_event_functions trac + + #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + ++#define ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b))) ++ + #undef __field_ext + #define __field_ext(_type, _item, _filter_type) { \ + .type = #_type, .name = #_item, \ +- .size = sizeof(_type), .align = __alignof__(_type), \ ++ .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ + .is_signed = is_signed_type(_type), .filter_type = _filter_type }, + + #undef __field_struct_ext + #define __field_struct_ext(_type, _item, _filter_type) { \ + .type = #_type, .name = #_item, \ +- .size = sizeof(_type), .align = __alignof__(_type), \ ++ .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ + 0, .filter_type = _filter_type }, + + #undef __field +@@ -421,7 +423,7 @@ static struct trace_event_functions trac + #undef __array + #define __array(_type, _item, _len) { \ + .type = #_type"["__stringify(_len)"]", .name = #_item, \ +- .size = sizeof(_type[_len]), .align = __alignof__(_type), \ ++ .size = sizeof(_type[_len]), .align = ALIGN_STRUCTFIELD(_type), \ + .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, + + #undef __dynamic_array -- 2.47.3