Skip to content

Commit 3e10b80

Browse files
committed
Merge: ftrace: backports fixes from stable
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/786 JIRA: https://issues.redhat.com/browse/RHEL-86682 JIRA: https://issues.redhat.com/browse/RHEL-81450 CVE: CVE-2025-21777 CVE: CVE-2025-21733 Backport stable fixes from linux v6.12.21. Omitted-fix: 0708908 The commit afd2627 ("tracing: Check "%s" dereference via the field and not the TP_printk format") merely exposes potential UAF vulnerabilities in the drm/xe code, it doesn't introduce them. Signed-off-by: Jerome Marchand <jmarchan@redhat.com> Approved-by: Joe Lawrence <joe.lawrence@redhat.com> Approved-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com> Merged-by: Julio Faracco <jfaracco@redhat.com>
2 parents 3f10b14 + 75f5307 commit 3e10b80

File tree

25 files changed

+757
-580
lines changed

25 files changed

+757
-580
lines changed

arch/mips/kernel/ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ int ftrace_disable_ftrace_graph_caller(void)
248248
#define S_R_SP (0xafb0 << 16) /* s{d,w} R, offset(sp) */
249249
#define OFFSET_MASK 0xffff /* stack offset range: 0 ~ PT_SIZE */
250250

251-
unsigned long ftrace_get_parent_ra_addr(unsigned long self_ra, unsigned long
251+
static unsigned long ftrace_get_parent_ra_addr(unsigned long self_ra, unsigned long
252252
old_parent_ra, unsigned long parent_ra_addr, unsigned long fp)
253253
{
254254
unsigned long sp, ip, tmp;

arch/parisc/kernel/ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int ftrace_enable_ftrace_graph_caller(void)
8787

8888
int ftrace_disable_ftrace_graph_caller(void)
8989
{
90-
static_key_enable(&ftrace_graph_enable.key);
90+
static_key_disable(&ftrace_graph_enable.key);
9191
return 0;
9292
}
9393
#endif

include/linux/trace_events.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ struct trace_event_fields {
273273
const char *name;
274274
const int size;
275275
const int align;
276-
const int is_signed;
276+
const unsigned int is_signed:1;
277+
unsigned int needs_test:1;
277278
const int filter_type;
278279
const int len;
279280
};
@@ -325,6 +326,7 @@ enum {
325326
TRACE_EVENT_FL_EPROBE_BIT,
326327
TRACE_EVENT_FL_FPROBE_BIT,
327328
TRACE_EVENT_FL_CUSTOM_BIT,
329+
TRACE_EVENT_FL_TEST_STR_BIT,
328330
};
329331

330332
/*
@@ -342,6 +344,7 @@ enum {
342344
* CUSTOM - Event is a custom event (to be attached to an exsiting tracepoint)
343345
* This is set when the custom event has not been attached
344346
* to a tracepoint yet, then it is cleared when it is.
347+
* TEST_STR - The event has a "%s" that points to a string outside the event
345348
*/
346349
enum {
347350
TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
@@ -355,6 +358,7 @@ enum {
355358
TRACE_EVENT_FL_EPROBE = (1 << TRACE_EVENT_FL_EPROBE_BIT),
356359
TRACE_EVENT_FL_FPROBE = (1 << TRACE_EVENT_FL_FPROBE_BIT),
357360
TRACE_EVENT_FL_CUSTOM = (1 << TRACE_EVENT_FL_CUSTOM_BIT),
361+
TRACE_EVENT_FL_TEST_STR = (1 << TRACE_EVENT_FL_TEST_STR_BIT),
358362
};
359363

360364
#define TRACE_EVENT_FL_UKPROBE (TRACE_EVENT_FL_KPROBE | TRACE_EVENT_FL_UPROBE)
@@ -363,7 +367,7 @@ struct trace_event_call {
363367
struct list_head list;
364368
struct trace_event_class *class;
365369
union {
366-
char *name;
370+
const char *name;
367371
/* Set TRACE_EVENT_FL_TRACEPOINT flag when using "tp" */
368372
struct tracepoint *tp;
369373
};

include/trace/events/mmflags.h

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,78 @@
1313
* Thus most bits set go first.
1414
*/
1515

16+
/* These define the values that are enums (the bits) */
17+
#define TRACE_GFP_FLAGS_GENERAL \
18+
TRACE_GFP_EM(DMA) \
19+
TRACE_GFP_EM(HIGHMEM) \
20+
TRACE_GFP_EM(DMA32) \
21+
TRACE_GFP_EM(MOVABLE) \
22+
TRACE_GFP_EM(RECLAIMABLE) \
23+
TRACE_GFP_EM(HIGH) \
24+
TRACE_GFP_EM(IO) \
25+
TRACE_GFP_EM(FS) \
26+
TRACE_GFP_EM(ZERO) \
27+
TRACE_GFP_EM(DIRECT_RECLAIM) \
28+
TRACE_GFP_EM(KSWAPD_RECLAIM) \
29+
TRACE_GFP_EM(WRITE) \
30+
TRACE_GFP_EM(NOWARN) \
31+
TRACE_GFP_EM(RETRY_MAYFAIL) \
32+
TRACE_GFP_EM(NOFAIL) \
33+
TRACE_GFP_EM(NORETRY) \
34+
TRACE_GFP_EM(MEMALLOC) \
35+
TRACE_GFP_EM(COMP) \
36+
TRACE_GFP_EM(NOMEMALLOC) \
37+
TRACE_GFP_EM(HARDWALL) \
38+
TRACE_GFP_EM(THISNODE) \
39+
TRACE_GFP_EM(ACCOUNT) \
40+
TRACE_GFP_EM(ZEROTAGS)
41+
42+
#ifdef CONFIG_KASAN_HW_TAGS
43+
# define TRACE_GFP_FLAGS_KASAN \
44+
TRACE_GFP_EM(SKIP_ZERO) \
45+
TRACE_GFP_EM(SKIP_KASAN)
46+
#else
47+
# define TRACE_GFP_FLAGS_KASAN
48+
#endif
49+
50+
#ifdef CONFIG_LOCKDEP
51+
# define TRACE_GFP_FLAGS_LOCKDEP \
52+
TRACE_GFP_EM(NOLOCKDEP)
53+
#else
54+
# define TRACE_GFP_FLAGS_LOCKDEP
55+
#endif
56+
57+
#ifdef CONFIG_SLAB_OBJ_EXT
58+
# define TRACE_GFP_FLAGS_SLAB \
59+
TRACE_GFP_EM(NO_OBJ_EXT)
60+
#else
61+
# define TRACE_GFP_FLAGS_SLAB
62+
#endif
63+
64+
#define TRACE_GFP_FLAGS \
65+
TRACE_GFP_FLAGS_GENERAL \
66+
TRACE_GFP_FLAGS_KASAN \
67+
TRACE_GFP_FLAGS_LOCKDEP \
68+
TRACE_GFP_FLAGS_SLAB
69+
70+
#undef TRACE_GFP_EM
71+
#define TRACE_GFP_EM(a) TRACE_DEFINE_ENUM(___GFP_##a##_BIT);
72+
73+
TRACE_GFP_FLAGS
74+
75+
/* Just in case these are ever used */
76+
TRACE_DEFINE_ENUM(___GFP_UNUSED_BIT);
77+
TRACE_DEFINE_ENUM(___GFP_LAST_BIT);
78+
1679
#define gfpflag_string(flag) {(__force unsigned long)flag, #flag}
1780

81+
/*
82+
* For the values that match the bits, use the TRACE_GFP_FLAGS
83+
* which will allow any updates to be included automatically.
84+
*/
85+
#undef TRACE_GFP_EM
86+
#define TRACE_GFP_EM(a) gfpflag_string(__GFP_##a),
87+
1888
#define __def_gfpflag_names \
1989
gfpflag_string(GFP_TRANSHUGE), \
2090
gfpflag_string(GFP_TRANSHUGE_LIGHT), \
@@ -28,41 +98,13 @@
2898
gfpflag_string(GFP_NOIO), \
2999
gfpflag_string(GFP_NOWAIT), \
30100
gfpflag_string(GFP_DMA), \
31-
gfpflag_string(__GFP_HIGHMEM), \
32101
gfpflag_string(GFP_DMA32), \
33-
gfpflag_string(__GFP_HIGH), \
34-
gfpflag_string(__GFP_IO), \
35-
gfpflag_string(__GFP_FS), \
36-
gfpflag_string(__GFP_NOWARN), \
37-
gfpflag_string(__GFP_RETRY_MAYFAIL), \
38-
gfpflag_string(__GFP_NOFAIL), \
39-
gfpflag_string(__GFP_NORETRY), \
40-
gfpflag_string(__GFP_COMP), \
41-
gfpflag_string(__GFP_ZERO), \
42-
gfpflag_string(__GFP_NOMEMALLOC), \
43-
gfpflag_string(__GFP_MEMALLOC), \
44-
gfpflag_string(__GFP_HARDWALL), \
45-
gfpflag_string(__GFP_THISNODE), \
46-
gfpflag_string(__GFP_RECLAIMABLE), \
47-
gfpflag_string(__GFP_MOVABLE), \
48-
gfpflag_string(__GFP_ACCOUNT), \
49-
gfpflag_string(__GFP_WRITE), \
50102
gfpflag_string(__GFP_RECLAIM), \
51-
gfpflag_string(__GFP_DIRECT_RECLAIM), \
52-
gfpflag_string(__GFP_KSWAPD_RECLAIM), \
53-
gfpflag_string(__GFP_ZEROTAGS)
54-
55-
#ifdef CONFIG_KASAN_HW_TAGS
56-
#define __def_gfpflag_names_kasan , \
57-
gfpflag_string(__GFP_SKIP_ZERO), \
58-
gfpflag_string(__GFP_SKIP_KASAN)
59-
#else
60-
#define __def_gfpflag_names_kasan
61-
#endif
103+
TRACE_GFP_FLAGS \
104+
{ 0, NULL }
62105

63106
#define show_gfp_flags(flags) \
64-
(flags) ? __print_flags(flags, "|", \
65-
__def_gfpflag_names __def_gfpflag_names_kasan \
107+
(flags) ? __print_flags(flags, "|", __def_gfpflag_names \
66108
) : "none"
67109

68110
#ifdef CONFIG_MMU

include/trace/trace_events.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ static struct trace_event_fields trace_event_fields_##call[] = { \
244244
tstruct \
245245
{} };
246246

247+
#undef DECLARE_EVENT_SYSCALL_CLASS
248+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
249+
247250
#undef DEFINE_EVENT_PRINT
248251
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
249252

@@ -374,11 +377,11 @@ static inline notrace int trace_event_get_offsets_##call( \
374377

375378
#include "stages/stage6_event_callback.h"
376379

377-
#undef DECLARE_EVENT_CLASS
378-
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
379-
\
380+
381+
#undef __DECLARE_EVENT_CLASS
382+
#define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
380383
static notrace void \
381-
trace_event_raw_event_##call(void *__data, proto) \
384+
do_trace_event_raw_event_##call(void *__data, proto) \
382385
{ \
383386
struct trace_event_file *trace_file = __data; \
384387
struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
@@ -403,6 +406,29 @@ trace_event_raw_event_##call(void *__data, proto) \
403406
\
404407
trace_event_buffer_commit(&fbuffer); \
405408
}
409+
410+
#undef DECLARE_EVENT_CLASS
411+
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
412+
__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
413+
PARAMS(assign), PARAMS(print)) \
414+
static notrace void \
415+
trace_event_raw_event_##call(void *__data, proto) \
416+
{ \
417+
do_trace_event_raw_event_##call(__data, args); \
418+
}
419+
420+
#undef DECLARE_EVENT_SYSCALL_CLASS
421+
#define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, print) \
422+
__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
423+
PARAMS(assign), PARAMS(print)) \
424+
static notrace void \
425+
trace_event_raw_event_##call(void *__data, proto) \
426+
{ \
427+
preempt_disable_notrace(); \
428+
do_trace_event_raw_event_##call(__data, args); \
429+
preempt_enable_notrace(); \
430+
}
431+
406432
/*
407433
* The ftrace_test_probe is compiled out, it is only here as a build time check
408434
* to make sure that if the tracepoint handling changes, the ftrace probe will
@@ -418,6 +444,8 @@ static inline void ftrace_test_probe_##call(void) \
418444

419445
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
420446

447+
#undef __DECLARE_EVENT_CLASS
448+
421449
#include "stages/stage7_class_define.h"
422450

423451
#undef DECLARE_EVENT_CLASS

kernel/trace/fgraph.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs
802802
#endif
803803
{
804804
for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) {
805-
struct fgraph_ops *gops = fgraph_array[i];
805+
struct fgraph_ops *gops = READ_ONCE(fgraph_array[i]);
806806

807807
if (gops == &fgraph_stub)
808808
continue;
@@ -1160,14 +1160,20 @@ void fgraph_update_pid_func(void)
11601160
static int start_graph_tracing(void)
11611161
{
11621162
unsigned long **ret_stack_list;
1163-
int ret;
1163+
int ret, cpu;
11641164

11651165
ret_stack_list = kcalloc(FTRACE_RETSTACK_ALLOC_SIZE,
11661166
sizeof(*ret_stack_list), GFP_KERNEL);
11671167

11681168
if (!ret_stack_list)
11691169
return -ENOMEM;
11701170

1171+
/* The cpu_boot init_task->ret_stack will never be freed */
1172+
for_each_online_cpu(cpu) {
1173+
if (!idle_task(cpu)->ret_stack)
1174+
ftrace_graph_init_idle_task(idle_task(cpu), cpu);
1175+
}
1176+
11711177
do {
11721178
ret = alloc_retstack_tasklist(ret_stack_list);
11731179
} while (ret == -EAGAIN);

0 commit comments

Comments
 (0)