All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: Alexander Potapenko <glider@google.com>
Cc: ast@kernel.org, daniel@iogearbox.net,
	Dmitriy Vyukov <dvyukov@google.com>,
	Networking <netdev@vger.kernel.org>
Subject: Re: Self-XORing BPF registers is undefined behavior
Date: Thu, 13 Dec 2018 12:59:36 +0100	[thread overview]
Message-ID: <20181213115936.GG21324@unicorn.suse.cz> (raw)
In-Reply-To: <CAG_fn=W55uuPbpvjzCphgiMbmhnFmmWY=KcOGvmUv14_JOGc5g@mail.gmail.com>

On Thu, Dec 13, 2018 at 12:00:59PM +0100, Alexander Potapenko wrote:
> Hi BPF maintainers,
> 
> some time ago KMSAN found an issue in BPF code which we decided to
> suppress at that point, but now I'd like to bring it to your
> attention.
> Namely, some BPF programs may contain instructions that XOR a register
> with itself.
> This effectively results in the following C code:
>   regs[BPF_REG_A] = regs[BPF_REG_A] ^ regs[BPF_REG_A];
> or
>   regs[BPF_REG_X] = regs[BPF_REG_X] ^ regs[BPF_REG_X];
> being executed.
> 
> According to the C11 standard this is undefined behavior, so KMSAN
> reports an error in this case.

Can you quote the part of the standard saying this is undefined
behavior? I couldn't find anything else than

  If the value being stored in an object is read from another object
  that overlaps in any way the storage of the first object, then the
  overlap shall be exact and the two objects shall have qualified or
  unqualified versions of a compatible type; otherwise, the behavior
  is undefined.

(but I only have a draft for obvious reasons). I'm not sure what exactly
they mean by "exact overlap" and the standard doesn't seem to define
the term but if the two objects are actually the same, they certainly
have compatible types.

> 
> Do you think it's feasible to explicitly initialize the register
> values like it's done here:
> https://github.com/google/kmsan/commit/813c0f3d45ebfa321d70b4b06cc054518dd1d90d
> ?

Wouldn't that mean we still end up with undefined behavior whenever
a cBPF program explicitly uses the xor with itself to zero a register?

Michal Kubecek

  parent reply	other threads:[~2018-12-13 11:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 11:00 Self-XORing BPF registers is undefined behavior Alexander Potapenko
2018-12-13 11:06 ` Eric Dumazet
2018-12-13 11:23   ` Alexander Potapenko
2018-12-13 11:59 ` Michal Kubecek [this message]
2018-12-13 12:20   ` Michal Kubecek
2018-12-13 12:24     ` Alexander Potapenko
2018-12-13 13:18       ` Daniel Borkmann
2018-12-13 14:54         ` Daniel Borkmann
2018-12-18 14:36           ` Alexander Potapenko
2020-05-27 15:52             ` Alexander Potapenko
2020-05-27 16:58               ` Alexei Starovoitov
2020-05-27 17:12                 ` Alexander Potapenko
2020-05-27 17:14                   ` Alexei Starovoitov
2020-05-28  9:54                     ` Alexander Potapenko
2020-05-28 16:00                       ` Alexei Starovoitov
2020-05-29  0:17                         ` Edward Cree
2020-05-29  6:14                           ` Dmitry Vyukov
2020-05-29  8:46                             ` Edward Cree
2020-05-29  8:53                               ` Dmitry Vyukov
2020-05-29 12:28                           ` Alexander Potapenko
2020-06-01  9:55                             ` Edward Cree
2020-06-02 13:31                               ` Alexander Potapenko
2020-06-02 17:32                                 ` Alexei Starovoitov
2020-06-03 15:37                                   ` Edward Cree
2020-06-03 16:33                                     ` Alexander Potapenko
2018-12-18 14:09         ` Alexander Potapenko

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=20181213115936.GG21324@unicorn.suse.cz \
    --to=mkubecek@suse.cz \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=netdev@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.