Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2502983rbb; Wed, 28 Feb 2024 04:07:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWAEdPUGtL4xh2sVqrFXLju9rir3ie+msvZFLZuHix2tXb5fT8ZXJlgjQNH4ZIWwXe3O9OTY2Z0aP3sqGLXo/Os0XeqddVgOcVoXVN8qQ== X-Google-Smtp-Source: AGHT+IFTundE485cgJHh7vVOL+ZmgUlt5Wg5cZ4fIC17SbF4bcwj1Uk/8nMOa6A4XjsV7UREwqIK X-Received: by 2002:a05:6402:e8c:b0:561:3b53:d0af with SMTP id h12-20020a0564020e8c00b005613b53d0afmr2251110eda.12.1709122030117; Wed, 28 Feb 2024 04:07:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709122030; cv=pass; d=google.com; s=arc-20160816; b=xqvqpgjsa+TOrgiViUSGSMGOCcdLp2OYeUVm8OeZpakZJ6GUNroXLNjTU/6HQHPGyi le4gsOe39L1iCXGPk8X3c0xi1+MYkuUkdmMGKRJQGelzH2/e/cD0LEx4p2KHXKbHiqIK BaiGfBwcjudpZ/99XquzcJYWmT1oIIPKuqsCAXvLvUxoAEVgGtuDpPLX1kjHDKq3KlKb HbckFL0w3+IhcKmtkd9OkSHPOaIRkXJVE5+R1Y3lzxws8nCiZ16f2m9j8rb9SA8aNt0U 9G1meSETtgDZ9Z0zh/N2vsfQRruF8aYxlocYJXFL5KarzlXp4ftOe3488jGmg6JyQrNa zq2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=DJFZAetVmC0jqCSPWDbRRaBD3njopELhDaq/3N3rDqY=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=IXqjD5sob8EMp/IneSV/al1YM6PaMgJrxElC1A5YcZzdH5oSEZxUTObvMiZtcOXTOz 9JAPTahvpFWxilGHbyxymlZEnaxReqBikg5qSaOTMJzxfbaNmt1HAEuyd+Yn+CcrK0X7 oUsnSOHS/T8N7swyTZyu3CKXBbGozCx8WWYxIwuqPMC2e+fHuZyWmEoabM/IyZi4yddW JwOveUBoPaz10oTVN0CT9NS3yRBeGhY7QO8z6ZXLyg/Mg3UFmjv/k5P1MbAQ8yKDYwav iSJwSYN3FjqOivNSHaCyorH9dPJnDaWja6nJQ028vbAE2Qa7ox3myKCJ6tcFMGWmWVlW ahNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-84987-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84987-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r18-20020a50c012000000b00564299247b9si1660610edb.120.2024.02.28.04.07.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 04:07:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84987-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-84987-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84987-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 194BE1F26E1F for ; Wed, 28 Feb 2024 12:01:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 609133BBC7; Wed, 28 Feb 2024 12:01:10 +0000 (UTC) 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 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 41SC05ID098352 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 --- 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 segno = GET_SEGNO(sbi, blkaddr); + if (segno == NULL_SEGNO) + return; se = get_seg_entry(sbi, segno); new_vblocks = 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) != NULL_SEGNO) - update_sit_entry(sbi, old_blkaddr, -1); + update_sit_entry(sbi, old_blkaddr, -1); /* * If the current segment is full, flush it out and replace it with a -- 1.9.1