License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-03-06 02:35:29 +00:00
|
|
|
/*
|
|
|
|
* trace_export.c - export basic ftrace utilities to user space
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
|
|
|
|
*/
|
|
|
|
#include <linux/stringify.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/ftrace.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include "trace_output.h"
|
|
|
|
|
2018-05-09 18:17:48 +00:00
|
|
|
/* Stub function for events with triggers */
|
|
|
|
static int ftrace_event_register(struct trace_event_call *call,
|
|
|
|
enum trace_reg type, void *data)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef TRACE_SYSTEM
|
|
|
|
#define TRACE_SYSTEM ftrace
|
tracing: new format for specialized trace points
Impact: clean up and enhancement
The TRACE_EVENT_FORMAT macro looks quite ugly and is limited in its
ability to save data as well as to print the record out. Working with
Ingo Molnar, we came up with a new format that is much more pleasing to
the eye of C developers. This new macro is more C style than the old
macro, and is more obvious to what it does.
Here's the example. The only updated macro in this patch is the
sched_switch trace point.
The old method looked like this:
TRACE_EVENT_FORMAT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_FMT("task %s:%d ==> %s:%d",
prev->comm, prev->pid, next->comm, next->pid),
TRACE_STRUCT(
TRACE_FIELD(pid_t, prev_pid, prev->pid)
TRACE_FIELD(int, prev_prio, prev->prio)
TRACE_FIELD_SPECIAL(char next_comm[TASK_COMM_LEN],
next_comm,
TP_CMD(memcpy(TRACE_ENTRY->next_comm,
next->comm,
TASK_COMM_LEN)))
TRACE_FIELD(pid_t, next_pid, next->pid)
TRACE_FIELD(int, next_prio, next->prio)
),
TP_RAW_FMT("prev %d:%d ==> next %s:%d:%d")
);
The above method is hard to read and requires two format fields.
The new method:
/*
* Tracepoint for task switches, performed by the scheduler:
*
* (NOTE: the 'rq' argument is not used by generic trace events,
* but used by the latency tracer plugin. )
*/
TRACE_EVENT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_STRUCT__entry(
__array( char, prev_comm, TASK_COMM_LEN )
__field( pid_t, prev_pid )
__field( int, prev_prio )
__array( char, next_comm, TASK_COMM_LEN )
__field( pid_t, next_pid )
__field( int, next_prio )
),
TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
__entry->next_comm, __entry->next_pid, __entry->next_prio),
TP_fast_assign(
memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
__entry->prev_pid = prev->pid;
__entry->prev_prio = prev->prio;
memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
__entry->next_pid = next->pid;
__entry->next_prio = next->prio;
)
);
This macro is called TRACE_EVENT, it is broken up into 5 parts:
TP_PROTO: the proto type of the trace point
TP_ARGS: the arguments of the trace point
TP_STRUCT_entry: the structure layout of the entry in the ring buffer
TP_printk: the printk format
TP_fast_assign: the method used to write the entry into the ring buffer
The structure is the definition of how the event will be saved in the
ring buffer. The printk is used by the internal tracing in case of
an oops, and the kernel needs to print out the format of the record
to the console. This the TP_printk gives a means to show the records
in a human readable format. It is also used to print out the data
from the trace file.
The TP_fast_assign is executed directly. It is basically like a C function,
where the __entry is the handle to the record.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-03-09 21:14:30 +00:00
|
|
|
|
2012-02-15 14:51:51 +00:00
|
|
|
/*
|
|
|
|
* The FTRACE_ENTRY_REG macro allows ftrace entry to define register
|
2020-10-29 15:05:54 +00:00
|
|
|
* function and thus become accessible via perf.
|
2012-02-15 14:51:51 +00:00
|
|
|
*/
|
|
|
|
#undef FTRACE_ENTRY_REG
|
2019-10-24 20:26:59 +00:00
|
|
|
#define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, regfn) \
|
|
|
|
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
|
2012-02-15 14:51:51 +00:00
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
/* not needed for this file */
|
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item)
|
tracing: new format for specialized trace points
Impact: clean up and enhancement
The TRACE_EVENT_FORMAT macro looks quite ugly and is limited in its
ability to save data as well as to print the record out. Working with
Ingo Molnar, we came up with a new format that is much more pleasing to
the eye of C developers. This new macro is more C style than the old
macro, and is more obvious to what it does.
Here's the example. The only updated macro in this patch is the
sched_switch trace point.
The old method looked like this:
TRACE_EVENT_FORMAT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_FMT("task %s:%d ==> %s:%d",
prev->comm, prev->pid, next->comm, next->pid),
TRACE_STRUCT(
TRACE_FIELD(pid_t, prev_pid, prev->pid)
TRACE_FIELD(int, prev_prio, prev->prio)
TRACE_FIELD_SPECIAL(char next_comm[TASK_COMM_LEN],
next_comm,
TP_CMD(memcpy(TRACE_ENTRY->next_comm,
next->comm,
TASK_COMM_LEN)))
TRACE_FIELD(pid_t, next_pid, next->pid)
TRACE_FIELD(int, next_prio, next->prio)
),
TP_RAW_FMT("prev %d:%d ==> next %s:%d:%d")
);
The above method is hard to read and requires two format fields.
The new method:
/*
* Tracepoint for task switches, performed by the scheduler:
*
* (NOTE: the 'rq' argument is not used by generic trace events,
* but used by the latency tracer plugin. )
*/
TRACE_EVENT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_STRUCT__entry(
__array( char, prev_comm, TASK_COMM_LEN )
__field( pid_t, prev_pid )
__field( int, prev_prio )
__array( char, next_comm, TASK_COMM_LEN )
__field( pid_t, next_pid )
__field( int, next_prio )
),
TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
__entry->next_comm, __entry->next_pid, __entry->next_prio),
TP_fast_assign(
memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
__entry->prev_pid = prev->pid;
__entry->prev_prio = prev->prio;
memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
__entry->next_pid = next->pid;
__entry->next_prio = next->prio;
)
);
This macro is called TRACE_EVENT, it is broken up into 5 parts:
TP_PROTO: the proto type of the trace point
TP_ARGS: the arguments of the trace point
TP_STRUCT_entry: the structure layout of the entry in the ring buffer
TP_printk: the printk format
TP_fast_assign: the method used to write the entry into the ring buffer
The structure is the definition of how the event will be saved in the
ring buffer. The printk is used by the internal tracing in case of
an oops, and the kernel needs to print out the format of the record
to the console. This the TP_printk gives a means to show the records
in a human readable format. It is also used to print out the data
from the trace file.
The TP_fast_assign is executed directly. It is basically like a C function,
where the __entry is the handle to the record.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-03-09 21:14:30 +00:00
|
|
|
|
2009-09-14 07:54:52 +00:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item) type item;
|
|
|
|
|
2019-10-24 20:26:59 +00:00
|
|
|
#undef __field_fn
|
|
|
|
#define __field_fn(type, item) type item;
|
|
|
|
|
2009-09-14 07:54:52 +00:00
|
|
|
#undef __field_desc
|
|
|
|
#define __field_desc(type, container, item) type item;
|
|
|
|
|
2020-06-10 02:00:41 +00:00
|
|
|
#undef __field_packed
|
|
|
|
#define __field_packed(type, container, item) type item;
|
|
|
|
|
2009-09-14 07:54:52 +00:00
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, size) type item[size];
|
|
|
|
|
tracing: Add back FORTIFY_SOURCE logic to kernel_stack event structure
For backward compatibility, older tooling expects to see the kernel_stack
event with a "caller" field that is a fixed size array of 8 addresses. The
code now supports more than 8 with an added "size" field that states the
real number of entries. But the "caller" field still just looks like a
fixed size to user space.
Since the tracing macros that create the user space format files also
creates the structures that those files represent, the kernel_stack event
structure had its "caller" field a fixed size of 8, but in reality, when
it is allocated on the ring buffer, it can hold more if the stack trace is
bigger that 8 functions. The copying of these entries was simply done with
a memcpy():
size = nr_entries * sizeof(unsigned long);
memcpy(entry->caller, fstack->calls, size);
The FORTIFY_SOURCE logic noticed at runtime that when the nr_entries was
larger than 8, that the memcpy() was writing more than what the structure
stated it can hold and it complained about it. This is because the
FORTIFY_SOURCE code is unaware that the amount allocated is actually
enough to hold the size. It does not expect that a fixed size field will
hold more than the fixed size.
This was originally solved by hiding the caller assignment with some
pointer arithmetic.
ptr = ring_buffer_data();
entry = ptr;
ptr += offsetof(typeof(*entry), caller);
memcpy(ptr, fstack->calls, size);
But it is considered bad form to hide from kernel hardening. Instead, make
it work nicely with FORTIFY_SOURCE by adding a new __stack_array() macro
that is specific for this one special use case. The macro will take 4
arguments: type, item, len, field (whereas the __array() macro takes just
the first three). This macro will act just like the __array() macro when
creating the code to deal with the format file that is exposed to user
space. But for the kernel, it will turn the caller field into:
type item[] __counted_by(field);
or for this instance:
unsigned long caller[] __counted_by(size);
Now the kernel code can expose the assignment of the caller to the
FORTIFY_SOURCE and everyone is happy!
Link: https://lore.kernel.org/linux-trace-kernel/20230712105235.5fc441aa@gandalf.local.home/
Link: https://lore.kernel.org/linux-trace-kernel/20230713092605.2ddb9788@rorschach.local.home
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
2023-07-13 13:26:05 +00:00
|
|
|
#undef __stack_array
|
|
|
|
#define __stack_array(type, item, size, field) __array(type, item, size)
|
|
|
|
|
2009-09-14 07:54:52 +00:00
|
|
|
#undef __array_desc
|
|
|
|
#define __array_desc(type, container, item, size) type item[size];
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item) type item[];
|
|
|
|
|
|
|
|
#undef F_STRUCT
|
|
|
|
#define F_STRUCT(args...) args
|
|
|
|
|
|
|
|
#undef F_printk
|
|
|
|
#define F_printk(fmt, args...) fmt, args
|
|
|
|
|
|
|
|
#undef FTRACE_ENTRY
|
2019-10-24 20:26:59 +00:00
|
|
|
#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
|
2012-02-15 14:51:53 +00:00
|
|
|
struct ____ftrace_##name { \
|
|
|
|
tstruct \
|
|
|
|
}; \
|
|
|
|
static void __always_unused ____ftrace_check_##name(void) \
|
|
|
|
{ \
|
|
|
|
struct ____ftrace_##name *__entry = NULL; \
|
|
|
|
\
|
|
|
|
/* force compile-time check on F_printk() */ \
|
|
|
|
printk(print); \
|
2009-09-14 07:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef FTRACE_ENTRY_DUP
|
2019-10-24 20:26:59 +00:00
|
|
|
#define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
|
|
|
|
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
|
2009-09-14 07:54:52 +00:00
|
|
|
|
|
|
|
#include "trace_entries.h"
|
|
|
|
|
2019-10-24 20:26:59 +00:00
|
|
|
#undef __field_ext
|
|
|
|
#define __field_ext(_type, _item, _filter_type) { \
|
|
|
|
.type = #_type, .name = #_item, \
|
|
|
|
.size = sizeof(_type), .align = __alignof__(_type), \
|
|
|
|
is_signed_type(_type), .filter_type = _filter_type },
|
|
|
|
|
2020-06-10 02:00:41 +00:00
|
|
|
|
|
|
|
#undef __field_ext_packed
|
|
|
|
#define __field_ext_packed(_type, _item, _filter_type) { \
|
|
|
|
.type = #_type, .name = #_item, \
|
|
|
|
.size = sizeof(_type), .align = 1, \
|
|
|
|
is_signed_type(_type), .filter_type = _filter_type },
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __field
|
2019-10-24 20:26:59 +00:00
|
|
|
#define __field(_type, _item) __field_ext(_type, _item, FILTER_OTHER)
|
|
|
|
|
|
|
|
#undef __field_fn
|
|
|
|
#define __field_fn(_type, _item) __field_ext(_type, _item, FILTER_TRACE_FN)
|
2009-09-12 23:26:21 +00:00
|
|
|
|
|
|
|
#undef __field_desc
|
2019-10-24 20:26:59 +00:00
|
|
|
#define __field_desc(_type, _container, _item) __field_ext(_type, _item, FILTER_OTHER)
|
2009-09-12 23:26:21 +00:00
|
|
|
|
2020-06-10 02:00:41 +00:00
|
|
|
#undef __field_packed
|
|
|
|
#define __field_packed(_type, _container, _item) __field_ext_packed(_type, _item, FILTER_OTHER)
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __array
|
2019-10-24 20:26:59 +00:00
|
|
|
#define __array(_type, _item, _len) { \
|
|
|
|
.type = #_type"["__stringify(_len)"]", .name = #_item, \
|
|
|
|
.size = sizeof(_type[_len]), .align = __alignof__(_type), \
|
2023-02-12 15:13:03 +00:00
|
|
|
is_signed_type(_type), .filter_type = FILTER_OTHER, \
|
|
|
|
.len = _len },
|
2009-09-12 23:26:21 +00:00
|
|
|
|
tracing: Add back FORTIFY_SOURCE logic to kernel_stack event structure
For backward compatibility, older tooling expects to see the kernel_stack
event with a "caller" field that is a fixed size array of 8 addresses. The
code now supports more than 8 with an added "size" field that states the
real number of entries. But the "caller" field still just looks like a
fixed size to user space.
Since the tracing macros that create the user space format files also
creates the structures that those files represent, the kernel_stack event
structure had its "caller" field a fixed size of 8, but in reality, when
it is allocated on the ring buffer, it can hold more if the stack trace is
bigger that 8 functions. The copying of these entries was simply done with
a memcpy():
size = nr_entries * sizeof(unsigned long);
memcpy(entry->caller, fstack->calls, size);
The FORTIFY_SOURCE logic noticed at runtime that when the nr_entries was
larger than 8, that the memcpy() was writing more than what the structure
stated it can hold and it complained about it. This is because the
FORTIFY_SOURCE code is unaware that the amount allocated is actually
enough to hold the size. It does not expect that a fixed size field will
hold more than the fixed size.
This was originally solved by hiding the caller assignment with some
pointer arithmetic.
ptr = ring_buffer_data();
entry = ptr;
ptr += offsetof(typeof(*entry), caller);
memcpy(ptr, fstack->calls, size);
But it is considered bad form to hide from kernel hardening. Instead, make
it work nicely with FORTIFY_SOURCE by adding a new __stack_array() macro
that is specific for this one special use case. The macro will take 4
arguments: type, item, len, field (whereas the __array() macro takes just
the first three). This macro will act just like the __array() macro when
creating the code to deal with the format file that is exposed to user
space. But for the kernel, it will turn the caller field into:
type item[] __counted_by(field);
or for this instance:
unsigned long caller[] __counted_by(size);
Now the kernel code can expose the assignment of the caller to the
FORTIFY_SOURCE and everyone is happy!
Link: https://lore.kernel.org/linux-trace-kernel/20230712105235.5fc441aa@gandalf.local.home/
Link: https://lore.kernel.org/linux-trace-kernel/20230713092605.2ddb9788@rorschach.local.home
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
2023-07-13 13:26:05 +00:00
|
|
|
#undef __stack_array
|
|
|
|
#define __stack_array(_type, _item, _len, _field) __array(_type, _item, _len)
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __array_desc
|
2019-10-24 20:26:59 +00:00
|
|
|
#define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len)
|
2009-09-12 23:26:21 +00:00
|
|
|
|
|
|
|
#undef __dynamic_array
|
2019-10-24 20:26:59 +00:00
|
|
|
#define __dynamic_array(_type, _item) { \
|
|
|
|
.type = #_type "[]", .name = #_item, \
|
|
|
|
.size = 0, .align = __alignof__(_type), \
|
|
|
|
is_signed_type(_type), .filter_type = FILTER_OTHER },
|
2009-09-12 23:26:21 +00:00
|
|
|
|
|
|
|
#undef FTRACE_ENTRY
|
2019-10-24 20:26:59 +00:00
|
|
|
#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
|
|
|
|
static struct trace_event_fields ftrace_event_fields_##name[] = { \
|
|
|
|
tstruct \
|
|
|
|
{} };
|
2009-03-31 05:49:16 +00:00
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#include "trace_entries.h"
|
|
|
|
|
2009-12-15 07:39:42 +00:00
|
|
|
#undef __entry
|
|
|
|
#define __entry REC
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item)
|
|
|
|
|
2019-10-24 20:26:59 +00:00
|
|
|
#undef __field_fn
|
|
|
|
#define __field_fn(type, item)
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __field_desc
|
|
|
|
#define __field_desc(type, container, item)
|
|
|
|
|
2020-06-10 02:00:41 +00:00
|
|
|
#undef __field_packed
|
|
|
|
#define __field_packed(type, container, item)
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len)
|
|
|
|
|
tracing: Add back FORTIFY_SOURCE logic to kernel_stack event structure
For backward compatibility, older tooling expects to see the kernel_stack
event with a "caller" field that is a fixed size array of 8 addresses. The
code now supports more than 8 with an added "size" field that states the
real number of entries. But the "caller" field still just looks like a
fixed size to user space.
Since the tracing macros that create the user space format files also
creates the structures that those files represent, the kernel_stack event
structure had its "caller" field a fixed size of 8, but in reality, when
it is allocated on the ring buffer, it can hold more if the stack trace is
bigger that 8 functions. The copying of these entries was simply done with
a memcpy():
size = nr_entries * sizeof(unsigned long);
memcpy(entry->caller, fstack->calls, size);
The FORTIFY_SOURCE logic noticed at runtime that when the nr_entries was
larger than 8, that the memcpy() was writing more than what the structure
stated it can hold and it complained about it. This is because the
FORTIFY_SOURCE code is unaware that the amount allocated is actually
enough to hold the size. It does not expect that a fixed size field will
hold more than the fixed size.
This was originally solved by hiding the caller assignment with some
pointer arithmetic.
ptr = ring_buffer_data();
entry = ptr;
ptr += offsetof(typeof(*entry), caller);
memcpy(ptr, fstack->calls, size);
But it is considered bad form to hide from kernel hardening. Instead, make
it work nicely with FORTIFY_SOURCE by adding a new __stack_array() macro
that is specific for this one special use case. The macro will take 4
arguments: type, item, len, field (whereas the __array() macro takes just
the first three). This macro will act just like the __array() macro when
creating the code to deal with the format file that is exposed to user
space. But for the kernel, it will turn the caller field into:
type item[] __counted_by(field);
or for this instance:
unsigned long caller[] __counted_by(size);
Now the kernel code can expose the assignment of the caller to the
FORTIFY_SOURCE and everyone is happy!
Link: https://lore.kernel.org/linux-trace-kernel/20230712105235.5fc441aa@gandalf.local.home/
Link: https://lore.kernel.org/linux-trace-kernel/20230713092605.2ddb9788@rorschach.local.home
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
2023-07-13 13:26:05 +00:00
|
|
|
#undef __stack_array
|
|
|
|
#define __stack_array(type, item, len, field)
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#undef __array_desc
|
|
|
|
#define __array_desc(type, container, item, len)
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item)
|
|
|
|
|
2009-12-15 07:39:42 +00:00
|
|
|
#undef F_printk
|
2012-03-22 10:18:20 +00:00
|
|
|
#define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
|
2009-12-15 07:39:42 +00:00
|
|
|
|
2012-02-15 14:51:51 +00:00
|
|
|
#undef FTRACE_ENTRY_REG
|
2019-10-24 20:26:59 +00:00
|
|
|
#define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, regfn) \
|
2019-10-15 12:10:12 +00:00
|
|
|
static struct trace_event_class __refdata event_class_ftrace_##call = { \
|
2010-04-22 14:35:55 +00:00
|
|
|
.system = __stringify(TRACE_SYSTEM), \
|
2019-10-24 20:26:59 +00:00
|
|
|
.fields_array = ftrace_event_fields_##call, \
|
2010-05-24 08:24:52 +00:00
|
|
|
.fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
|
2012-02-15 14:51:51 +00:00
|
|
|
.reg = regfn, \
|
2010-04-22 14:35:55 +00:00
|
|
|
}; \
|
|
|
|
\
|
2015-05-05 15:45:27 +00:00
|
|
|
struct trace_event_call __used event_##call = { \
|
2010-04-22 14:35:55 +00:00
|
|
|
.class = &event_class_ftrace_##call, \
|
2014-04-09 21:06:08 +00:00
|
|
|
{ \
|
|
|
|
.name = #call, \
|
|
|
|
}, \
|
|
|
|
.event.type = etype, \
|
2009-12-15 07:39:42 +00:00
|
|
|
.print_fmt = print, \
|
2015-03-03 07:21:33 +00:00
|
|
|
.flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
|
2009-03-31 05:48:49 +00:00
|
|
|
}; \
|
2019-10-15 12:10:12 +00:00
|
|
|
static struct trace_event_call __used \
|
2020-10-22 02:36:07 +00:00
|
|
|
__section("_ftrace_events") *__event_##call = &event_##call;
|
2009-03-31 05:48:49 +00:00
|
|
|
|
2012-02-15 14:51:51 +00:00
|
|
|
#undef FTRACE_ENTRY
|
2019-10-24 20:26:59 +00:00
|
|
|
#define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
|
2012-02-15 14:51:51 +00:00
|
|
|
FTRACE_ENTRY_REG(call, struct_name, etype, \
|
2019-10-24 20:26:59 +00:00
|
|
|
PARAMS(tstruct), PARAMS(print), NULL)
|
2012-02-15 14:51:51 +00:00
|
|
|
|
2015-09-29 14:43:36 +00:00
|
|
|
bool ftrace_event_is_function(struct trace_event_call *call)
|
2012-02-15 14:51:52 +00:00
|
|
|
{
|
|
|
|
return call == &event_function;
|
|
|
|
}
|
|
|
|
|
2009-09-12 23:26:21 +00:00
|
|
|
#include "trace_entries.h"
|