From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C56CC49ED7 for ; Thu, 19 Sep 2019 22:08:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5995621929 for ; Thu, 19 Sep 2019 22:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568930937; bh=gcfw7Pl9wJ1QreK2DJ9KV2FBShwf39zNfDMOs861Vlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=y6dYRi9mMtWt6aXptKOhuKSHUlXv7G1h54BMTweMeTlRkKO3re7pAdEOJyAwFg0pc zOmKFUY6ANWWusWsWdSzNIYDRfhFhaMRnz27pP/hoRxVwwixSloYBmb5WffnKyo69h JqTHqXa2tA0VcpvUSD5plzsPl1874YCZ9ctRltYE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393496AbfISWI4 (ORCPT ); Thu, 19 Sep 2019 18:08:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:46824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404077AbfISWIt (ORCPT ); Thu, 19 Sep 2019 18:08:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1CE1D2196F; Thu, 19 Sep 2019 22:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568930928; bh=gcfw7Pl9wJ1QreK2DJ9KV2FBShwf39zNfDMOs861Vlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YoFjiHZtPBFmE4VfyO1XNzUBJigMmwVFJYW4jT+pyoKY3DPAhGXjkAobuZnlmin/k u+sIQHslYnS8SVmfy0orvH4MXo59V1NDLyMj2y9DNsrQnphTVXB2SeehqdPtQqXIxB JVYYU6/mpwAXq2HX6psIihbRiauVoA6v9z0Q/PeA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Leoshkevich , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.2 064/124] bpf: allow narrow loads of some sk_reuseport_md fields with offset > 0 Date: Fri, 20 Sep 2019 00:02:32 +0200 Message-Id: <20190919214821.326409691@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214819.198419517@linuxfoundation.org> References: <20190919214819.198419517@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Leoshkevich [ Upstream commit 2c238177bd7f4b14bdf7447cc1cd9bb791f147e6 ] test_select_reuseport fails on s390 due to verifier rejecting test_select_reuseport_kern.o with the following message: ; data_check.eth_protocol = reuse_md->eth_protocol; 18: (69) r1 = *(u16 *)(r6 +22) invalid bpf_context access off=22 size=2 This is because on big-endian machines casts from __u32 to __u16 are generated by referencing the respective variable as __u16 with an offset of 2 (as opposed to 0 on little-endian machines). The verifier already has all the infrastructure in place to allow such accesses, it's just that they are not explicitly enabled for eth_protocol field. Enable them for eth_protocol field by using bpf_ctx_range instead of offsetof. Ditto for ip_protocol, bind_inany and len, since they already allow narrowing, and the same problem can arise when working with them. Fixes: 2dbb9b9e6df6 ("bpf: Introduce BPF_PROG_TYPE_SK_REUSEPORT") Signed-off-by: Ilya Leoshkevich Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- net/core/filter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 534c310bb0893..7aee6f368754a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -8553,13 +8553,13 @@ sk_reuseport_is_valid_access(int off, int size, return size == size_default; /* Fields that allow narrowing */ - case offsetof(struct sk_reuseport_md, eth_protocol): + case bpf_ctx_range(struct sk_reuseport_md, eth_protocol): if (size < FIELD_SIZEOF(struct sk_buff, protocol)) return false; /* fall through */ - case offsetof(struct sk_reuseport_md, ip_protocol): - case offsetof(struct sk_reuseport_md, bind_inany): - case offsetof(struct sk_reuseport_md, len): + case bpf_ctx_range(struct sk_reuseport_md, ip_protocol): + case bpf_ctx_range(struct sk_reuseport_md, bind_inany): + case bpf_ctx_range(struct sk_reuseport_md, len): bpf_ctx_record_field_size(info, size_default); return bpf_ctx_narrow_access_ok(off, size, size_default); -- 2.20.1