From nobody Sun Feb 8 18:19:10 2026 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 5BB4773507 for ; Wed, 28 Feb 2024 12:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709121669; cv=none; b=SU+SSN/no5+RJ/uDpuJ0c5SGEhbO4J20jLsT6S20VJZqQyOfYCg7K481Euw0AmbMxmfJUzqDk5HSEC/PMUbH8kV8s7kE9yVfS/mt3sgc04egJPVC7fDm/r3CQFB9ip0KEEVtYF/b9I23Me4JaAw/y7PUDF4XtU0T7QyCuf/MaFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709121669; c=relaxed/simple; bh=FrU6YwsdY8xv+w1+Fi+52JvqnVCKxp8qLyZLX9ksaLs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=tMja0hK9XEewAfg0+PRuZIBfWcqY44WlZhJkgmwM2C98z+AcT/QARAVAx7Vld9cdgQ4bQPrnENioNPZvFJ2QxzDTjdJjDhN1szRjiXyBaY603hT2zqHX9UijLzftfmtJbwGPE3yMQYH8qtN8XJES4sQc0B+4EJ+DAXBFWGRiFZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 41SC05ID098352; Wed, 28 Feb 2024 20:00:05 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4TlCZF1jW3z2KpclH; Wed, 28 Feb 2024 19:59:17 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 28 Feb 2024 20:00:04 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH] f2fs: fix to do sanity check in update_sit_entry Date: Wed, 28 Feb 2024 19:59:54 +0800 Message-ID: <1709121594-22314-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 41SC05ID098352 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If GET_SEGNO return NULL_SEGNO for some unecpected case, update_sit_entry will access invalid memory address, cause system crash. It is better to do sanity check about GET_SEGNO just like update_segment_mtime & locate_dirty_segment. Also remove some redundant judgment code. Signed-off-by: Zhiguo Niu Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c616e7a..f8a823f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2407,6 +2407,8 @@ static void update_sit_entry(struct f2fs_sb_info *sbi= , block_t blkaddr, int del) #endif =20 segno =3D GET_SEGNO(sbi, blkaddr); + if (segno =3D=3D NULL_SEGNO) + return; =20 se =3D get_seg_entry(sbi, segno); new_vblocks =3D se->valid_blocks + del; @@ -3504,8 +3506,7 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi= , struct page *page, * since SSR needs latest valid block information. */ update_sit_entry(sbi, *new_blkaddr, 1); - if (GET_SEGNO(sbi, old_blkaddr) !=3D NULL_SEGNO) - update_sit_entry(sbi, old_blkaddr, -1); + update_sit_entry(sbi, old_blkaddr, -1); =20 /* * If the current segment is full, flush it out and replace it with a --=20 1.9.1