Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3320307pxf; Mon, 15 Mar 2021 07:05:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJqLIeWDrlTx89GbONwx6XwpVAWcQRAZM3zeJXkZLofWMdbIRBvQ+mZHhycl3tclJVWQ0b X-Received: by 2002:a05:6402:cb8:: with SMTP id cn24mr30537478edb.105.1615817119474; Mon, 15 Mar 2021 07:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817119; cv=none; d=google.com; s=arc-20160816; b=u1IHlHW3bu8DN9c3b/p7EpgOPRhegRTMxiinqGrGwpatn/jnGpgLYKzYkgFVGBeOZL 2Uew8+5Gdd5MR1U+DJmrbwLBu5+2ikVzXCL6SLDnjkdbSr/e6AzXCtYGNAIOk4mJvrM2 UXDpCFV/+J41TYHh/6COfGB9dVoIFLcnsKSmof3WnTH+GyzYO2rtK+qeSqqTthwR0LXY ZYVDs04ws7R4QSdnaRsBAICMmFgVmRUrbkRwdGYoKPSvquk9FpVfrFCnD808+Urh6Sng goBxUp2fUmHL93Ov5gkqrsJcIUlleN8aMgvF7K74N0I+Wle5PZNFW9doH8GXO4iUmEU+ X+AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/JbT797yZTup6xHHYjoEefkNgxKy4NKtRfnbYD7FSG8=; b=lm8jlA2CrlVNjAaq07sPUmXfQhmLIFxTP1inhZPjkUsUVvW/pnOIFhvtc3wXPRmJsQ 872YtPcEoeeuA+cRWwYszChG/6dfPFovZwXJ3JcqMz5XH5aFyPSUXnmNHGti17ybPgzH jG0PKnxL3QmZmBeuivZcrQwN33GO+7T/cYCyWrr5Z0Ke531eQXb9gqJlL121NCGJ8oFT eJnmzg4xy4PAYTPFiszu+eW0Gkhhr2Vy0va2ITIKAjHFOAvAQYiuxjORhwJA8TaUIydN CW5MQwcKoYRta65fwZQfHqCYwwWK5B7dGRY8QTImUSS580V2Bs8NwlaSVmM5cMc1HIlh 7/kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PGjUdVZM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ko24si11393870ejc.407.2021.03.15.07.04.55; Mon, 15 Mar 2021 07:05:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PGjUdVZM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232786AbhCOODh (ORCPT + 99 others); Mon, 15 Mar 2021 10:03:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:34280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231777AbhCON5L (ORCPT ); Mon, 15 Mar 2021 09:57:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A608464F38; Mon, 15 Mar 2021 13:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816631; bh=brXWXpnYW6YQL0ESqPRMZqTazFW2xCed+nZ3A+nBLeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PGjUdVZM7lcQqPhSPZ3xZ/1sAs8Rk+ClJouWMDEwTaiOutVLkrEQHYVgtcLGn5Z2S lffk3+Inw58NEvBDiGtCaf7LclRdba3fuxsPFWXJ4BuhN6dQ/z05CmazLqRACdWjk9 mJ0FT7eoZ/if9wnkMg18qCEL5zaUDkooMJ/8lqrA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yauheni Kaliuta , Daniel Borkmann Subject: [PATCH 5.11 031/306] selftests/bpf: Mask bpf_csum_diff() return value to 16 bits in test_verifier Date: Mon, 15 Mar 2021 14:51:34 +0100 Message-Id: <20210315135508.675532522@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Yauheni Kaliuta commit 6185266c5a853bb0f2a459e3ff594546f277609b upstream. The verifier test labelled "valid read map access into a read-only array 2" calls the bpf_csum_diff() helper and checks its return value. However, architecture implementations of csum_partial() (which is what the helper uses) differ in whether they fold the return value to 16 bit or not. For example, x86 version has ... if (unlikely(odd)) { result = from32to16(result); result = ((result >> 8) & 0xff) | ((result & 0xff) << 8); } ... while generic lib/checksum.c does: result = from32to16(result); if (odd) result = ((result >> 8) & 0xff) | ((result & 0xff) << 8); This makes the helper return different values on different architectures, breaking the test on non-x86. To fix this, add an additional instruction to always mask the return value to 16 bits, and update the expected return value accordingly. Fixes: fb2abb73e575 ("bpf, selftest: test {rd, wr}only flags and direct value access") Signed-off-by: Yauheni Kaliuta Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20210228103017.320240-1-yauheni.kaliuta@redhat.com Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/bpf/verifier/array_access.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/bpf/verifier/array_access.c +++ b/tools/testing/selftests/bpf/verifier/array_access.c @@ -250,12 +250,13 @@ BPF_MOV64_IMM(BPF_REG_5, 0), BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_csum_diff), + BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffff), BPF_EXIT_INSN(), }, .prog_type = BPF_PROG_TYPE_SCHED_CLS, .fixup_map_array_ro = { 3 }, .result = ACCEPT, - .retval = -29, + .retval = 65507, }, { "invalid write map access into a read-only array 1",