From mboxrd@z Thu Jan 1 00:00:00 1970 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 3A7F43A2E0A for ; Tue, 12 May 2026 14:01:54 +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=1778594514; cv=none; b=CNE1sE5gSkvwe/n1oa4vnsAOxkurhhzPGLNksmcDwOOvKwGhvWhOPK3rjgUMgUwaUlhSI2WKv+q+/pq4J5MuIHvFijSOdNRbx5WPkD4de984WapSQvmoBh/LIo6ULN77ZOeWksnMM7QFuji8n3ODhxFoaJsbJeGadK7q06qaqFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778594514; c=relaxed/simple; bh=KAmjC9kXQFmrkVRdZoIGa0TbUSf2mmiG9wNDgdj86j0=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=HSL2eu1NQ7zBXuCQJXAXKaCZzwbuRN2jdoYE8+owK2wWqyHLHdTYT8steVDfPeunjIXxh6sfCBSymGho9PJt6uOP7ibj9jAoSrdvTIZD007ikTxQ2uh7EnLjAjrEAyDuhHHC/6VsxO/Hw9Gpt+VnTRLR1G/iZ1ekcEYNV3Ad41s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UGhLCOwv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UGhLCOwv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7683C2BCB0; Tue, 12 May 2026 14:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778594514; bh=KAmjC9kXQFmrkVRdZoIGa0TbUSf2mmiG9wNDgdj86j0=; h=Subject:To:Cc:From:Date:From; b=UGhLCOwvhaYJ7VpgeoDikJJGP+cDhpJUDb7ijXx/fPwsvTh4PZ8NrfynjSyionYTR Ed2NRBhnw4eAT2hiGHb4HLVyLHgVfn2byTT5qKGWRgga1RIhGV4GPU0lwV3JAIOL1y Pj/Pphm33ePAb5eEW9Po6W86V66RNYKzQAdto4hw= Subject: FAILED: patch "[PATCH] btrfs: fix btrfs_ioctl_space_info() slot_count TOCTOU which" failed to apply to 6.18-stable tree To: yochaie@sweet.security,dsterba@suse.com,echelonh@gmail.com Cc: From: Date: Tue, 12 May 2026 15:58:17 +0200 Message-ID: <2026051217-juvenile-glucose-6e1a@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.18-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y git checkout FETCH_HEAD git cherry-pick -x 973e57c726c1f8e77259d1c8e519519f1e9aea77 # git commit -s git send-email --to '' --in-reply-to '2026051217-juvenile-glucose-6e1a@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 973e57c726c1f8e77259d1c8e519519f1e9aea77 Mon Sep 17 00:00:00 2001 From: Yochai Eisenrich Date: Sun, 22 Mar 2026 08:39:35 +0200 Subject: [PATCH] btrfs: fix btrfs_ioctl_space_info() slot_count TOCTOU which can lead to info-leak btrfs_ioctl_space_info() has a TOCTOU race between two passes over the block group RAID type lists. The first pass counts entries to determine the allocation size, then the second pass fills the buffer. The groups_sem rwlock is released between passes, allowing concurrent block group removal to reduce the entry count. When the second pass fills fewer entries than the first pass counted, copy_to_user() copies the full alloc_size bytes including trailing uninitialized kmalloc bytes to userspace. Fix by copying only total_spaces entries (the actually-filled count from the second pass) instead of alloc_size bytes, and switch to kzalloc so any future copy size mismatch cannot leak heap data. Fixes: 7fde62bffb57 ("Btrfs: buffer results in the space_info ioctl") CC: stable@vger.kernel.org # 3.0 Signed-off-by: Yochai Eisenrich Reviewed-by: David Sterba Signed-off-by: David Sterba diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a4d715bbed57..b2e447f5005c 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2897,7 +2897,7 @@ static long btrfs_ioctl_space_info(struct btrfs_fs_info *fs_info, return -ENOMEM; space_args.total_spaces = 0; - dest = kmalloc(alloc_size, GFP_KERNEL); + dest = kzalloc(alloc_size, GFP_KERNEL); if (!dest) return -ENOMEM; dest_orig = dest; @@ -2953,7 +2953,8 @@ static long btrfs_ioctl_space_info(struct btrfs_fs_info *fs_info, user_dest = (struct btrfs_ioctl_space_info __user *) (arg + sizeof(struct btrfs_ioctl_space_args)); - if (copy_to_user(user_dest, dest_orig, alloc_size)) + if (copy_to_user(user_dest, dest_orig, + space_args.total_spaces * sizeof(*dest_orig))) return -EFAULT; out: