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 A9137A0C43; Fri, 15 Oct 2021 20:29:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 561DB41123; Fri, 15 Oct 2021 20:29:15 +0200 (CEST) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mails.dpdk.org (Postfix) with ESMTP id F0943410FE for ; Fri, 15 Oct 2021 20:29:12 +0200 (CEST) Received: by mail-pj1-f48.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so7891559pjb.3 for ; Fri, 15 Oct 2021 11:29:12 -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=RAcdIOYK/MSnA0NzPdY9MGJnlgtlN7VUzWvl4arUCkFJldseCT3YwDKZiv8MbPYGc4 CRC/rHka5THGupOBzozRTMWsQjNPgOSs/2bAwxdgWajOYEyQAuaf4eru/xSgIDJ9oBHB XoWTeMeHwa2GgjXerg14ATsnW/i7VRAUSAhWTWahBCs0weQIL09bJa2s/cKHnNhSjRj1 YzBmPKTK3Ed7zFeFozxWIJFmn/0vFGN7mMt8H7yEOUnskXTbABaFyApFV2z4w54p170X Ti2G9Qq2MaD3sYCJL/4FVnmAElVR7xPOAEBtEvxtEMniJNfD8pk5tAnhIYDWmidOnxiO LFng== 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=pBcXWXw7HUPFj796QS4Icm2TOHbpsZUhbbw0E5tfADUpGy7CzFcKJrbzwU7CuJzfMB pATo+F2INFKpxe4PVw8pza+oVh6NWtBg0JHxJNdLM82PZI9s5NzJyNijlQKBcPtJiGHg 9QT+0CtJl2TqEhpLtAGstPDzO2eO7BNAgFYHTeHdhd0SfiqI+USNW/XXDGH8NXoxc5kR +con/BveklT6JBriDsj44tgI2gFbwSm/SKVpjF1ZwJlGD/DLQrS/xcVvKDroRq8xZu3O bxJkxJwL+/5W5qNoqcYup6G3IQcCoIOlQlTnlShanuh7O/ySyDU4ASAtfb3exbuw7Gz4 pjvg== X-Gm-Message-State: AOAM530XnsCnM6+Ipm+SFIINXStcEZ79IPtcPhX07Lsd3gJztWItWfQa mnxJUjGFTWVBSPvCgCjeN1NAU+A112Uefw== X-Google-Smtp-Source: ABdhPJyF1I4fHaKNhgdHekRCUPyQwXvG3iJHje9TdHjfXuamxYkBdi3EaNr1zjGJ+ANLbbMpoguTvw== X-Received: by 2002:a17:90b:2247:: with SMTP id hk7mr15328622pjb.72.1634322551741; Fri, 15 Oct 2021 11:29:11 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id p189sm5526545pfp.167.2021.10.15.11.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 11:29:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Fri, 15 Oct 2021 11:28:54 -0700 Message-Id: <20211015182903.52615-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211015182903.52615-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20211015182903.52615-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v13 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