Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1911155yba; Mon, 15 Apr 2019 00:33:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMZugUaIhezmywTcrlSHIdSSr+ts+UNh0K5Rq/y04eZacBZsz3i0Bdwq/qICK2byGh8RfI X-Received: by 2002:aa7:800e:: with SMTP id j14mr12457252pfi.157.1555313627129; Mon, 15 Apr 2019 00:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555313627; cv=none; d=google.com; s=arc-20160816; b=d5IhGalwUAk8oLG6UPxVq2wSGIay4n7KL/ZjPlqrZz19qxeUfENGmH4yeCPHDHRu+f mneRkqtrlP6Kmm2YcyHagvHneUbvHPxbRSAAIlmu4pi39UKSKoWSxz8QC5WAipnjEcjW iU94sGsPzy5/nthwhn8B9DuvRN0kNEGgz784hI5FUHC//4aHedlpg/Po3SlXn/l9BuAs RGZHRR+aW+kEGttv8UMFSUXUxSk4Mpc9Zosk4g2MUIIaB7NH6vEHRwEPAlvsN/M+C0rL BuWa1kMIQr/JkUw+wzRPTTTk4FqKRUiSiCOEuekrKSadTc6OJJvJ0I+HJN+eZwIE937X cjNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=f+Fs/1XIbeqgibYqlSYxu2z16U15f9mTXEnAvUZg4ZI=; b=H80CgXI/mo1OjRbtUNtHlRlFTm2Dy8EyPUi6ufLvyPmDMU25MAaZlvRu9OZRxiO2OO SvKFhVYRFrRiCMuVEsYNpKnDam024fyWCpH6rIGqZHwsux01gw460mOki0F+SpIgjDsY tFLYkZghr09YRRmWu9LfCWi6/tLTd9/+DKACo6m8H6XKxR62FGoXhst8U+s3xgklZZ7d xNzYKuNcEsgNkFQ1phlLtDbkYvb4lxly8bQfHkfsM5fF6rwcgw0Jh4syoTF+u7Ba9Qxj DSQjXN5Adk2dZGRnb1G2aQ5tlQbDmifrpDGhrBs631agsmU/U2cHQpsTAhLaG3Y6faVL 2HcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si47819951pfb.68.2019.04.15.00.33.31; Mon, 15 Apr 2019 00:33:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbfDOHbZ (ORCPT + 99 others); Mon, 15 Apr 2019 03:31:25 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:45622 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725851AbfDOHbF (ORCPT ); Mon, 15 Apr 2019 03:31:05 -0400 Received: from DGGEMM404-HUB.china.huawei.com (unknown [172.30.72.53]) by Forcepoint Email with ESMTP id AA9E8B7DF60FF1B436AE; Mon, 15 Apr 2019 15:31:03 +0800 (CST) Received: from dggeme763-chm.china.huawei.com (10.3.19.109) by DGGEMM404-HUB.china.huawei.com (10.3.20.212) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 15 Apr 2019 15:31:03 +0800 Received: from szvp000201624.huawei.com (10.120.216.130) by dggeme763-chm.china.huawei.com (10.3.19.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 15 Apr 2019 15:31:02 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH 11/13] f2fs: fix to avoid panic in f2fs_inplace_write_data() Date: Mon, 15 Apr 2019 15:30:52 +0800 Message-ID: <20190415073054.2577-3-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 In-Reply-To: <20190415073054.2577-1-yuchao0@huawei.com> References: <20190415073054.2577-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-ClientProxiedBy: dggeme710-chm.china.huawei.com (10.1.199.106) To dggeme763-chm.china.huawei.com (10.3.19.109) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As Jungyeon reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203239 - Overview When mounting the attached crafted image and running program, following errors are reported. Additionally, it hangs on sync after running program. The image is intentionally fuzzed from a normal f2fs image for testing. Compile options for F2FS are as follows. CONFIG_F2FS_FS=y CONFIG_F2FS_STAT_FS=y CONFIG_F2FS_FS_XATTR=y CONFIG_F2FS_FS_POSIX_ACL=y CONFIG_F2FS_CHECK_FS=y - Reproduces cc poc_15.c ./run.sh f2fs sync - Kernel messages ------------[ cut here ]------------ kernel BUG at fs/f2fs/segment.c:3162! RIP: 0010:f2fs_inplace_write_data+0x12d/0x160 Call Trace: f2fs_do_write_data_page+0x3c1/0x820 __write_data_page+0x156/0x720 f2fs_write_cache_pages+0x20d/0x460 f2fs_write_data_pages+0x1b4/0x300 do_writepages+0x15/0x60 __filemap_fdatawrite_range+0x7c/0xb0 file_write_and_wait_range+0x2c/0x80 f2fs_do_sync_file+0x102/0x810 do_fsync+0x33/0x60 __x64_sys_fsync+0xb/0x10 do_syscall_64+0x43/0xf0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 The reason is f2fs_inplace_write_data() will trigger kernel panic due to data block locates in node type segment. To avoid panic, let's just return error code and set SBI_NEED_FSCK to give a hint to fsck for latter repairing. Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b59d1c85863b..8388d2abacb5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3184,13 +3184,18 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) { int err; struct f2fs_sb_info *sbi = fio->sbi; + unsigned int segno; fio->new_blkaddr = fio->old_blkaddr; /* i/o temperature is needed for passing down write hints */ __get_segment_type(fio); - f2fs_bug_on(sbi, !IS_DATASEG(get_seg_entry(sbi, - GET_SEGNO(sbi, fio->new_blkaddr))->type)); + segno = GET_SEGNO(sbi, fio->new_blkaddr); + + if (!IS_DATASEG(get_seg_entry(sbi, segno)->type)) { + set_sbi_flag(sbi, SBI_NEED_FSCK); + return -EFAULT; + } stat_inc_inplace_blocks(fio->sbi); -- 2.18.0.rc1