Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932256AbbBIDZS (ORCPT ); Sun, 8 Feb 2015 22:25:18 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:49358 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755625AbbBIDZQ (ORCPT ); Sun, 8 Feb 2015 22:25:16 -0500 X-AuditID: cbfee61b-f79d76d0000024d6-66-54d82891eb7f From: Chao Yu To: Jaegeuk Kim , Changman Lee Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: avoid data offset overflow when lseeking huge file Date: Mon, 09 Feb 2015 11:23:58 +0800 Message-id: <004501d04418$006f4360$014dca20$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdBEF8Dk8AiVRvp/SVuA29H4ctfluA== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRmVeSWpSXmKPExsVy+t9jQd2JGjdCDL4vsLC4tq+RyeLJ+lnM FpcWuVtc3jWHzYHFY9OqTjaP3Qs+M3n0bVnF6PF5k1wASxSXTUpqTmZZapG+XQJXxssnb9gK PvJVzD7+mK2B8TR3FyMnh4SAicSerhssELaYxIV769m6GLk4hASmM0qsuX6IBcL5wShx+XA7 M0gVm4CKxPKO/0wgtoiAl8Sk/SfAupkFPCQaO76zgtjCAp4Sd9fPA4uzCKhKvF10lxHE5hWw lHj6+ScThC0o8WPyPaheLYnN25pYIWx5ic1r3jJDXKQgsePsa0aIXXoSmzdMgKoXl9h45BbL BEaBWUhGzUIyahaSUbOQtCxgZFnFKJpakFxQnJSea6RXnJhbXJqXrpecn7uJERzUz6R3MK5q sDjEKMDBqMTDe+Hz9RAh1sSy4srcQ4wSHMxKIrxGH4FCvCmJlVWpRfnxRaU5qcWHGKU5WJTE eZXs20KEBNITS1KzU1MLUotgskwcnFINjG57L05oaPBOvH2j5tYJfd7v317wONwTYAwprfKL UfwuM4uRd0VA8f5NiaZGr9gOyjPsWlPyKaDn0SXeQ3M39VV73JD27Kxpkog9VvVnTvRFl6CJ c/2PM5b8f382UWB/476VDpzybzg+5HQvrrF6f/jtv6Br7gXymT+e3E24XT6h0/5UzrtEZSWW 4oxEQy3mouJEAIxoKTxmAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2099 Lines: 56 xfstest generic/285 complains our issue in lseeking huge file. Here is the detail output of generic/285: "./check -f2fs tests/generic/285 Ran: generic/285 Failures: generic/285 Failed 1 of 1 tests 10. Test a huge file for offset overflow 10.01 SEEK_HOLE expected 65536 or 8589934592, got 65536. succ 10.02 SEEK_HOLE expected 65536 or 8589934592, got 65536. succ 10.03 SEEK_DATA expected 0 or 0, got 0. succ 10.04 SEEK_DATA expected 1 or 1, got 1. succ 10.05 SEEK_HOLE expected 8589934592 or 8589934592, got 0. FAIL 10.06 SEEK_DATA expected 8589869056 or 8589869056, got 8589869056. succ 10.07 SEEK_DATA expected 8589869057 or 8589869057, got 8589869057. succ 10.08 SEEK_DATA expected 8589869056 or 8589869056, got 4294901760. FAIL" The reason of this issue is: We will calculate current offset through left shifting page-offset with PAGE_CACHE_SHIFT bits, but our page-offset is a type of unsigned long, its size is 4 bytes in 32-bits machine. So if our page-offset is bigger than (1 << 32 / pagesize - 1), result of left shifting will overflow. Let's fix this issue by casting type of page-offset to type of current offset: loff_t. Signed-off-by: Chao Yu --- fs/f2fs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5cbbc9a..7dc0ed8 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -357,7 +357,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) /* find data/hole in dnode block */ for (; dn.ofs_in_node < end_offset; dn.ofs_in_node++, pgofs++, - data_ofs = pgofs << PAGE_CACHE_SHIFT) { + data_ofs = (loff_t)pgofs << PAGE_CACHE_SHIFT) { block_t blkaddr; blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node); -- 2.2.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/