linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Linus Torvalds' <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: RE: [GIT PULL] tracing: Updates for 5.2
Date: Thu, 16 May 2019 09:08:15 +0000	[thread overview]
Message-ID: <3d476a88ffc6486099dd29acdd242436@AcuMS.aculab.com> (raw)
In-Reply-To: <CAHk-=wihYB8w__YQjgYjYZsVniu5CtkTcFycmCGdqVg8GUje7g@mail.gmail.com>

> This code:
> 
>                 /* reset all but tr, trace, and overruns */
>                 memset(&iter.seq, 0,
>                        sizeof(struct trace_iterator) -
>                        offsetof(struct trace_iterator, seq));
> 
> not only has a completely misleading comment (it resets a lot more
> than the comment states), but modern gcc looks at that code and says
> "oh, you're passing it a pointer to 'iter.seq', but then clearing a
> lot more than a 'trace_seq'":
> 
>   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);
>         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> It's a somewhat annoying warning because the code itself is
> technically correct, but at the same time, I think the gcc warning is
> reasonable. You *are* passing it a 'struct trace_seq' pointer, and
> then you're clearing a whole lot more than that.
> 
> One option is to just rewrite it something like
> 
>         const unsigned int offset = offsetof(struct trace_iterator, seq);
>         memset(offset+(void *)&iter, 0, sizeof(iter) - offset);

I'd do (const char *)&iter + offset ...

A quick fix is (probably) just:
	memset((void *)(long)&iter.seq, ...

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  parent reply	other threads:[~2019-05-16  9:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15 17:36 Steven Rostedt
2019-05-15 23:29 ` Linus Torvalds
2019-05-15 23:31   ` Linus Torvalds
2019-05-16  0:27     ` Steven Rostedt
2019-05-16  1:21       ` Linus Torvalds
2019-05-16  9:08   ` David Laight [this message]
2019-05-15 23:50 ` pr-tracker-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3d476a88ffc6486099dd29acdd242436@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --subject='RE: [GIT PULL] tracing: Updates for 5.2' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).