Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp900043ybj; Fri, 20 Sep 2019 01:42:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGbTEwqde3AtjVtFr2VepjGo1o0wxxJms5YjhRm0XWekDH/fvCPrjyaXwSDwXP9j8986p6 X-Received: by 2002:a17:906:d8c8:: with SMTP id re8mr18218276ejb.130.1568968954762; Fri, 20 Sep 2019 01:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568968954; cv=none; d=google.com; s=arc-20160816; b=CKtt2dYt2vtokK+ehs4zRwCwVwsMtvfT1LvBatDHVkdmKx8rTSF72XJSwq03Znu/qZ BZVA7tiHxo9344fNjoZFvMZHjmsZZLNNcANkoM26PJw/sCxpEw8sZl44aVsPtvddqs3X Y1PpE1dzNyYymzNoQoNMLmNfWgQY8aXUrGy17AxQCseB8B/YOPgajVMZycGRqo+MbvPz Cz+g7NzJoG41vr8Smm0DlN9WnW2lPUgZCpeUeHy4G8LwFLIFAiMrxD6M4thT7+I+UcLI b5K2odTNK62E1mj2Skzu6XpFMQ84DTCKAJBk202zaZUMd02FuwAZAqBFXjSoPorQU7++ twaQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wTl2o6iwMZ08ydUwOPnIsMJminPa9keFNJU+oEpepE4=; b=biJ6oXMBpXC9kCprIyus9o/iiYJK9/aP1IsXF1LvG3bUFk7FuOImFcpHNpda/+HkVp oX6F0BTXkarITEIXbviw57gg/iqBxRSXAFf2WxXEwzrl/LA/UUGVLJJvv2CcIrrWthAq VFK8YF8gPQH77br8SYkZFnTNWv9s5LZAsSHwMn9ihbfW6xGxJuaPG2uyMVkAcPDXY3es cErRNPTacXdH3t9W1v8BFxXYwKhSFrm++z8oa8r1mp2fU0LxcA6n56cHrCJ5kf3DnZiy yYT0Yz5Wse7Xtk7c89L2vWeOf+R+5Vfdw3AN3JxTkDMocQOhbxXP7+qLVqWKrsD21tAg sU8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YoFjiHZt; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3si696071ejo.242.2019.09.20.01.42.11; Fri, 20 Sep 2019 01:42:34 -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=YoFjiHZt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393492AbfISWIy (ORCPT + 99 others); Thu, 19 Sep 2019 18:08:54 -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