Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757347AbdLWDh3 (ORCPT ); Fri, 22 Dec 2017 22:37:29 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:40592 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1757161AbdLWDh2 (ORCPT ); Fri, 22 Dec 2017 22:37:28 -0500 Subject: Re: [PATCH v2] fsck.f2fs: check nid range before use to avoid segmentation fault To: Chao Yu , , , CC: , , , , , , References: <1513319174-114303-1-git-send-email-yunlong.song@huawei.com> <1513598025-160615-1-git-send-email-yunlong.song@huawei.com> From: Yunlong Song Message-ID: <88632fa0-ec8d-ecf0-656f-c52fbfdc9be2@huawei.com> Date: Sat, 23 Dec 2017 11:35:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.111.220.140] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 986 Lines: 38 Both are OK, since nid < root_ino cannot trigger segmentation fault (nat_block->entries[nid%NAT_ENTRY_PER_BLOCK]). On 2017/12/23 11:14, Chao Yu wrote: > On 2017/12/18 19:53, Yunlong Song wrote: >> Signed-off-by: Yunlong Song > How about introducing IS_AVAILABLE_NID as below, and use it instead? > > #define IS_AVAILABLE_NID(sbi, nid) (IS_VALID_NID(sbi, nid) && (nid >= root_ino)) > > Thanks, > >> --- >> fsck/fsck.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/fsck/fsck.c b/fsck/fsck.c >> index 11b8b0b..faf0663 100644 >> --- a/fsck/fsck.c >> +++ b/fsck/fsck.c >> @@ -740,7 +740,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid, >> for (idx = 0; idx < 5; idx++) { >> u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]); >> >> - if (nid != 0) { >> + if (nid != 0 && IS_VALID_NID(sbi, nid)) { >> struct node_info ni; >> >> get_node_info(sbi, nid, &ni); >> > > . > -- Thanks, Yunlong Song