From patchwork Thu Sep 16 22:26:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 99039 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 BA4A1A0C47; Fri, 17 Sep 2021 00:26:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7C35410F7; Fri, 17 Sep 2021 00:26:45 +0200 (CEST) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mails.dpdk.org (Postfix) with ESMTP id 4A846410F4 for ; Fri, 17 Sep 2021 00:26:41 +0200 (CEST) Received: by mail-pg1-f177.google.com with SMTP id u18so7691445pgf.0 for ; Thu, 16 Sep 2021 15:26:41 -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=LkccsOCra3us6bbxBnJDQj5aNtIsmhStPfMIIbh57J0FqlWtQ4ZSiKApyRP1l/6QB+ AD9ikmtOnRHl4f3pYz0NMWNoeMGGQAmXopJstxZw1Pj6XpT2j3DnY0Op7Ee+DekD0cnx nTj+ygAZE2l7SUBubaaAZDSKfZIGJ6lFsw4O4N17MZ2j8TmOfT1KhPWiC/VwwdDj/pT9 C+OgG8TLm1ZbWMYQPZmLMtn0RwbgOGbHdjw6K/k24ctFfX5CvF1qAKcSv+afKfD+vmUB iWhb3fW/UOEJUwSVx7phVKEiF+RnjlaocoKq0umQX7Nd4jUWBiBs7/qoaphgx80KqOyu y5MQ== 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=olADE+IucmKMB632DhitFz4YKhvJ2hMMlynPF5Uys0kUvjQN83QHhZAO9ghANNr2oq JxcEMTiixx9+goCj3RH3Iw/On2qXKmclWt0FtAbGygeZAUd909y0dCfUOAAEfvQa4eE4 Ge2+m9AXereBeu6PFfypFxjB6zlxBvaNu/3xAMR1/lXyUAyLLZbk0nGnlzPjRQpU2asC 1Qy6zZKLi7LjU1cMvathm4CicCDV6vgg7DyJ82Ue5TuOzy91U1E4+gmWJuS22v4K+m7J OV+Hqtx6E0MpQfWGa+OQ0azFW+PeWILpdufm3Cm/ujxORD2pcbv2vOv4bTUJsgMaHVdK NjWQ== X-Gm-Message-State: AOAM533bZMPa/xEEv407AMB11ZJuaEnc0QpvjngnqMyWEjBGpdi9xgTe j0lUbiNXA8+FgsSa8Cp4wId35f5loYruIw== X-Google-Smtp-Source: ABdhPJzhOhMXPtEwIT75FkFwg+8tGwAodv2rNtUKxCNvWpB4kOYrVn2bY8OJTxY6wGdPlWyDaqrAHw== X-Received: by 2002:aa7:9d02:0:b0:43d:ea96:5882 with SMTP id k2-20020aa79d02000000b0043dea965882mr7256170pfp.23.1631831199452; Thu, 16 Sep 2021 15:26:39 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id 3sm3937169pfp.112.2021.09.16.15.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 15:26:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Thu, 16 Sep 2021 15:26:21 -0700 Message-Id: <20210916222630.71543-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210916222630.71543-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20210916222630.71543-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v10 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;