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=1795057838; b=FqYP0kyrQKVZN3RaSdfxK2Y3CElyNIAgLsG1i+63ZvnK8sE2Jo4epjD5LTYqqlOsAqS/ PdiHCmRB0/hAcclrVdFfrwqHxDxoNKTPeMofStJUpUp2C9Gi+lGrV8FEDXcFyQTsCnqOi HybWdIalWfgHOA3fRnjp8Mnt5amPBW0X7TetE4JWXqRAYF7E56/AQ3UIlsnYqglPBY9k0 ZRTgrtsHnBCe+7T6enIwBMSaNenMuXPSyH4FPzi4XEaThjnQcFDKb4IgUqz4eQgJrfsFj uXrK/zj/6cJzXvVf4VHPJDttWliS7v2jSTNKQyGMwc6yKoto8rFgFquaKIXOTLSu5Dw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795057838; 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=O4tBuearqnmCc2jTcLSbI3Y9z7nW7kfRB2/823uZfLY=; b=Fdvny02YiBPPVBbg6F2qzAJMNUM9gkdqglOCOfijGAhWjZPI4FOGnDhKP0NyQeQ56RNp 7ZhtYxu5RxynHoIoxsUZ3H6NSTvY8wQuNrVvGoIE2JqscVyziIU0n8Agd/eP4tegCgMzu TosC9sTzKBY6RdqL81olRkQmSlDIOi/NXD79KLn5VLGtdpdmHwg+rjjlyBBXmgbFJRdqF eo8fum01T+3oEyjUin1AFVncgFWfSgIOF4bKkejN2D0jnPbvYp7XULH8fglaWcvJ/iiKT DE3vWSzmzRNOevypbXgaBb7yRXSI+v+NR69hSMA7DFN9kQKeL0poPNHsCpQKinqK43g== 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=GY5tDbP7; 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 C1A8A606A320; Thu, 19 Nov 2026 03:10:38 +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=GY5tDbP7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D60E1F000C4; Thu, 19 Nov 2026 03:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795057838; bh=O4tBuearqnmCc2jTcLSbI3Y9z7nW7kfRB2/823uZfLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GY5tDbP7EMtCz/UQqoVkcjGwCYqW04eadOGWtG4EGVUv5Oo3uwXOORH0r8xY6uggI 4l7FAcEDTjRnxv3b9bgJ3L+BlrnDkSKul9w2tJFgmvspZ8sI8BM5txl9qpzP9g4L3H Yhe9sTTH6SejZbsvM6Q7/ZV9H1KlIT2VXTw1a61E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Al Viro , Joseph Qi , Sasha Levin Subject: [PATCH 5.10 0273/1848] ufs: fix ufs_read_cylinder() failure handling Date: Wed, 18 Nov 2026 15:38:31 +0100 Message-ID: <20261118145923.696307176@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Al Viro commit 0bfd3e1078c537cd66a8addb1c01835de4234a4c upstream. 1) ufs_load_cylinder() should return NULL on ufs_read_cylinder() failures. ufs_error() is not enough. As it is, IO failure on attempt to read a part of cylinder group metadata is likely to end up with an oops. 2) we drop the wrong buffer heads when undoing sb_bread() on IO failure halfway through the read - we need to brelse() what we've got from sb_bread(), TYVM... Signed-off-by: Al Viro Signed-off-by: Joseph Qi Signed-off-by: Sasha Levin --- fs/ufs/cylinder.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/fs/ufs/cylinder.c b/fs/ufs/cylinder.c index 5781c7db97276..b930ee1cf8530 100644 --- a/fs/ufs/cylinder.c +++ b/fs/ufs/cylinder.c @@ -26,7 +26,7 @@ * Read cylinder group into cache. The memory space for ufs_cg_private_info * structure is already allocated during ufs_read_super. */ -static void ufs_read_cylinder (struct super_block * sb, +static bool ufs_read_cylinder(struct super_block *sb, unsigned cgno, unsigned bitmap_nr) { struct ufs_sb_info * sbi = UFS_SB(sb); @@ -46,9 +46,11 @@ static void ufs_read_cylinder (struct super_block * sb, * We have already the first fragment of cylinder group block in buffer */ UCPI_UBH(ucpi)->bh[0] = sbi->s_ucg[cgno]; - for (i = 1; i < UCPI_UBH(ucpi)->count; i++) - if (!(UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i))) + for (i = 1; i < UCPI_UBH(ucpi)->count; i++) { + UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i); + if (!UCPI_UBH(ucpi)->bh[i]) goto failed; + } sbi->s_cgno[bitmap_nr] = cgno; ucpi->c_cgx = fs32_to_cpu(sb, ucg->cg_cgx); @@ -77,13 +79,14 @@ static void ufs_read_cylinder (struct super_block * sb, goto failed; } UFSD("EXIT\n"); - return; + return true; failed: for (j = 1; j < i; j++) - brelse (sbi->s_ucg[j]); + brelse(UCPI_UBH(ucpi)->bh[j]); sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY; ufs_error (sb, "ufs_read_cylinder", "can't read cylinder group block %u", cgno); + return false; } /* @@ -166,15 +169,14 @@ struct ufs_cg_private_info * ufs_load_cylinder ( UFSD("EXIT (FAILED)\n"); return NULL; } - else { - UFSD("EXIT\n"); - return sbi->s_ucpi[cgno]; - } } else { - ufs_read_cylinder (sb, cgno, cgno); - UFSD("EXIT\n"); - return sbi->s_ucpi[cgno]; + if (unlikely(!ufs_read_cylinder (sb, cgno, cgno))) { + UFSD("EXIT (FAILED)\n"); + return NULL; + } } + UFSD("EXIT\n"); + return sbi->s_ucpi[cgno]; } /* * Cylinder group number cg is in cache but it was not last used, @@ -205,7 +207,10 @@ struct ufs_cg_private_info * ufs_load_cylinder ( sbi->s_ucpi[j] = sbi->s_ucpi[j-1]; } sbi->s_ucpi[0] = ucpi; - ufs_read_cylinder (sb, cgno, 0); + if (unlikely(!ufs_read_cylinder (sb, cgno, 0))) { + UFSD("EXIT (FAILED)\n"); + return NULL; + } } UFSD("EXIT\n"); return sbi->s_ucpi[0]; -- 2.53.0