From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 45C77A0032; Fri, 1 Oct 2021 18:31:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 97FB341182; Fri, 1 Oct 2021 18:30:46 +0200 (CEST) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by mails.dpdk.org (Postfix) with ESMTP id C7C6341174 for ; Fri, 1 Oct 2021 18:30:43 +0200 (CEST) Received: by mail-pg1-f173.google.com with SMTP id s11so9895478pgr.11 for ; Fri, 01 Oct 2021 09:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=erHA10QBvEPMIbVt+G0y/6YMrkQ0owEAYa4+5XVFXzM=; b=G8DC49Iw1WEV4CEXYmKVCVA5CtFRKEbPGlW8rB8UNd/ACSxkQH9FDjNRYwYNWng0sm q7fcSqi6VwwjNlul2nR3GQO6wfI7eQBWBKNPz7vC6hebA2sjRCIybvZHP3XKoD5Q8U/n nREAsfO5T2o9Btjeleen+LCQj8m0vByXbyB/pBMZM+BMZLqoR4N78tKSjn6mmuMLS4nV HXzfyfpkoivuhV6y5U0Z9vbCwhcZoMuikmTvQS4hgsw7C1qaBWgv0fJKtBGk+E2fQpVh 5hLnJN7kGEmcPxcH2cdQLkz0dgb7lapy3RBV7MIeZTf+XhGz5ZXdJqX+WItjjvZS8J07 C/8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=erHA10QBvEPMIbVt+G0y/6YMrkQ0owEAYa4+5XVFXzM=; b=hBEALlyo/LdfcZQlFn3LOAvJ1MwDomp62/gz2vHwoZ8GMS+a3plnrw5LJ+yXqliFmU Dls9QrSF4XFz3MS2rb5317K8aQxAX9bd+0r14ZhIaJm+Jkg1mva67i0nLJcF1ggoeyqB h2+8Qsy2VOTvlR/YtqrO+2fdKSyV0/tF8WvFWO1WXxukYs5zluiqXlUfKR2I14Vs9c9J zPgXXP6eRlpbuom2Iy5qFC2RNYqT2456MciwVSnZ8JkmEdUOKsPi4tEWiAs0JCrI+vdE DT9TF4QxiV3u/S1laafuNmkbP2cdS3R+pldHcIBqsO+TgobUD0M3omAuZmMpT6+KuNBO uw2A== X-Gm-Message-State: AOAM5314layqH+ZhdcoGLWm83fpopWBOMhJzBydOwNFW56JodKr9VABS wAGkVe6cXDiWbBvQvn+lmQTQPLfR8CaqmTrE X-Google-Smtp-Source: ABdhPJxgCkE2FuyZZsBhHS7VgHPzGWCTyjLCuO0ELPaN0qXajsfLxDRZS0wXEc016vO16+tgXBsnJw== X-Received: by 2002:a63:da49:: with SMTP id l9mr10280280pgj.277.1633105842521; Fri, 01 Oct 2021 09:30:42 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id u2sm1450432pfi.120.2021.10.01.09.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 09:30:41 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Fri, 1 Oct 2021 09:26:56 -0700 Message-Id: <20211001162705.442298-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001162705.442298-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20211001162705.442298-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v12 03/12] bpf: allow self-xor operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some BPF programs may use XOR of a register with itself as a way to zero register in one instruction. The BPF filter converter generates this in the prolog to the generated code. The BPF validator would not allow this because the value of register was undefined. But after this operation it always zero. Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program") Acked-by: Konstantin Ananyev Signed-off-by: Stephen Hemminger --- lib/bpf/bpf_validate.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c index 7b1291b382e9..853279fee557 100644 --- a/lib/bpf/bpf_validate.c +++ b/lib/bpf/bpf_validate.c @@ -661,8 +661,15 @@ eval_alu(struct bpf_verifier *bvf, const struct ebpf_insn *ins) op = BPF_OP(ins->code); + /* Allow self-xor as way to zero register */ + if (op == BPF_XOR && BPF_SRC(ins->code) == BPF_X && + ins->src_reg == ins->dst_reg) { + eval_fill_imm(&rs, UINT64_MAX, 0); + eval_fill_imm(rd, UINT64_MAX, 0); + } + err = eval_defined((op != EBPF_MOV) ? rd : NULL, - (op != BPF_NEG) ? &rs : NULL); + (op != BPF_NEG) ? &rs : NULL); if (err != NULL) return err; -- 2.30.2