Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2374lqz; Fri, 29 Mar 2024 06:56:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVvefCypR4g/WnVUVTHl6qSOKH7mDcyZ+R81/kvLM81MUgsgpnOD1ab2IlrsYu7S4iH22xmQ2RDNDnEM+5htkO/og6mNMFLvh4/ADGShg== X-Google-Smtp-Source: AGHT+IHhABe18bK7hsGdYyW9U5vyvH4t/dZ8LyQisi7OXbfow22PL8JtB0apZoRnA19mKQt7Frf+ X-Received: by 2002:a05:6a20:3d81:b0:1a5:6e14:369 with SMTP id s1-20020a056a203d8100b001a56e140369mr2381743pzi.6.1711720568188; Fri, 29 Mar 2024 06:56:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711720568; cv=pass; d=google.com; s=arc-20160816; b=HFci+dT9cFE51VUf2TJ8JyVMVc9+zmGPh9j91yXnlsckQj681Z96DNsD4eK5NngaWi CY6tJRw50UQnq6hY9e0A7O7Ev0rbdrmt91PuOQU0X+tDDEPkLhyfkINGPE4E7/gg7PCB s9yNl3Pns7Ur8912GqtWqkmzEamiEW1I/Um5blxv5FtPt8WXxO6/97VX3/X3JpX4lsRv ra6UohTz0dS2MkcnfEV0yhbphE22v984BlJKhXbpywlnmFMrJdsFXi6va+xvwsV9au/B lvExWpAesYYEtjkHc6q6OwvBmPk0q4snQgBllzC4fQn3hz6xICuH3svC0ILPBXYWI2vy mbmw== 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=qkJWbotBTCZI6Lxh6aXtFobMUlG0Lxa0oY1bd5Cbzuc=; fh=6ZbX4F/8nxAsc82Z4EpBh9THwIEirJCKSIwvrwyDEY8=; b=fb5lz4WieyW5ZnOXTL2LZA36oN1uigXXuGy9OZjmJz/0zWLNxz9hCChE0xorXEyOi2 pKLloYe8C2QnVzJoQEfsSmO3Ekzhs+7c0X8xSwKdmtUyxgugDZXfaZCuatyYUh7Dv3+7 k+hoBvI/Qhcpt+ZFMiPgJdrwqDk/PPh7liUbs+6p9R7Wf9CgVt/fIubsqlWgFKUFaVg8 DwKRYv371K5YAzNgm5OrKlspWpKfoxAaFivHCC1o21y6PnzzEyitY+jNGwoekqGGN/qL sEw42pGNonI4dwgH4nx4zCpJOZMNvEeJm2rxzy8eeayQWWKwEqTdj77dFeUhD7HcVH8J LsPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oz0qfMR1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124794-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124794-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ln18-20020a056a003cd200b006ea81489146si3897926pfb.155.2024.03.29.06.56.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:56:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124794-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oz0qfMR1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124794-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124794-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7D6FD2896A8 for ; Fri, 29 Mar 2024 13:53:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A3BC18BC20; Fri, 29 Mar 2024 12:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oz0qfMR1" 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 5C8F718B5FC; Fri, 29 Mar 2024 12:42:29 +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=1711716149; cv=none; b=FNU2quHqxW7Ue5/XKE6iKn+eJ54rzEZwoa8PPrs1rbkg8x5OQ8QqoYq5xov4xkjNrXm1TT0cxRYd9l/ZMIqIEQFwOccTdge65rVr2YqCgP7t13VaGoGMiJAvZ1d7eNCTNhauRJuFymBzOdiAUw4go8AsYaYbUkI7eV8W3LuENlA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716149; c=relaxed/simple; bh=T07ykANRiSqZ127sWwnwShI1QgsOuD8uUzy1UKgsxBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TUToFUpKwLeaHDutuaWFT4l4Xy43ihi+BBDMyNTUTEDM6+sMbkhE9RJFuj4QRh5oaeyA3gmteIpzq7gENoxAs9zD7pp0CMWHBYcYTgBHgTniNhjO39LxOvynlMnBVXNUhR1O2rz6jr4LQCC0nlVYkDu7rL3UVQZgMm3kQhdEnRI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oz0qfMR1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EED49C433C7; Fri, 29 Mar 2024 12:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716148; bh=T07ykANRiSqZ127sWwnwShI1QgsOuD8uUzy1UKgsxBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oz0qfMR1XemVm7Mx2hTw03ANnYjjJoiLIOBgVSktFEMg0FPWZiFPTUOm0PIg/vBkJ /wXKDt6CbWTBBCmLlmqBjJG5p5/BKTQr8EGXgBgHljlrCURLyAYO0VKL2E3ikcYOfA B/L5lo7b/PqzISrQvsAWxG4HMhvkUSG/uTaRi26xfzAeYt3Umi5uOUdNqsGyNjboPB SQEIMQypiPba6DeYd/RK25cJgRwYL9g5Aw8lGm4eSfiHJdKkrE7SSOoszqOn1IGjVW Y0omEQr2PlKP2CjtURE0EAt2L7Xuf89loE5L/1ydR3rKRenApxa5CjsLIu4zDfolSt PPhk2n0dgm62A== 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.8 83/98] btrfs: send: handle path ref underflow in header iterate_inode_ref() Date: Fri, 29 Mar 2024 08:37:54 -0400 Message-ID: <20240329123919.3087149-83-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-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.8.2 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 e48a063ef0851..e9bafc73c621e 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1070,7 +1070,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