Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp899629ybe; Wed, 4 Sep 2019 09:20:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFz04LfCFkyrkGSDx0gNxvPtV7YcxtMraKEJneulZHOIzfIyOY/y8GX70+iB4QGofvvKRa X-Received: by 2002:a17:90a:8981:: with SMTP id v1mr5826901pjn.136.1567614058714; Wed, 04 Sep 2019 09:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567614058; cv=none; d=google.com; s=arc-20160816; b=saZEKVnb7b/IYPFI6MnKsoJk9vWJBeaokaTSoCN8Y4jPBhoFAOlxSbfYntFwomUC7I /RawbCLNJIyWZf1pG+aQm9RpauwVdfQ4OsCSk0TnxuKQgGm7dYFcJK0OaSC9+KBEDksC OPCYSGaZkGXisLXMaXM34L1bbaiLVlwi2pnWZlLnG7Z2/Ng/v6omWh8z+cbX309MzzQn 2gvRHmC3MWPdWwIv6MC+aMojUOeZ3ibHSTSbHbabFPpELgn+dpZHR85v42YdJeheUFc7 3T5Y4Nc82vfc3m8CAafk7gFhGqys5uygF1272k88nJ2LJ8NAgcY4H2/mcaadTseU1OPf I3bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wTl2o6iwMZ08ydUwOPnIsMJminPa9keFNJU+oEpepE4=; b=Es9WEPt7C14EGzvKBlhun2VyuZ99SvfWayxcVhdsNmtSsJuMlNnXnILXQ5K/Sj+C1i eoIviL5i0fL7IBTSviD61utfIS323k3fm8E3dzXHI/J3NyDtyF8axiHdBRr0xqwzVNml dMZItW9ci2J9yrQByjxCEIBiDHJdbRonwzKUhs8LsQ0WPzOWhJlHL5mAGruZG9XikXWk ymkTYRF9Ne4OWhTf1g89OpfNjtemQdVXsF85c7nOVfVL0yLcbgEQ6q4sVpe1vkCZtYg6 djufYXdwtk4OtCTDNaMHuUlyYLFQcyPdIoeTo7F0dLTtKV550cRdaWbNvFmgjJbt1ynM l36Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p+LDXK+T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si6543857pln.87.2019.09.04.09.20.42; Wed, 04 Sep 2019 09:20:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p+LDXK+T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387463AbfIDQSd (ORCPT + 99 others); Wed, 4 Sep 2019 12:18:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:32836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732082AbfIDP6m (ORCPT ); Wed, 4 Sep 2019 11:58:42 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE8192339D; Wed, 4 Sep 2019 15:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567612721; bh=gcfw7Pl9wJ1QreK2DJ9KV2FBShwf39zNfDMOs861Vlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p+LDXK+T1k1os6p1NJbzu/qlEBpfUABImLqTmCSAb17HPA3nM03VLAqxgbf7FM3bS dSah5jbMd0yZwYmXra5rGCK2DWJIze7P5D4fqRAVwnDLZxJ2gKqnFPZ/G6okvT5Dwl LpZu1JRO4WRb8YvAcIfXoWvn6plYo0fK1CKABkGg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ilya Leoshkevich , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 42/94] bpf: allow narrow loads of some sk_reuseport_md fields with offset > 0 Date: Wed, 4 Sep 2019 11:56:47 -0400 Message-Id: <20190904155739.2816-42-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190904155739.2816-1-sashal@kernel.org> References: <20190904155739.2816-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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