tracing: Silence GCC 9 array bounds warning 54/220854/1
authorMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Thu, 23 May 2019 12:45:35 +0000 (14:45 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 24 Dec 2019 04:12:28 +0000 (13:12 +0900)
commit279f52b4aed95d21025d457dfad973321d3dd860
tree1b760212b2f060e6896d4249e09c259ee070a899
parent97dc085fa5d2cd509e18d3846d6b55eb92594b15
tracing: Silence GCC 9 array bounds warning

commit 0c97bf863efce63d6ab7971dad811601e6171d2f upstream.

Starting with GCC 9, -Warray-bounds detects cases when memset is called
starting on a member of a struct but the size to be cleared ends up
writing over further members.

Such a call happens in the trace code to clear, at once, all members
after and including `seq` on struct trace_iterator:

    In function 'memset',
        inlined from 'ftrace_dump' at kernel/trace/trace.c:8914:3:
    ./include/linux/string.h:344:9: warning: '__builtin_memset' offset
    [8505, 8560] from the object at 'iter' is out of the bounds of
    referenced subobject 'seq' with type 'struct trace_seq' at offset
    4368 [-Warray-bounds]
      344 |  return __builtin_memset(p, c, size);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to avoid GCC complaining about it, we compute the address
ourselves by adding the offsetof distance instead of referring
directly to the member.

Since there are two places doing this clear (trace.c and trace_kdb.c),
take the chance to move the workaround into a single place in
the internal header.

Link: http://lkml.kernel.org/r/20190523124535.GA12931@gmail.com
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
[ Removed unnecessary parenthesis around "iter" ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: backport stable linux-4.4.y commit f7247666a71 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I23f6f6304e67469acbd12d815fcb4882599f1829
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_kdb.c