DPDK patches and discussions
 help / color / mirror / Atom feed
From: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
To: dev@dpdk.org
Cc: stephen@networkplumber.org,
	Konstantin Ananyev <konstantin.ananyev@huawei.com>,
	stable@dpdk.org
Subject: [PATCH 1/3] bfp: fix MOV instruction evaluation
Date: Thu, 27 Jun 2024 12:55:29 +0100	[thread overview]
Message-ID: <20240627115531.1440-2-konstantin.v.ananyev@yandex.ru> (raw)
In-Reply-To: <20240627115531.1440-1-konstantin.v.ananyev@yandex.ru>

From: Konstantin Ananyev <konstantin.ananyev@huawei.com>

Verifier might left some register-state values uninitialized while
evaluating MOV instructions.
Add explicit initialization.

Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
Cc: stable@dpdk.org

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
---
 lib/bpf/bpf_validate.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
index 79be5e917d..11344fff4d 100644
--- a/lib/bpf/bpf_validate.c
+++ b/lib/bpf/bpf_validate.c
@@ -636,14 +636,14 @@ eval_alu(struct bpf_verifier *bvf, const struct ebpf_insn *ins)
 {
 	uint64_t msk;
 	uint32_t op;
-	size_t opsz;
+	size_t opsz, sz;
 	const char *err;
 	struct bpf_eval_state *st;
 	struct bpf_reg_val *rd, rs;
 
-	opsz = (BPF_CLASS(ins->code) == BPF_ALU) ?
+	sz = (BPF_CLASS(ins->code) == BPF_ALU) ?
 		sizeof(uint32_t) : sizeof(uint64_t);
-	opsz = opsz * CHAR_BIT;
+	opsz = sz * CHAR_BIT;
 	msk = RTE_LEN2MASK(opsz, uint64_t);
 
 	st = bvf->evst;
@@ -652,8 +652,10 @@ eval_alu(struct bpf_verifier *bvf, const struct ebpf_insn *ins)
 	if (BPF_SRC(ins->code) == BPF_X) {
 		rs = st->rv[ins->src_reg];
 		eval_apply_mask(&rs, msk);
-	} else
+	} else {
+		rs = (struct bpf_reg_val){.v = {.size = sz,},};
 		eval_fill_imm(&rs, msk, ins->imm);
+	}
 
 	eval_apply_mask(rd, msk);
 
-- 
2.35.3


  reply	other threads:[~2024-06-27 11:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27 11:55 [PATCH 0/3] fix bpf load hangs with six IPv6 addresses Konstantin Ananyev
2024-06-27 11:55 ` Konstantin Ananyev [this message]
2024-06-27 11:55 ` [PATCH 2/3] bfp: fix " Konstantin Ananyev
2024-06-27 15:13   ` Stephen Hemminger
2024-06-27 11:55 ` [PATCH 3/3] test/bpf: add extra test cases for bpf convert Konstantin Ananyev
2024-06-27 15:15   ` Stephen Hemminger
2024-06-27 12:41 ` [PATCH 0/3] fix bpf load hangs with six IPv6 addresses Morten Brørup
2024-06-27 18:04 ` [PATCH v2 " Konstantin Ananyev
2024-06-27 18:04   ` [PATCH v2 1/3] bfp: fix MOV instruction evaluation Konstantin Ananyev
2024-06-27 18:04   ` [PATCH v2 2/3] bfp: fix load hangs with six IPv6 addresses Konstantin Ananyev
2024-06-27 18:04   ` [PATCH v2 3/3] test/bpf: add extra test cases for bpf convert Konstantin Ananyev
2024-07-04 15:10   ` [PATCH v2 0/3] fix bpf load hangs with six IPv6 addresses David Marchand

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=20240627115531.1440-2-konstantin.v.ananyev@yandex.ru \
    --to=konstantin.v.ananyev@yandex.ru \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@huawei.com \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.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).