Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3601076pxb; Mon, 24 Jan 2022 13:14:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4mU05ivhAaBTzDZSNvFhmzXOKRspZ8PbxbsFber9Q/FFTUmP4ufd+rWgBXoOjA8pSk8ZI X-Received: by 2002:a63:710c:: with SMTP id m12mr12835382pgc.519.1643058876782; Mon, 24 Jan 2022 13:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058876; cv=none; d=google.com; s=arc-20160816; b=xDwBl5FiW/rMfggoi4UdVe8dmZ1k1V2d7Y40i9PeSDqWuuS/oz2yb0DGKNgVhgBmn5 b3qky5Gf+Fr2qmj7Hz24wLYUkTeBH4laQeQZY27Z2wl4roD9ZQrxvQIB147IlzDLeSxX krKU9MGcUWM3IeTYFfxAI7ZK+brak6F4CSqtm8mmNz9S9n11hMEF7DrHTVRO+4ZhtuUT ApccU++h4B3svnZj78/fPOg/Al5hm2iFH7H4LcV4EaPOCDQRQqN89oPCbpoRwwLKsqXa xB9lQupHzJ0/ZqAPKuOAnsNQxaB7RMqUGyINjM+8wBKZCd6M/eaf7FHVjyh9fVmAjf1t 63nw== 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=E0c4aDC1SxRbHcXOOFZS6UY4UaLODMhB7ue3Oxsirl0=; b=vuRYRcxPgAcnjz/rr7dSVDHhZ41pY7bCNefQGcqDFV4eJS9QaTYTL55171MW80z2oA gp30ZiFgt/rBH29NJgP6frQM1tPuI8lVPpGGMuxHA8+R7yeYHpV1A3gZYvvLfIP0GVBy 3a5wFqBuee+TUmm1ixeRal8IUaiqmBZcOgPfzGMtYv2a3dVrZDxeVJdciZXOUA1vsnAa aEPAzQnCmRUCOD/y/rl1Unse7MlvfSkAqmW73zIu3X2MKY+tfhnrY6FWIVhnen5xXB27 tvhHjUE60O1WHhTX88N/5dDELjk9ThptDmfEnbBHgmnl344al4PoX4Uc70LkSgFUQOXN uemQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BjDy7tOt; 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 bg7si13130005plb.285.2022.01.24.13.14.21; Mon, 24 Jan 2022 13:14:36 -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=BjDy7tOt; 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 S1389898AbiAXUof (ORCPT + 99 others); Mon, 24 Jan 2022 15:44:35 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:51138 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382303AbiAXUZZ (ORCPT ); Mon, 24 Jan 2022 15:25:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4BB8D61502; Mon, 24 Jan 2022 20:25:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B065C340E5; Mon, 24 Jan 2022 20:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055924; bh=26VFPS+ZlWVKCMKJXuqEIsOZBUmq064yZg1RBxXVpvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BjDy7tOtN8Disis7zpJfvM0390JLstMxtyOJfDMcY2VIBbJ2cRaSF5HoRRCXqDlGt 4MXTzYApREecys9mMRqzqgVNDIQhP+c2FBTWL3aSrqanxqv4xwbBnfxB12peb47VxC 5fUdLGscOGZR+1sNEc+yc+MrRKxVqIWmd9VhErTk= 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 5.15 311/846] bpf: Dont promote bogus looking registers after null check. Date: Mon, 24 Jan 2022 19:37:08 +0100 Message-Id: <20220124184111.642942692@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 [ Upstream commit e60b0d12a95dcf16a63225cead4541567f5cb517 ] If we ever get to a point again where we convert a bogus looking _or_null typed register containing a non-zero fixed or variable offset, then lets not reset these bounds to zero since they are not and also don't promote the register to a type, but instead leave it as _or_null. Converting to a unknown register could be an avenue as well, but then if we run into this case it would allow to leak a kernel pointer this way. Fixes: f1174f77b50c ("bpf/verifier: rework value tracking") Signed-off-by: Daniel Borkmann Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 18c75d6d98960..7be72682dfda0 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -8771,15 +8771,15 @@ static void mark_ptr_or_null_reg(struct bpf_func_state *state, { if (reg_type_may_be_null(reg->type) && reg->id == id && !WARN_ON_ONCE(!reg->id)) { - /* Old offset (both fixed and variable parts) should - * have been known-zero, because we don't allow pointer - * arithmetic on pointers that might be NULL. - */ if (WARN_ON_ONCE(reg->smin_value || reg->smax_value || !tnum_equals_const(reg->var_off, 0) || reg->off)) { - __mark_reg_known_zero(reg); - reg->off = 0; + /* Old offset (both fixed and variable parts) should + * have been known-zero, because we don't allow pointer + * arithmetic on pointers that might be NULL. If we + * see this happening, don't convert the register. + */ + return; } if (is_null) { reg->type = SCALAR_VALUE; -- 2.34.1