linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Kees Cook <keescook@chromium.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Jean Delvare <jdelvare@suse.de>
Subject: Re: [GIT PULL] gcc-plugins updates for v4.13-rc1
Date: Wed, 5 Jul 2017 14:35:08 -0700	[thread overview]
Message-ID: <CA+55aFyu=uLyVsp2jfpZVyk3yJTJbLs01br1DUt==2hqk-NN+g@mail.gmail.com> (raw)
In-Reply-To: <CAKv+Gu-2ZzUd0G5Ngn_pca2AjMP4f9SKAdpEP7U3pH3msZxg0g@mail.gmail.com>

On Wed, Jul 5, 2017 at 1:40 PM, Ard Biesheuvel
<ard.biesheuvel@linaro.org> wrote:
>
> So while I think it may be useful for robustness, to avoid erratic
> behavior or exploitable interactions between different parts of the
> code, my estimation is that it wouldn't make a great deal of
> difference, given that the logic that allows the compiler to 'see the
> real initialization' is the same logic that warns us if it is lacking,
> and so in a warning free build, no init sequences should have been
> emitted to begin with.

So the issue I think would be good to fix is perhaps best explained by
pseudo-code

  int testfn(struct somestruct __user *p)
  {
        struct somestruct a;

        initialize_struct(&a);
        if (copy_to_user(p, &a, sizeof(a)))
                return -EFAULT;
        return 0;
  }

which is obviously made-up code, but is not actually entirely unrealistic.

It's fairly common code in various ioctl-like functions, but also in
things like the "stat()" system call etc. The thing that initializes a
variable is not necessarily visible, and gcc can not warn about the
fact that "initialize_struct()" doesn't actually initialize all
fields.

Or even if it does initialize all the fields, what about the padding
bytes? That doesn't matter in most normal C programs, since by
definition the padding bytes aren't used, but for the kernel, it
*does* matter when they get copied outside the kernel.

              Linus

  reply	other threads:[~2017-07-05 21:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-05  5:05 [GIT PULL] gcc-plugins updates for v4.13-rc1 Kees Cook
2017-07-05 19:07 ` Linus Torvalds
2017-07-05 20:40   ` Ard Biesheuvel
2017-07-05 21:35     ` Linus Torvalds [this message]
2017-07-05 21:48       ` Arnd Bergmann
2017-07-05 21:52         ` Kees Cook
2017-07-05 21:56         ` Linus Torvalds
2017-07-05 22:27           ` Ard Biesheuvel
2017-07-05 22:39             ` Linus Torvalds
2017-07-05 22:41           ` Andrey Ryabinin
2017-07-05 21:12   ` Arnd Bergmann
2017-07-05 21:49   ` Kees Cook

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='CA+55aFyu=uLyVsp2jfpZVyk3yJTJbLs01br1DUt==2hqk-NN+g@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=jdelvare@suse.de \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).