Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3493474imu; Sun, 11 Nov 2018 16:21:05 -0800 (PST) X-Google-Smtp-Source: AJdET5dmCwWo3PB2N1Wu3uBVr/I9IuInOtyKPdqeZLzJcN2OTPIbl1Z9PQCG7G3Bvh8b0+RmQ2nu X-Received: by 2002:a17:902:b789:: with SMTP id e9-v6mr17869577pls.338.1541982065837; Sun, 11 Nov 2018 16:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541982065; cv=none; d=google.com; s=arc-20160816; b=fQpDx9eIHbr69DCnRIO5AEtQu6As/RGzn3kzP/hrg1QUGYeMlYFeuNOQFXXnI2kkkf mI8Kk5VZCB64wf7dFFMcWtBzchbnmhv9cIBAJLaBj+P+yPT+OFuFFHS+9ToQEaLl0Yqf hKoYA9NoexqqBJEV8mmJYgXlEIbQRUAR/aXfmdGJ3nTsy7GuaGlhP0cFmp2Tg7dZOgPL 0RDhCwo3xreq6JPvmr7DaJbjcr1EsJvXHbCWxyFOhiLybGcRx61izXfCav5juyb+0860 BOxbTIEp90VBKe8xg96slvmfDNNGLI+y7FocEVtFccndpdByL4/ccL2jr64Dh9bgIwzc YnLw== 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=nGi5dy67nFxzloO24WZ2DJf0y3ZP2ATPNHDqnQ23H5Q=; b=QrsjPQfJAuuncjGyvodLvFHPqersy7JMpniyP9sWqRFOUyt0W1wEAjrUCSknII+EEz 4kFUEhCQL8dvoSUV/Bk3DrLrHnJiYya5/ShVBIY7IEMACfpoZeq8ZUafwq+R2BNmHT3b 4Hqc5nghSyt4KFwbB7IIPCDs2E7k5uV9j7coM2yoqQKPHX6t9Z1jdwCzmLubPgdtMWbD e7/EmGLFVH3h0UaJdN1VhlkzQNFtEhSPbSFLijXVopDuGS4+PHIbADNnIiDEAE2Jd8e8 Dv1MctG4McDrYNXWvDcTymxkHU1bMGjm372pMxOqxWU9boYiLqhIG3VkRctqGumriDlM gchQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G3MFCpXT; 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 f3-v6si16019295pld.186.2018.11.11.16.20.51; Sun, 11 Nov 2018 16:21:05 -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=G3MFCpXT; 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 S1729705AbeKLIQv (ORCPT + 99 others); Mon, 12 Nov 2018 03:16:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:58332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeKLIQu (ORCPT ); Mon, 12 Nov 2018 03:16:50 -0500 Received: from localhost (unknown [206.108.79.134]) (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 38AC7208A3; Sun, 11 Nov 2018 22:26:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975215; bh=VAFA9Poo6TtDJ2/qA3VvknnAD7sSbP85+oufINQYKr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3MFCpXTMs+XUduqm690Y1LpiNeUYPMD7tZrBxfr88x/2CkDyGIrZEfbziaBzYGGC kVVywEdz4OZuODa1Kt0b5fPxoSJf311raNtLQEpwLzK/RRV/x1sEdvZfo2wfUyDGDA HnIW5rPqCsa7QkaEfBINsLWs4Y8zU/g9SC4Dq4Bo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Edward Cree , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.19 001/361] bpf: fix partial copy of map_ptr when dst is scalar Date: Sun, 11 Nov 2018 14:15:48 -0800 Message-Id: <20181111221620.394307264@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 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 0962590e553331db2cc0aef2dc35c57f6300dbbe upstream. ALU operations on pointers such as scalar_reg += map_value_ptr are handled in adjust_ptr_min_max_vals(). Problem is however that map_ptr and range in the register state share a union, so transferring state through dst_reg->range = ptr_reg->range is just buggy as any new map_ptr in the dst_reg is then truncated (or null) for subsequent checks. Fix this by adding a raw member and use it for copying state over to dst_reg. Fixes: f1174f77b50c ("bpf/verifier: rework value tracking") Signed-off-by: Daniel Borkmann Cc: Edward Cree Acked-by: Alexei Starovoitov Signed-off-by: Alexei Starovoitov Acked-by: Edward Cree Signed-off-by: Sasha Levin --- include/linux/bpf_verifier.h | 3 +++ kernel/bpf/verifier.c | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 38b04f559ad3..1fd6fa822d2c 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -50,6 +50,9 @@ struct bpf_reg_state { * PTR_TO_MAP_VALUE_OR_NULL */ struct bpf_map *map_ptr; + + /* Max size from any of the above. */ + unsigned long raw; }; /* Fixed part of pointer offset, pointer types only */ s32 off; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 465952a8e465..b046564cc18d 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2762,7 +2762,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, dst_reg->umax_value = umax_ptr; dst_reg->var_off = ptr_reg->var_off; dst_reg->off = ptr_reg->off + smin_val; - dst_reg->range = ptr_reg->range; + dst_reg->raw = ptr_reg->raw; break; } /* A new variable offset is created. Note that off_reg->off @@ -2792,10 +2792,11 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, } dst_reg->var_off = tnum_add(ptr_reg->var_off, off_reg->var_off); dst_reg->off = ptr_reg->off; + dst_reg->raw = ptr_reg->raw; if (reg_is_pkt_pointer(ptr_reg)) { dst_reg->id = ++env->id_gen; /* something was added to pkt_ptr, set range to zero */ - dst_reg->range = 0; + dst_reg->raw = 0; } break; case BPF_SUB: @@ -2824,7 +2825,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, dst_reg->var_off = ptr_reg->var_off; dst_reg->id = ptr_reg->id; dst_reg->off = ptr_reg->off - smin_val; - dst_reg->range = ptr_reg->range; + dst_reg->raw = ptr_reg->raw; break; } /* A new variable offset is created. If the subtrahend is known @@ -2850,11 +2851,12 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, } dst_reg->var_off = tnum_sub(ptr_reg->var_off, off_reg->var_off); dst_reg->off = ptr_reg->off; + dst_reg->raw = ptr_reg->raw; if (reg_is_pkt_pointer(ptr_reg)) { dst_reg->id = ++env->id_gen; /* something was added to pkt_ptr, set range to zero */ if (smin_val < 0) - dst_reg->range = 0; + dst_reg->raw = 0; } break; case BPF_AND: -- 2.17.1