From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
Dan Carpenter <error27@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Kees Cook <keescook@chromium.org>,
zhanglin <zhang.lin16@zte.com.cn>
Subject: Re: [PATCH] kernel: sys.c: Avoid copying possible padding bytes in copy_to_user
Date: Sun, 27 Oct 2019 15:47:21 -0700 [thread overview]
Message-ID: <92212e57d45f4410be654183f5dcb1e98d636ef2.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1910270644590.3186@hadrien>
On Sun, 2019-10-27 at 06:47 +0100, Julia Lawall wrote:
>
> On Sat, 26 Oct 2019, Joe Perches wrote:
>
> > Initialization is not guaranteed to zero padding bytes so
> > use an explicit memset instead to avoid leaking any kernel
> > content in any possible padding bytes.
>
> Here is an extract of an email that I sent to Kees at one point that left
> me unsure about what should be done about these situations:
>
> From Kees:
>
> The only way to correctly handle this is:
>
> memset(&instance, 0, sizeof(instance));
> instance.one = 1;
>
> From me:
>
> Actually, this document:
>
> https://wiki.sei.cmu.edu/confluence/display/c/DCL39-C.+Avoid+information+leakage+when+passing+a+structure+across+a+trust+boundary
>
> says that memset is a "noncompliant solution". They suggest declaring the
> structure as packed, as well as some other more unpleasant solutions.
> Their point is that 1 will be sitting in a register, and the assignment at
> least might copy the upper bytes of the register into the padding space.
It took me a minute to understand why, but it
is true and possible.
> Is the memset solution nevertheless what is always wanted in the kernel
> when there is padding?
I think yes as at least it makes it consistent.
From the link above, as I understand the __user
gcc extension here
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c61f13eaa1ee17728c41370100d2d45c254ce76f
gcc does not clear padding from initialized structs
marked with __user.
Perhaps adding yet another attribute to struct definitions
and another gcc extension could help.
Perhaps add something like
#define __uapi __attribute__((__uapi__))
and mark the struct definitions in include/uapi like:
struct ethtool_wolinfo {
__u32 cmd;
__u32 supported;
__u32 wolopts;
__u8 sopass[SOPASS_MAX];
} __uapi;
so that gcc could make sure any struct padding
is also zeroed if initialized.
Though that doesn't force the compiler to not
perform the possible register optimization shown
in the first document above.
next prev parent reply other threads:[~2019-10-27 22:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-26 19:46 Joe Perches
2019-10-27 5:47 ` Julia Lawall
2019-10-27 22:47 ` Joe Perches [this message]
2019-10-28 7:30 ` Dan Carpenter
2019-10-28 18:58 ` Kees Cook
2019-10-28 7:18 ` Dan Carpenter
2019-10-28 8:08 ` Joe Perches
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=92212e57d45f4410be654183f5dcb1e98d636ef2.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=error27@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=zhang.lin16@zte.com.cn \
/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
all inboxes | Powered by JetHome®