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 0EA58A0C43; Wed, 20 Oct 2021 23:43:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B2BE641149; Wed, 20 Oct 2021 23:42:47 +0200 (CEST) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 8884441134 for ; Wed, 20 Oct 2021 23:42:44 +0200 (CEST) Received: by mail-pf1-f169.google.com with SMTP id v8so4054967pfu.11 for ; Wed, 20 Oct 2021 14:42:44 -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=GBOaU6vsmQLOt+0Qfovxr1Ot5zkGiRHemQ6k+S0zLhON3AAlDuGsdWAzA1Ssb/PGYd Ui/CDENX++AWJ+I6PKcOe+VTbLwO+qlWzetP5cl0pxD7KL48CIv7CnC6ISq47SzIGRdu y6Q8nTpczh3zw5MjMQHsemUY/dew9wbe5BVnRYLkGf579XpYrgGZYYxHIylY6ptGZw5c e0Shw0VoL9wIdCcJonqMbA/edyy4Nl5Yc7q+EDkFeiinTDbksGB0QF8nrw59u8snWzKU LwduDXO2RFSZbGSdSQkEYYGvVJ/f40kNhd1jjhxu7lgafrkey0yST0gESNfJNgTAmLSx zSBA== 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=G0dPpO6q2Q5yFXqoctL3GPbwccvDOORQBXkmOvLhN+pxipOI7GISELX6omXmym9JO0 T04mDbl9uflzBUtJK+jD0RtzZRNhArdIO9KREgu4esO+Gjf278ul/1KBsSLs014DOyVX pKvxPer7HubwtdPz1QqGPHubnhVyKfpTLvJ+m3A6wik12D6uRD4sYDiCubOzlM5uXTxM 3WSjsqvI8X7juk59fcDVziIrIk/1Ka2EJsSMI0qcdfQTm96SiECRxdaIAlqSBhaqawUa +E2pVqJzee7TfnXUMTQoEryrpAW/g7fRdN1VlZF6Pg0nV/IUtrYkk9RcQ3nOSjSMdVcP 3Mew== X-Gm-Message-State: AOAM533GwEt9YYGZtFjoAYJFprMk0+/yfTTqNW1H+zx4gpCBorfmFCzP zytZWHGXbmtB7sFc1p5LLP9N7GBfG32zMA== X-Google-Smtp-Source: ABdhPJx0Novi53SKGYHSr0HRG9GnJE8wFTYUdQ2oVObIRRBkTrq4aoO65219rOgCDAW+aLLFc4aujA== X-Received: by 2002:a63:295:: with SMTP id 143mr1388784pgc.334.1634766163423; Wed, 20 Oct 2021 14:42:43 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id d20sm3304480pfl.82.2021.10.20.14.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 14:42:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Wed, 20 Oct 2021 14:42:27 -0700 Message-Id: <20211020214236.71444-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211020214236.71444-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20211020214236.71444-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v15 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