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 ED2CCA0C41; Thu, 16 Sep 2021 02:14:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C674410F6; Thu, 16 Sep 2021 02:14:27 +0200 (CEST) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id 79FD6410E7 for ; Thu, 16 Sep 2021 02:14:23 +0200 (CEST) Received: by mail-pj1-f51.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so6215106pjc.3 for ; Wed, 15 Sep 2021 17:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8zLAH8JYngduUqqKn8lVvsuW5Di209PrcYAPwWhsz0I=; b=ZaNN/WcSUeZotziPjwgChptNMqhntBjM27n9Y3fwX8xGtjdi5BXfmS7IECC9/zdPxZ Bx4XFCsNUkdU670T3j0nLcznvQ92RIVnl8xM9huiDEPBzIlIb5UzO5f3Udz7+d9M65Ze phbOjm26pyRJ70+ueI0wjbGJibQB9TUqYNyr431hO97GZTLpaOk/f7x0ztK+nT1GFXq4 waT1cagWXv6FSZ5CJ/AfwLMjbSbDGvD13Ohbbqx9KhG/N65oXkh9O2bLAzILLrKw/m2t J+UuHtbGwwVl+cdk+n2d9GE+GB04n/Sd+64keXinYHq4+/NyYDbSDEaun6J48oVQGmKu 0tRg== 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=8zLAH8JYngduUqqKn8lVvsuW5Di209PrcYAPwWhsz0I=; b=kGswmAqMt4S+c/fwWvjji1xVGOMB0fpMOOb2RPimuVfWr6vwXOTskjc4NUGecHT3nS /bzllwCC0SDcgHGS8FKx9WDkvnJHldc/HzStxDbI8de2s6HvVSgKSVd/bkuCbrWLsjYS OhFY/r69rSw1T6S+sQSNhYHJ8nvJJrP5f1muROSTgT0fjm6s1LTgKAre0YuWY3xG8UHN Y6pZ03rLWahWjH3TywX1tsHfl5vIkgFGqbV5jq+YwIsZSHexhf2VPxDWHbEKxGxiOss5 ZRBQb6g+o+h3KmbhWVeB7FXhW8dIdwEZAvhBKjRaPft8cAVwUa+0GbeSPmf2Ms4H6NTu ovaw== X-Gm-Message-State: AOAM532vezZqkA00W+saElsYFpAC1ERYUilR++lQQMPWfiBGsUWyePN7 V1vnBeMo4gL76shoUvRj6oBHdfDzZNe4KA== X-Google-Smtp-Source: ABdhPJy6K+eroURQuXUy3bo7NtqDo0qYTXbHVlRLFCGAFkVkyTg/1dFaWZh6ZnDxJmPtCDdKsrc9Kw== X-Received: by 2002:a17:90b:4b89:: with SMTP id lr9mr11370489pjb.145.1631751262327; Wed, 15 Sep 2021 17:14:22 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id 26sm1082252pgx.72.2021.09.15.17.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 17:14:21 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , konstantin.ananyev@intel.com Date: Wed, 15 Sep 2021 17:14:07 -0700 Message-Id: <20210916001416.39998-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210916001416.39998-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20210916001416.39998-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v9 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") Cc: konstantin.ananyev@intel.com 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