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.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 23DA0C48BD3 for ; Thu, 27 Jun 2019 00:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5D2A2082F for ; Thu, 27 Jun 2019 00:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561596910; bh=oLXxZ23PxMtr4AgajN54CECw/vg69hq/wtmyTzA3Ceg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=OiaT6mBfvqlKgvA14sWi/ZczFSTOUDjBYt8I+ghKJw2ZMWcU1dX6+nhzOu6//dFvE Kh1cE52gXmuuR0HaebcxqXfsOtMrChsT4OQ3W282WOpqRAkva7jwMbcH8OZPyrUTFY ANERFptnqDwlp8tfmA1Lc9sgKfWM19tNsu+dZaCI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbfF0Aav (ORCPT ); Wed, 26 Jun 2019 20:30:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:34076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726862AbfF0Aav (ORCPT ); Wed, 26 Jun 2019 20:30:51 -0400 Received: from sasha-vm.mshome.net (unknown [107.242.116.147]) (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 179F1217D7; Thu, 27 Jun 2019 00:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561595449; bh=oLXxZ23PxMtr4AgajN54CECw/vg69hq/wtmyTzA3Ceg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSzfe2pZGD460EvkQ5deswGpqufFdpC6QNeBJYc55Kt8SbFK4tygbow6/AQvr9T2o UMs2xZ8YHL8VKhsMoAEkMFczBosxOAqpnaibpgvzj0NYbAJNGzWh4IF9HiHRG+RlZW YNCFmM1yDDqLVFpIB+9lNLD74SYV0KMWxPNf9Bwg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lorenz Bauer , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.1 08/95] bpf: fix out-of-bounds read in __bpf_skc_lookup Date: Wed, 26 Jun 2019 20:28:53 -0400 Message-Id: <20190627003021.19867-8-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190627003021.19867-1-sashal@kernel.org> References: <20190627003021.19867-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Lorenz Bauer [ Upstream commit 9b28ae243ef3b13d8a88b5451d025475c75ebdef ] __bpf_skc_lookup takes a socket tuple and the length of the tuple as an argument. Based on the length, it decides which address family to pass to the helper function sk_lookup. In case of AF_INET6, it fails to verify that the length of the tuple is long enough. sk_lookup may therefore access data past the end of the tuple. Fixes: 6acc9b432e67 ("bpf: Add helper to retrieve socket in BPF") Signed-off-by: Lorenz Bauer Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- net/core/filter.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 27e61ffd9039..85f9e960588b 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5173,7 +5173,13 @@ __bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len, struct net *net; int sdif; - family = len == sizeof(tuple->ipv4) ? AF_INET : AF_INET6; + if (len == sizeof(tuple->ipv4)) + family = AF_INET; + else if (len == sizeof(tuple->ipv6)) + family = AF_INET6; + else + return NULL; + if (unlikely(family == AF_UNSPEC || flags || !((s32)netns_id < 0 || netns_id <= S32_MAX))) goto out; -- 2.20.1