From patchwork Fri Sep 24 15:21:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 99625 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 24774A0548; Fri, 24 Sep 2021 17:22:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1A6624133B; Fri, 24 Sep 2021 17:22:21 +0200 (CEST) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mails.dpdk.org (Postfix) with ESMTP id 5319541326 for ; Fri, 24 Sep 2021 17:22:14 +0200 (CEST) Received: by mail-pl1-f175.google.com with SMTP id j15so5279598plh.7 for ; Fri, 24 Sep 2021 08:22:14 -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=S4/YDTOu2tyYjCeIN8Fd4Vhli6VANSY3huhBm7JzCt/XLGHqnCZvhJIpHX/hnf74xP 0jqkvbsNNAzzVBuNKE/zWCym3XdfioICNp785N2z6HIsipmjjeHqd75KT5Tpf4JWPdMw nOs9jWkTcg/33oI8EdRo1MhXBQScfO5P1vXGkwmwK6SNmUyEmqKADgiWCYZp+mmk4dMz ogM7Vf3lzi/2iWSLJCkDVqj6myYzJiKNepghKVRlxuBoghq2mpu7UiQGhBOcI3UpPAlj c24MJoEk6aWJhwVWRgAQrpSoOdeasCEkLeaVtgx5KhVjySMlRnlc0Q34H2BKHQOe7Afp 3TkQ== 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=OrunCHXzy6OcJgO28XG5f1TEY7x0JWGEFZKUottsO4yVJm9nv/QoAQJq5K6M4ZJsmC jN3SrsjQimN3Nd2EYekAZXxYCtHCKpixcrLPRuesGekSnObgrZl/bdquwZJiPGGTxfkN f2lhozBkEFCKYbboHN5KNXIOQ0xvE9yosCzE261opAcAEt459kJJhEIL0Z6AYcx/nJKM d6/SxhNtDPVdNFRA8R8puhhTsN4GhsIZYQllUX7K4mHZot8QJRn9Ob5X4PybrpKIBUcq y1GI60gyUukt/Ww7CjVp6a35k1LbTEKDDy51YMSJ9gjw0RfJYTR/KR/u5f0k16RRv6r5 TXmA== X-Gm-Message-State: AOAM533CxiV9m7sjSie+pxOFpvX8IpWMq9n5/zQ/lChv79fuEbDQpA2Y FvLFkkaFtVbZFD4e5JwllH+NyJ+FmFeljQ== X-Google-Smtp-Source: ABdhPJxiNPjBTDHXrOvuM4mKhg3OC/wFkCNPKrjdroMMCiBOhkP0H5jlE6sw3CPMEnlkpAO5+iADDA== X-Received: by 2002:a17:90a:ba12:: with SMTP id s18mr2918249pjr.60.1632496932933; Fri, 24 Sep 2021 08:22:12 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id v2sm8587493pje.15.2021.09.24.08.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:22:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Fri, 24 Sep 2021 08:21:53 -0700 Message-Id: <20210924152202.7592-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924152202.7592-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20210924152202.7592-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v11 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;