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 B1E8DA0C4D; Fri, 15 Oct 2021 22:11:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 74F4C4116B; Fri, 15 Oct 2021 22:11:42 +0200 (CEST) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id 4BF0D4114D for ; Fri, 15 Oct 2021 22:11:40 +0200 (CEST) Received: by mail-pf1-f179.google.com with SMTP id 187so9255152pfc.10 for ; Fri, 15 Oct 2021 13:11:40 -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=qw8stj48At7HmiECpk1Xrnh9nHVxI+QWcc1LAg0XW4lgasFr4rkh1f9GanX392wpjF MzjBaBPV2JG1/mySgvvZbplaSwmcgBZj3xO7bmCtEjJgnvG3Z+O1yA5RA0nHuTg0J+/y 9EN6rQ1vSOjNPcoSD3bCPZfPmVp7fZQvP4VrqN/zs9vpK//fcOyYfi7VDvKBKb5QtfoE PwW0BAQ5XYyXRxwbXMYoDZlAaPO2k8BBSokumBTL6rEsoMOV0sFCwH1AqNo/GNbwQzUY 3z+aBK28bjx2zPZlw0YSmoR5eYGnblzVnTcBEUo2O18YDFHYToHjJU4GbgsqmnLhF/bz TADA== 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=nc1UlYJ+a+JpEvBlq4T1+QpdHpvmf1mNxelj0itI0lpxn2Ug80AfChO2N2z0RIl/RW DSlyQFMejG8j5OURi9rt2gCWCE3NMmL3P5wHw6RkF561gOQaafxVMz1i65WaTVP6yhos tXm9egd91ZAoUI0Nfy0F5XnQjNNkHpKkuc1D2lYJ07vQf1yWre4NlOD/6bzJI/Sckeql KSnrJIggsqk+ZreB8SO+cElIjhyTUvlmUUkECUbncU2M/XnX87S52x5DWfN3sgpMbtS8 ktZtcd0+5Uv34tibf8ofgIwyzyGjLjvP+PjT4dgVtrEqA5+L25l07rpy8KgPubP8FMCR RDPg== X-Gm-Message-State: AOAM532WrFzFirqRhafhYp+k8pUPWvebmwpgrP9+M4JD/Lh9QeRJLdVC /X+c7PrFMOFuRxsFff8tSIm2OHLh8z7vDw== X-Google-Smtp-Source: ABdhPJy+7teQnOcbALUuETO73+v3n66SJmo4wggUaYB701m0vE+sh7OdzMPGwoOsIIcXVlA26dSk6w== X-Received: by 2002:a63:251:: with SMTP id 78mr10842068pgc.54.1634328699078; Fri, 15 Oct 2021 13:11:39 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id g4sm5250456pgs.42.2021.10.15.13.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 13:11:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Fri, 15 Oct 2021 13:11:20 -0700 Message-Id: <20211015201129.63220-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211015201129.63220-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20211015201129.63220-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v14 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