linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Daniel Borkmann <daniel@iogearbox.net>,
	Piotr Krysiuk <piotras@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>
Subject: [PATCH 5.12 3/7] bpf: No need to simulate speculative domain for immediates
Date: Thu, 27 May 2021 17:13:04 +0200	[thread overview]
Message-ID: <20210527151139.354476579@linuxfoundation.org> (raw)
In-Reply-To: <20210527151139.241267495@linuxfoundation.org>

From: Daniel Borkmann <daniel@iogearbox.net>

commit a7036191277f9fa68d92f2071ddc38c09b1e5ee5 upstream.

In 801c6058d14a ("bpf: Fix leakage of uninitialized bpf stack under
speculation") we replaced masking logic with direct loads of immediates
if the register is a known constant. Given in this case we do not apply
any masking, there is also no reason for the operation to be truncated
under the speculative domain.

Therefore, there is also zero reason for the verifier to branch-off and
simulate this case, it only needs to do it for unknown but bounded scalars.
As a side-effect, this also enables few test cases that were previously
rejected due to simulation under zero truncation.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Piotr Krysiuk <piotras@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 kernel/bpf/verifier.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5999,8 +5999,12 @@ do_sim:
 	/* If we're in commit phase, we're done here given we already
 	 * pushed the truncated dst_reg into the speculative verification
 	 * stack.
+	 *
+	 * Also, when register is a known constant, we rewrite register-based
+	 * operation to immediate-based, and thus do not need masking (and as
+	 * a consequence, do not need to simulate the zero-truncation either).
 	 */
-	if (commit_window)
+	if (commit_window || off_is_imm)
 		return 0;
 
 	/* Simulate and find potential out-of-bounds access under



  parent reply	other threads:[~2021-05-27 15:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 15:13 [PATCH 5.12 0/7] 5.12.8-rc1 review Greg Kroah-Hartman
2021-05-27 15:13 ` [PATCH 5.12 1/7] bpf: Wrap aux data inside bpf_sanitize_info container Greg Kroah-Hartman
2021-05-27 15:13 ` [PATCH 5.12 2/7] bpf: Fix mask direction swap upon off reg sign change Greg Kroah-Hartman
2021-05-27 15:13 ` Greg Kroah-Hartman [this message]
2021-05-27 15:13 ` [PATCH 5.12 4/7] context_tracking: Move guest exit context tracking to separate helpers Greg Kroah-Hartman
2021-05-27 15:13 ` [PATCH 5.12 5/7] context_tracking: Move guest exit vtime accounting " Greg Kroah-Hartman
2021-05-27 15:13 ` [PATCH 5.12 6/7] KVM: x86: Defer vtime accounting til after IRQ handling Greg Kroah-Hartman
2021-05-27 15:13 ` [PATCH 5.12 7/7] NFC: nci: fix memory leak in nci_allocate_device Greg Kroah-Hartman
2021-05-27 22:28 ` [PATCH 5.12 0/7] 5.12.8-rc1 review Fox Chen
2021-05-28  0:00 ` Shuah Khan
2021-05-28  3:34 ` Florian Fainelli
2021-05-28  6:00 ` Guenter Roeck
2021-05-28  6:04 ` Naresh Kamboju
2021-05-28 12:15 ` Rudi Heitbaum
2021-05-28 13:53 ` Justin Forbes

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=20210527151139.354476579@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=piotras@gmail.com \
    --cc=stable@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).