Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1767205pxb; Fri, 29 Jan 2021 04:58:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyO6x4oh+ejKJFkw+PYJOwvO+WQN7Qi/gaJLyGmnSXClHX2+H9hWw1JEgGqPk4gb9u4JsCP X-Received: by 2002:a17:906:1116:: with SMTP id h22mr4440205eja.279.1611925114355; Fri, 29 Jan 2021 04:58:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611925114; cv=none; d=google.com; s=arc-20160816; b=In8Ss6fM587AEWV+VXaQ8jEx8NdjgLTvkXJ2yHYmI1d7WbhteXQMt5bTPgfOo/Xdal CBj8IwjrI5SWROiphqDzQYSNBv/q6nBTLjjngVxU4nBejZDgPU5L0MZ1cn3F9pcBL/+M yfCPElMbfSa+kFzFizomOqLbSoyLsoXm+shDx0UzpFPMIhfikyhlz1RlBlLdW2VFaU00 4vMXGH4GWt3dbS9PJw6rmyB7AqU66ucWTOCC4ytK5cQY9ehPBsFQivUXr4yiRX0XoLJJ ds/RhWO3RbbziQ5U4dUdXDcBKH6gA7+52V1iQWL88w0VQ+8lyW1aKrOEh57ibI7/zrKD aY9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=98I+kxiBsVmZ3rWNJNPdp45dGexj7piXQOzcqv4y/0U=; b=Y5sSqN+AMVafcT3mdLnDY791fT4hkIG0trG+V9mjbRNE6PlGPPtNsL5dNDaGs3E1PJ SUJs/RibidAKDxadlEnzfK4BtjMzcgIN12wDKP2MTOAtGSHW4uBhC5hbiu2/5qc/TRVl NhoUYol6aVKGEoKmxfhoPPyt2bL3Ch/Hwyx4xXD/73JB1nypYk+n5DdRmhAVbB3viDU/ S5rd0PcygKpXwQlNnuQ9Y6IhDx/35dPPNLUmQ0J0mdN9GBBWMNVUox7MdLJm7jzrH2Xq 2kQ2xcd+bWOrQH8DpqaaWblS5KJpZqgjO7u5yfbmgtGQEioZoD9dHhm6a4QQqtBih2rw wOIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IpwpTrrd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p24si860132edw.248.2021.01.29.04.58.07; Fri, 29 Jan 2021 04:58:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IpwpTrrd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232603AbhA2MMA (ORCPT + 99 others); Fri, 29 Jan 2021 07:12:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:55012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232455AbhA2MFl (ORCPT ); Fri, 29 Jan 2021 07:05:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 88C4164F2E; Fri, 29 Jan 2021 11:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611918692; bh=cIhsYkjH1sbP4EzOIl/tVAIS80g1q+E0gKgoggxt1mU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpwpTrrd34QArbmzvrpoCeuHFw/5rZyPX5YXL2e9c8m0pcUrpqXLkH1kg9JH7YtmJ tdeb0w0CXayaDiZV/jMtJmjXIJI45STEsprz3dmv3o5HEehVxVoRiTi+6l+wnnBiUg 5mAlWWSP87/h7odyC89QzY1OduhlxlvVa1pKbQ7U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Josef Bacik Subject: [PATCH 4.9 19/30] bpf: Fix buggy rsh min/max bounds tracking Date: Fri, 29 Jan 2021 12:06:55 +0100 Message-Id: <20210129105911.339338950@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210129105910.583037839@linuxfoundation.org> References: <20210129105910.583037839@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Borkmann [ no upstream commit ] Fix incorrect bounds tracking for RSH opcode. Commit f23cc643f9ba ("bpf: fix range arithmetic for bpf map access") had a wrong assumption about min/max bounds. The new dst_reg->min_value needs to be derived by right shifting the max_val bounds, not min_val, and likewise new dst_reg->max_value needs to be derived by right shifting the min_val bounds, not max_val. Later stable kernels than 4.9 are not affected since bounds tracking was overall reworked and they already track this similarly as in the fix. Fixes: f23cc643f9ba ("bpf: fix range arithmetic for bpf map access") Reported-by: Ryota Shiga (Flatt Security) Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Cc: Josef Bacik Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -1732,12 +1732,11 @@ static void adjust_reg_min_max_vals(stru * unsigned shift, so make the appropriate casts. */ if (min_val < 0 || dst_reg->min_value < 0) - dst_reg->min_value = BPF_REGISTER_MIN_RANGE; + reset_reg_range_values(regs, insn->dst_reg); else - dst_reg->min_value = - (u64)(dst_reg->min_value) >> min_val; + dst_reg->min_value = (u64)(dst_reg->min_value) >> max_val; if (dst_reg->max_value != BPF_REGISTER_MAX_RANGE) - dst_reg->max_value >>= max_val; + dst_reg->max_value >>= min_val; break; default: reset_reg_range_values(regs, insn->dst_reg);