Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp883459yba; Thu, 18 Apr 2019 11:09:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMCCjV9BjVzLtRp2EIW1SLR0AYjyhs2EiVprOxF+PRRs3zk0RMEmJZpSVKdILmkY55Zu3C X-Received: by 2002:a17:902:fa5:: with SMTP id 34mr7585360plz.323.1555610982376; Thu, 18 Apr 2019 11:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555610982; cv=none; d=google.com; s=arc-20160816; b=h6CSqTm2ETq+WQCwuG8pKPWDtkdK3hdwJ9mt+TxLOIoPuiD8QlbO78QYL2DUu2b4Wk 0sRSj1daVIuQTz0A0Xr7FWgKGDee3ymBGvKJg3FOoOnshBN4PbH8vfkPknCmnv3uTe6V jaxxCARG8yRuz2qGWVWke5WJFAJizIxvQV4/oPKX2a2ivlLU8JbKjmSndGp8vNxC0BCc P81FRHWdAySxyO4jGLo6Dxfo1RSZw+YQftC6xBpBhYM2gkAOLiC4SezdOR05nGLQPVxp R9oQoC+ZmigY3bSODa2443fewnoDfgkA88DJOmttYSpDQYAyS3K8l8O6MiIspK2uXZ42 A15A== 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=Jzwjw7/bul2ZoO7GnzrY4Zj3Vfre2CtNPLpIGhmbxo8=; b=KcVA8fh/sb1fDj0x4RkAAZhbp+yUfVsU7W+tEgEt/rDv3+9Z/2gnpoQ6nV/fjJWsZ1 pzzNvWQ+w3yfAc1p+Mk54HFoAyWSMIjeQu8Y0IRuB+dU1Ao57y29lmHm/sK/mfh8nzhl rgSGl9fbnfxTDcwo1OhMVzM81F8FFnb/xVWI3xpGWfkpXXyYRrYm88mZKE0v9uM/yihi QQHA3TPED2EFhCS4g01SF2HwM09XVQz6hAbIbNnyQHkxNnqH4vx88u5Dx8igQgPz+K++ oJ81j9UAGcWOuqTZ8t1gitcqKm4/lJYs5b4V1ryOLxH4BQPhoa/dORpfMgW/uIj03d4/ FwoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HxpbksBd; 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 d3si2984909pfc.278.2019.04.18.11.09.27; Thu, 18 Apr 2019 11:09:42 -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=HxpbksBd; 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 S2391477AbfDRSG0 (ORCPT + 99 others); Thu, 18 Apr 2019 14:06:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:36218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390285AbfDRSGZ (ORCPT ); Thu, 18 Apr 2019 14:06:25 -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 CFC61218CD; Thu, 18 Apr 2019 18:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610784; bh=hxtOyQw9ug4h5ERpL9+6Fv4vW4LO6LA3g5iB2yHjfoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxpbksBdTq4QNqEKkCXBYeDvpebZGkJa11VZMFTjz/zh+50Gj5MI3h4ekHsolq3yH xPXK/yUCpunNrL8YH+Q1rMkbihH4eEAX75C8Sw5WlQZx9rFQM0LixCK/NIBxeVGiqR nFBxHRmcbBf2VPhUe3rBuza2sgTEariG6yMUv6MY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Alexei Starovoitov , Balbir Singh Subject: [PATCH 4.14 83/92] bpf: fix check_map_access smin_value test when pointer contains offset Date: Thu, 18 Apr 2019 19:57:41 +0200 Message-Id: <20190418160437.796780044@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160430.325165109@linuxfoundation.org> References: <20190418160430.325165109@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: Daniel Borkmann commit b7137c4eab85c1cf3d46acdde90ce1163b28c873 upstream. In check_map_access() we probe actual bounds through __check_map_access() with offset of reg->smin_value + off for lower bound and offset of reg->umax_value + off for the upper bound. However, even though the reg->smin_value could have a negative value, the final result of the sum with off could be positive when pointer arithmetic with known and unknown scalars is combined. In this case we reject the program with an error such as "R min value is negative, either use unsigned index or do a if (index >=0) check." even though the access itself would be fine. Therefore extend the check to probe whether the actual resulting reg->smin_value + off is less than zero. Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Signed-off-by: Alexei Starovoitov [backported to 4.14 sblbir] Signed-off-by: Balbir Singh Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -994,13 +994,17 @@ static int check_map_access(struct bpf_v */ if (log_level) print_verifier_state(state); + /* The minimum value is only important with signed * comparisons where we can't assume the floor of a * value is 0. If we are using signed variables for our * index'es we need to make sure that whatever we use * will have a set floor within our range. */ - if (reg->smin_value < 0) { + if (reg->smin_value < 0 && + (reg->smin_value == S64_MIN || + (off + reg->smin_value != (s64)(s32)(off + reg->smin_value)) || + reg->smin_value + off < 0)) { verbose("R%d min value is negative, either use unsigned index or do a if (index >=0) check.\n", regno); return -EACCES;