Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4570390imu; Tue, 29 Jan 2019 04:01:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN4tRtW7AUrX9+mPVlh/Eg3/pWkK8I4m1by57HQptlJHqC0U2IwQjDWEr1Pd9jjME32zmiiC X-Received: by 2002:a17:902:ba8b:: with SMTP id k11mr25637346pls.177.1548763262351; Tue, 29 Jan 2019 04:01:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548763262; cv=none; d=google.com; s=arc-20160816; b=Sr0K7tT89vefQfwsCaXRkE6dGPVRhLJtVqBIPvEJ+KXwXMuOmfNRLR+JTku/MATbX4 A29EuO6Ao7iUHG75eGSmMcSqdjsfojmPWmSbHpQ68XO98bDZD5aXOK+NonssoFZdpxHN 8PsMhPNNWljRmYDr06oCHty/a6EmfL0WGuDFOrE/tk5r3W8P0+sHz78yrN5jOPQzhE7c FCVZ/txnT+yI1VFkRiRcufao8e/tqCG8VqOdXh41+TKRdWDqZnnhL4MvnZnZqNYzBPBd 4U2AVvj+NLxgmYeCtwZiiMNq4uNQxKPjsfkQB6fPaidGRofhnywdPLBtcV+mZ5HtwOGE SLtw== 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=+06UssppGFW89POuPHhM2tjB0dDXncVOnIIKiM+g1BA=; b=gB46gdMMX+DxIlsIebSWOuOsnxuYVIxWrvmDSOLh+GFTL1M3szZ5tbSKAcfEQDl9vh +ZFufDdsUuc1XLDR2y0il/NzfYoe77ZXs9rSyWp2QABQdg794WlYUSmnohEUOaCU6IhJ biZ3dtLfqgwa8ZTem6LYBL9+LR9k9tb30wmz3qPlUzKuOUCcWBJrL/L3INmP+PsZF1gu Bs2ZR/QTvYi4RpxmywMpDGmA4KZCzdVPJgF4LwGPtqO8uojyQntVUdL7FHjGVC4xjvSE AYBpY53VSG2quVl1fKoNm3oV5lnaYYKl/A0yJ47op+vWHO9vapeP5pGQvVn4tdsIWzw8 F8EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VpmPK9/u"; 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 v5si35977939ply.74.2019.01.29.04.00.46; Tue, 29 Jan 2019 04:01:02 -0800 (PST) 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="VpmPK9/u"; 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 S1730103AbfA2Lqm (ORCPT + 99 others); Tue, 29 Jan 2019 06:46:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:37120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730998AbfA2Lqb (ORCPT ); Tue, 29 Jan 2019 06:46:31 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 39FBF21873; Tue, 29 Jan 2019 11:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762390; bh=T0wmoTGF3/eI2RPCDlcyhCHff0vthpjYGMjPh2iBilQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VpmPK9/uR40ejBRzubND2PtbRzP4SQpCJvoARcr10obj4/0Tuv5fSJCZtr9nhWsFW sigD2lQ7ns0sysQV0+P9FTJFNeYfj7ivjoKNGwtc5sQweUi8YtxdbYMf0GK8bv4DO8 wzLeS8Rm5D0c9kkOPLlNjmtHxgwUNqxJyGVl+TO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.19 091/103] bpf: restrict map value pointer arithmetic for unprivileged Date: Tue, 29 Jan 2019 12:36:08 +0100 Message-Id: <20190129113207.001538791@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113159.567154026@linuxfoundation.org> References: <20190129113159.567154026@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ commit 0d6303db7970e6f56ae700fa07e11eb510cda125 upstream ] Restrict map value pointer arithmetic for unprivileged users in that arithmetic itself must not go out of bounds as opposed to the actual access later on. Therefore after each adjust_ptr_min_max_vals() with a map value pointer as a destination it will simulate a check_map_access() of 1 byte on the destination and once that fails the program is rejected for unprivileged program loads. We use this later on for masking any pointer arithmetic with the remainder of the map value space. The likelihood of breaking any existing real-world unprivileged eBPF program is very small for this corner case. Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Signed-off-by: Alexei Starovoitov Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 6d11320998c6..110ca915cfb6 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2880,6 +2880,17 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, __update_reg_bounds(dst_reg); __reg_deduce_bounds(dst_reg); __reg_bound_offset(dst_reg); + + /* For unprivileged we require that resulting offset must be in bounds + * in order to be able to sanitize access later on. + */ + if (!env->allow_ptr_leaks && dst_reg->type == PTR_TO_MAP_VALUE && + check_map_access(env, dst, dst_reg->off, 1, false)) { + verbose(env, "R%d pointer arithmetic of map value goes out of range, prohibited for !root\n", + dst); + return -EACCES; + } + return 0; } -- 2.19.1