From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387835; b=AqM0Mpl01emduyz9+nXKbGygbelblH9UE4FMcA+lSFAhvBSg9jOj3kq2uz3Pb47PuwMe XplJZcFZZqcyHUjR/vaXVqxCjohCnWpFrSUb4FXcx0QnfoY1bdrZx7KpIKy8LjYED986L 3QREdclWwYsWir2K1Nctmj2Y8Oy7OCt1wFd1lkfGHr8PMrHY76HnygHOolB2hxBI/Z8v+ Wu74K48wJUUkbqkNdmAYTbTNf0enXj6Gh9jny67Q0FmvNSc9x1KWgP7IVH7viBN3P4H6E AQwlbrEsS6KnOio/11DgYePBrENNAQjyektbmwQ/Gf5a2M+jlDxW/86cRxqeGTqLlIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387835; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=PZThVWeaJPbLRRl8Qe0pwf7FB4JU4M+68eFx84KSjmA=; b=p5PMfDoEtojOOK3q+NYDWeCRqC2Pm/qudbEcP2/8sejPphjbR67w59rIwgl2i5LA3eJQ qJOHBb4qkYRXhH5bqUpwTQ+r+VM5TAaeqpNC+adrxpc8xsIgd+iAIJ3zfVTCo+fSGsup0 M+RnblClBSWz/zRa8WT/bD0ULeBwQu9FyQ3SuQhfIeD4x9Vn05W08gxANcEicxiVgDRUU DrxE446z3a82/Ujpw3UV33UT58bPLPp2FjrGmxAfv2aasfiVaI34ibS1V3Yuq3kKuk0F4 3uu0rnohpwCJa81SDGVaFtsBjLlzEI3v5xh9yv4SciCiCGhNs+lKjw44EIkCW6wOx2w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XeS4kcUJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89F48606A322; Fri, 4 Dec 2026 12:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XeS4kcUJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0009B1F000C2; Fri, 4 Dec 2026 12:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387835; bh=PZThVWeaJPbLRRl8Qe0pwf7FB4JU4M+68eFx84KSjmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XeS4kcUJPnyoaCjL+Cr24aT1KiPQqFUXfA81ckgrTTb8kPiQSbFBoaTdnmGw0THbu SsUHnu+kwgDpjFIUqbQAgaDdZe727ZCgaTmPGXdVtVjvlNVX660dR0FnKYkw5N4CRg soa7/pC6vMzT/eyypdAqrbl1z8L+MC9DN9dazZIE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qu Wenruo , Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 6.1 0378/1059] btrfs: fix incomplete iteration over fs state when logging messages Date: Fri, 4 Dec 2026 18:58:29 +0900 Message-ID: <20261204100654.081297038@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana [ Upstream commit d1d74665ab9a8971d42177ca865cfbe2897c1fc7 ] In btrfs_state_to_string() we iterate over all the bits set in fs_info->fs_state using for_each_set_bit(), which requires its third argument to match the number of bits, but we pass it the number of bytes of the type used by fs_info->fs_state, an unsigned long, which is 8 on 64 bits platforms and 4 on 32 bits platforms. This means we are not iterating over bits in the ranges [8, 63] or [4, 31]. Fix this by passing BTRFS_FS_STATE_COUNT instead of sizeof(fs_state). Note that we could pass BITS_PER_TYPE(fs_state), but since BTRFS_FS_STATE_COUNT is 11 and we have no bits beyond that, it would cause pointless iterations over fs_state. This also makes pointless the checks for the bit being inside the limit of BTRFS_FS_STATE_COUNT inside the loop. Fixes: c067da878156 ("btrfs: add filesystems state details to error messages") Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Signed-off-by: David Sterba [ sashal: Applied the fix to btrfs_state_to_string() in super.c because messages.c doesn't exist here, and the surrounding context differs slightly. ] Signed-off-by: Sasha Levin --- fs/btrfs/super.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 3b8afd05e3748..3dcf785e56137 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -97,9 +97,8 @@ static void btrfs_state_to_string(const struct btrfs_fs_info *info, char *buf) memcpy(curr, STATE_STRING_PREFACE, sizeof(STATE_STRING_PREFACE)); curr += sizeof(STATE_STRING_PREFACE) - 1; - for_each_set_bit(bit, &fs_state, sizeof(fs_state)) { - WARN_ON_ONCE(bit >= BTRFS_FS_STATE_COUNT); - if ((bit < BTRFS_FS_STATE_COUNT) && fs_state_chars[bit]) { + for_each_set_bit(bit, &fs_state, BTRFS_FS_STATE_COUNT) { + if (fs_state_chars[bit]) { *curr++ = fs_state_chars[bit]; states_printed = true; } -- 2.53.0