Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp38689lqz; Fri, 29 Mar 2024 07:57:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/JD9U9C96qY19gY/0YsIAnhwhcvX2Q6NUNUcizWZ4mtPiwGdDqmjP94oyDop7DVY1rex5x3i+8eQKST5fCw7p2JWVk1RRiQ+EHaUJQg== X-Google-Smtp-Source: AGHT+IE1r1r3CyX3H36Zr7vpd4n5AqflzDKImWZ5vjVFaYf7CYrqdQWHMTwiScvQV/OR4ZOZAsEq X-Received: by 2002:a17:902:d2cf:b0:1e0:bc5e:5ee1 with SMTP id n15-20020a170902d2cf00b001e0bc5e5ee1mr2671581plc.47.1711724259432; Fri, 29 Mar 2024 07:57:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711724259; cv=pass; d=google.com; s=arc-20160816; b=ATckXEUCMaL/YdoE3sB9Ym7wKoijleaJnEtdsPeqv9SE4f+aeTRrNAlPOryYTPYTuc wp9V2Bh0SXjmfJ6T4js31ZLn881S/8ZuH5u2q8uI4M2TVPfKZEwyVT4gXyPL7BUEAGtV 1FhuamBhyRIzk3j413upSQPb5/O1OEmwICwkDSWSi1DKxU0IIfHRnddX/QGEph3npDRR Jo/iTyBdztg465I3r071ownM0IF6gG7wOSZ/AtD/9JvHzbdHJjZ3Msa8nXo52ADdD1iV Org6ruvH6Umnn1uyzgKQizqyO7Bryx1JW60/mG6h8GbDk0KeggE08FoOOEKfMbePCQm7 gYGw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=h3NA1T/WvzHq7gGTIuI0NbSZl3Pa3ex2AOnGMkiDIsk=; fh=6ZbX4F/8nxAsc82Z4EpBh9THwIEirJCKSIwvrwyDEY8=; b=vYDY5BuJo0MvSAeuyb3MM1FZBakKecLnhHeN6Bxgzvyh5xoAATnldzVXN8VhVOGhU9 DuVvi0QpToXQ//SzPNExnLGH9nUs6s+E4I3bR7SlXUSgdHDkvtbl+dsZ6QNYPToHH9Ei xYgrhOr+wu6qF8r4cTgiM4Odan6NCjuzgOVLzkCUfhBoM53Y0qWudryfBFoks0pVPDmk IgwLlf8++7LLPqsk5K2Sn5/6AGZ9bwpR1ql8TUg/lqZsNPed174r1sGIy6YCdOEPVlh8 BiCfeyO2kgaCm3TvshroIWxXIBP7MoNMf3F9tsC7608fDGcqf0Dg/8ohQoV60600D/Um XYGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s6lArYuD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124926-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124926-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j4-20020a170903028400b001e0ebb7519asi3921118plr.50.2024.03.29.07.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124926-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s6lArYuD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124926-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124926-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 130B4B3310B for ; Fri, 29 Mar 2024 14:28:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3960B1A33B1; Fri, 29 Mar 2024 12:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s6lArYuD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C6461A3398; Fri, 29 Mar 2024 12:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716440; cv=none; b=EN/1n5AbbzF+kun/QOaVrLLimODHHAChP9YEtpCeWyngft0mRRG78ZQjfa3hBTzWBBqG7l8lPv3jMx+NKdpQLsw/muHxMuDgxo7VgMTUHtUBPTp38zpdqx+BBLuqrTSt8tJgQbsUwsgRvwCV7H/zUf43bLCrTf+4X9PXaN69Va0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716440; c=relaxed/simple; bh=1Wra2lwoSp/z48sWnntzoYkS5wx/babMCJBNRI4avDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OeyAB6csdJthwnGnFKBP11r5Pw8ZLXiefXgLJNhzltj9Ca106nHg4RxY9pggui+35/qsQq5ONOHmb18A0hwfVYHq1v9e+rFM35wHs9czX4CXHOGxdyFAEh7PqHwacJreLAXKZP3XuaCBtHa0AHRdzvj7ayFXKj9hdxN3fSmYP9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s6lArYuD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A5C5C433F1; Fri, 29 Mar 2024 12:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716439; bh=1Wra2lwoSp/z48sWnntzoYkS5wx/babMCJBNRI4avDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s6lArYuDxDGV9bUOra2gFlAfN+6LcwW0nBJn3FZYL+0lMV5aVxaRBRpz3B7s8KRCa As6aI7+R+RPGVXtuoqPOwMrDKGZmSsQP27Eu4IKubILBU98DSHlbIX0tJU2n1O4DRz d/xMtkINn0iZ8RWTvbpTwVeg4yOQSmjHeD2DW8XvM38/xMPcxsD02bPZjNfXRzCLru dt6lag0HSPqi234YlFlReCnfNUF85GTc2K9MOhFdcWVMdo5fhqhAMgQetjZKBPln3k +c2QR25XLuqJiUSGdHW2Jxg+ly0yVx8uaN/Kkf5qamvhsQyG7aczA2ErrNRxeM6UA0 InJwt4kx80/Kg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Sterba , Sasha Levin , clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 42/52] btrfs: send: handle path ref underflow in header iterate_inode_ref() Date: Fri, 29 Mar 2024 08:45:36 -0400 Message-ID: <20240329124605.3091273-42-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.83 Content-Transfer-Encoding: 8bit From: David Sterba [ Upstream commit 3c6ee34c6f9cd12802326da26631232a61743501 ] Change BUG_ON to proper error handling if building the path buffer fails. The pointers are not printed so we don't accidentally leak kernel addresses. Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/send.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 9f7ffd9ef6fd7..754a9fb0165fa 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1015,7 +1015,15 @@ static int iterate_inode_ref(struct btrfs_root *root, struct btrfs_path *path, ret = PTR_ERR(start); goto out; } - BUG_ON(start < p->buf); + if (unlikely(start < p->buf)) { + btrfs_err(root->fs_info, + "send: path ref buffer underflow for key (%llu %u %llu)", + found_key->objectid, + found_key->type, + found_key->offset); + ret = -EINVAL; + goto out; + } } p->start = start; } else { -- 2.43.0