Re: [PATCH v2 50/63] tracing: Use memset_startat() to zero struct trace_iterator

From: Steven Rostedt
Date: Wed Aug 18 2021 - 09:33:58 EST


On Tue, 17 Aug 2021 23:05:20 -0700
Kees Cook <keescook@xxxxxxxxxxxx> wrote:

> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memset(), avoid intentionally writing across
> neighboring fields.
>
> Use memset_startat() to avoid confusing memset() about writing beyond
> the target struct member.
>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
> ---
> kernel/trace/trace.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 13587e771567..9ff8c31975cd 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -6691,9 +6691,7 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
> cnt = PAGE_SIZE - 1;
>
> /* reset all but tr, trace, and overruns */
> - memset(&iter->seq, 0,
> - sizeof(struct trace_iterator) -
> - offsetof(struct trace_iterator, seq));
> + memset_startat(iter, 0, seq);

I can't find memset_startat() in mainline nor linux-next. I don't see it
in this thread either, but since this has 63 patches, I could have
easily missed it.

This change really should belong to a patch set that just introduces
memset_startat() (and perhaps memset_after()) and then updates all the
places that should use it. That way I can give it a proper review. In
other words, you should break this patch set up into smaller, more
digestible portions for the reviewers.

Thanks,

-- Steve



> cpumask_clear(iter->started);
> trace_seq_init(&iter->seq);
> iter->pos = -1;