Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3321283pxf; Mon, 15 Mar 2021 07:06:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfTiVe+cY3IADyNYBCJfaF4n3amBGR7lGv5VziHBx/RnwXo80tuufczP2jivo6ZusshRIP X-Received: by 2002:a05:6402:38d:: with SMTP id o13mr29853199edv.337.1615817183170; Mon, 15 Mar 2021 07:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817183; cv=none; d=google.com; s=arc-20160816; b=b1aZh3v+RxUN/tCYDMT6RwPmUduokoRrE++Jy59wF9rNbEu/lqid6JC5iEC76Wr/A2 53CmfSkDMW/x3Kvln9MXl6g/zZuKdux6jjDuf2+wREWaQx3MjynNUt3rKTADsNSZ4o58 TkeU+m6cIwrQU6TjuBFt2mVqdncJqrmOjBkBENodol6vJw/X2S2TCgzk/Nk9ZrOFVnqS BZkHCbPClGpEUf7gTttPA68FXOPgt4QLTA+EaTHMfwqTgjDebauQKufblGpmUQD4DWe/ 07bvAarQencz2V7RVPf5PyXLZQvLmuKRZD/85q3GzUNy4dy+FjjTEHb1VjI+WOH9wqw/ BLxA== 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=hLSOP0H24tDn0de9wHhUXVr6VntsU/HqslLSSlojfEaiwMDsbhSQ3B8CE8VR/Ew9Xl 5v79NsaMKWVhbPQpAmvUEorvTsK6MFau877Mmp4FVx7mEoH7wYHjWKuQb/9OdR1OvUqQ lVyiVxfGZMjYP6b5343iQIt/2X/YnPkfmzIDEl6esoKjEosNBVOwoQCTXXnCqwy/IQyL rGhOWiTXEv0JSzxFqcpb+64ZMAAe65TUone4+xCQcup593Cb4SQW/vlRRmpgUNYgpONp 6pYCjH7s1sbgFJIDvRRR5pRXMEvah4Xi5gKX8VPPMYG4D0wYk3wJGJplK1+9/3ruby5M N0OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UY+XdkQk; 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 bx12si11098098edb.404.2021.03.15.07.06.00; Mon, 15 Mar 2021 07:06:23 -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=UY+XdkQk; 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 S234552AbhCOOET (ORCPT + 99 others); Mon, 15 Mar 2021 10:04:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231901AbhCON5S (ORCPT ); Mon, 15 Mar 2021 09:57:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 438AE64F1A; Mon, 15 Mar 2021 13:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816637; bh=brXWXpnYW6YQL0ESqPRMZqTazFW2xCed+nZ3A+nBLeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UY+XdkQkIBZ/PnBjRuf5GakahDW7i2+HMt99+WKEGrrSbzlZT3n1Zthgj08gzsXZU 3Z8yyOIuLNtISsxGcGZ1BzrbSficFTQhFw9IxrEN/0iozDiD+I6kLGcGG/+jeqt5UR YTNWlEsyD+7LIJFa02J7npX1XfPbUOdDUCHoDM+Y= 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.4 018/168] selftests/bpf: Mask bpf_csum_diff() return value to 16 bits in test_verifier Date: Mon, 15 Mar 2021 14:54:10 +0100 Message-Id: <20210315135550.945940300@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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",