linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@gmail.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: fs: Uninitialized memory read at take_dentry_name_snapshot
Date: Mon, 4 Sep 2017 18:56:02 +0200	[thread overview]
Message-ID: <CAOMGZ=HCtLUFvhy727b=pCE+BapVZobRaRqymTYr48FqZncBoA@mail.gmail.com> (raw)
In-Reply-To: <20170904142233.GV5426@ZenIV.linux.org.uk>

On 4 September 2017 at 16:22, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Mon, Sep 04, 2017 at 11:11:04PM +0900, Tetsuo Handa wrote:
>> at __d_alloc() which leaves a room for some of d_iname[] bytes uninitialized?
>> So, I think either pad explicitly at __f_alloc() or use dentry->d_name.len + 1 is needed.
>
> It's the same situation as with
>         struct foo {char s[10];int v;} *p, *q;
>         p = malloc(sizeof struct foo);
>         strcpy(p->s, "foo");
>         p->v = 69;
>         ...
>         q = malloc(sizeof struct foo);
>         memcpy(q, p, sizeof(struct foo));
>
> Sure, bytes after NUL are uninitialized, but that NUL is there
> in both copies.  FWIW, kmemcheck could simply copy the information
> about source to that about destination - in the example above
> we'd end up with "q->v initialized, along with the first 4 bytes of
> q->s", which matches the reality.  BTW, how do you handle struct
> assignments?

kmemcheck knows how to memcpy() the shadow memory state between two
slab-allocated objects, but it doesn't track memory state for the
stack so if you're copying partially uninitialised object to the stack
(which I'm guessing is the case here?) then it will produce the
warning Tetsuo Handa saw.

BTW as soon as msan/kmsan support for the kernel [1] is merged I am
planning to nuke kmemcheck from the kernel. msan/kmsan should handle
it properly.

[1]: https://github.com/google/kmsan


Vegard

  reply	other threads:[~2017-09-04 16:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 12:12 fs: Uninitialized memory read at take_dentry_name_snapshot Tetsuo Handa
2017-09-04 13:21 ` Al Viro
2017-09-04 14:11   ` Tetsuo Handa
2017-09-04 14:22     ` Al Viro
2017-09-04 16:56       ` Vegard Nossum [this message]
2017-09-13 10:12         ` [PATCH] dentry: Fix kmemcheck splat at take_dentry_name_snapshot() Tetsuo Handa

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='CAOMGZ=HCtLUFvhy727b=pCE+BapVZobRaRqymTYr48FqZncBoA@mail.gmail.com' \
    --to=vegard.nossum@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=viro@zeniv.linux.org.uk \
    /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).