Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3169430pxx; Mon, 2 Nov 2020 01:39:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7H+FcEOePlBjEvmKFwtCKJnJI3QgL8FAS3tGVRYcLfk9siqh6W/+lR2OOonSH2fSJ2BtR X-Received: by 2002:aa7:d709:: with SMTP id t9mr589748edq.305.1604309999153; Mon, 02 Nov 2020 01:39:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604309999; cv=none; d=google.com; s=arc-20160816; b=OQXz+7UWHIJkUmDl8hjvtHuCK/qQcX23B3S9RBQQH6+L6M8uLb5s9Ia2HGgD6m+nci n2cAFOSVmYfjfz8lb7Ww5ozFA6fgyPtl/mo3v2uDDkpw+qiI71Pum35mBxW+U0zlB4ZR vxyPx4DCWUnd/1DpcFPAh0db4vmujMZhzAhRuPXOPpOzzW2YEiPaXKmX2qd0Ki3z5hTc OQrdW8IQaOvactEyrWz1h+vAsDUSJrlgktvsGrqZc+LnEaKRmEIPI2mIAKLRT2Uvi/nc EDM/3yp3UF0yV8XzyVRA5sKpn2JUoas11tEb5WbzS/eqKwzo+gdjKFekP3DYjybN246O Yz6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3lM/ZACqOWn22foPZ50T2eFxh6n4sh8EWmhPxsYN588=; b=H5dTwLtrxFpkjrEHfvNqtsdEH4tYPtMyeAnTNYkkGaW9FNiATg59OVGJNoMmyT4lhc SqsG6x2xU7kFqpvqeyCaVurrcM2qyPOVL3ToBd9zkm9z/DzMCKz5sItaGFlwSHcNROC6 Xcv8ZrtBP8Srj9Ay4azoo6f6UHO66gh5M6+Jo0vI3Oktoc+RdUM/XUldGeL589juS/O5 XOtTgF1nj3rUDAW69S/1p7IFmaootEhaEGM0b+PZdLUKh+3Q+DNB846X2XSSnHQsugmi ROb9O+P2iZTX8qtMrxDrgYTAJHky1E+zMtWwTFJjisAZRzxIbYS83WaLGubwSXnKXIE+ NZPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r15si10154526ejy.36.2020.11.02.01.39.36; Mon, 02 Nov 2020 01:39:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728359AbgKBJhW (ORCPT + 99 others); Mon, 2 Nov 2020 04:37:22 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:7007 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbgKBJhU (ORCPT ); Mon, 2 Nov 2020 04:37:20 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CPnrG0cfZzhf8M; Mon, 2 Nov 2020 17:37:18 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 2 Nov 2020 17:37:07 +0800 From: Chao Yu To: CC: , , , Chao Yu , kitestramuort Subject: [PATCH] f2fs: fix to seek incorrect data offset in inline data file Date: Mon, 2 Nov 2020 17:36:58 +0800 Message-ID: <20201102093658.37206-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As kitestramuort reported: F2FS-fs (nvme0n1p4): access invalid blkaddr:1598541474 [ 25.725898] ------------[ cut here ]------------ [ 25.725903] WARNING: CPU: 6 PID: 2018 at f2fs_is_valid_blkaddr+0x23a/0x250 [ 25.725923] Call Trace: [ 25.725927] ? f2fs_llseek+0x204/0x620 [ 25.725929] ? ovl_copy_up_data+0x14f/0x200 [ 25.725931] ? ovl_copy_up_inode+0x174/0x1e0 [ 25.725933] ? ovl_copy_up_one+0xa22/0xdf0 [ 25.725936] ? ovl_copy_up_flags+0xa6/0xf0 [ 25.725938] ? ovl_aio_cleanup_handler+0xd0/0xd0 [ 25.725939] ? ovl_maybe_copy_up+0x86/0xa0 [ 25.725941] ? ovl_open+0x22/0x80 [ 25.725943] ? do_dentry_open+0x136/0x350 [ 25.725945] ? path_openat+0xb7e/0xf40 [ 25.725947] ? __check_sticky+0x40/0x40 [ 25.725948] ? do_filp_open+0x70/0x100 [ 25.725950] ? __check_sticky+0x40/0x40 [ 25.725951] ? __check_sticky+0x40/0x40 [ 25.725953] ? __x64_sys_openat+0x1db/0x2c0 [ 25.725955] ? do_syscall_64+0x2d/0x40 [ 25.725957] ? entry_SYSCALL_64_after_hwframe+0x44/0xa9 llseek() reports invalid block address access, the root cause is if file has inline data, f2fs_seek_block() will access inline data regard as block address index in inode block, which should be wrong, fix it. Reported-by: kitestramuort Signed-off-by: Chao Yu --- fs/f2fs/file.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d898f1e2764b..89c451f09344 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -413,9 +413,14 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) goto fail; /* handle inline data case */ - if (f2fs_has_inline_data(inode) && whence == SEEK_HOLE) { - data_ofs = isize; - goto found; + if (f2fs_has_inline_data(inode)) { + if (whence == SEEK_HOLE) { + data_ofs = isize; + goto found; + } else if (whence == SEEK_DATA) { + data_ofs = offset; + goto found; + } } pgofs = (pgoff_t)(offset >> PAGE_SHIFT); -- 2.26.2