From patchwork Sun Dec 1 01:58:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11268481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9334915AB for ; Sun, 1 Dec 2019 01:58:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F716208C3 for ; Sun, 1 Dec 2019 01:58:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="MufvndhX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F716208C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3D3756B0396; Sat, 30 Nov 2019 20:58:13 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 384286B0399; Sat, 30 Nov 2019 20:58:13 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29B376B039A; Sat, 30 Nov 2019 20:58:13 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0CC746B0396 for ; Sat, 30 Nov 2019 20:58:13 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id C297E181AEF0B for ; Sun, 1 Dec 2019 01:58:12 +0000 (UTC) X-FDA: 76214912424.21.suit02_47aced2024d36 X-Spam-Summary: 2,0,0,e72a69d8384abb24,d41d8cd98f00b204,akpm@linux-foundation.org,:akpm@linux-foundation.org:cai@lca.pw:chenjun102@huawei.com:hughd@google.com::mm-commits@vger.kernel.org:torvalds@linux-foundation.org:wangkefeng.wang@huawei.com,RULES_HIT:41:355:379:800:960:967:973:988:989:1260:1263:1345:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:2393:2525:2553:2559:2563:2682:2685:2693:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3866:3867:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6119:6238:6261:6653:7576:7875:7903:8660:9025:9036:9163:9545:10004:10913:11026:11473:11658:11914:12043:12048:12296:12297:12517:12519:12555:12679:12783:12895:12986:13148:13161:13229:13230:13846:13870:14181:14721:14849:21080:21324:21433:21451:21611:21627:21796:21819:21939:30029:30036:30054:30056:30070:30090,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral, Custom_r X-HE-Tag: suit02_47aced2024d36 X-Filterd-Recvd-Size: 3922 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Sun, 1 Dec 2019 01:58:12 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9205A205ED; Sun, 1 Dec 2019 01:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575165491; bh=7U814T7aIKNwCnIDPSbFK+hkgGtpf5VTYAlK4X6w/8Q=; h=Date:From:To:Subject:From; b=MufvndhX2TMgn2DkovLOm1Mly0U9IseWCqtGX/6Pz6i89GshgxfTQPufWPQyT5BTZ jrZd5qs3JN4G9FYrIX6MfFdnTeS7gcsQ4pT5NHWTtfAPKtWQpByuQ6NMtOfS9oA03t xhtY2Bg2NeQBKKWwQfuUwwP+2rOMWbLCWbZGtGaw= Date: Sat, 30 Nov 2019 17:58:11 -0800 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, cai@lca.pw, chenjun102@huawei.com, hughd@google.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, wangkefeng.wang@huawei.com Subject: [patch 152/158] mm/shmem.c: cast the type of unmap_start to u64 Message-ID: <20191201015811.1qCFcdjbI%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Chen Jun Subject: mm/shmem.c: cast the type of unmap_start to u64 In 64bit system. sb->s_maxbytes of shmem filesystem is MAX_LFS_FILESIZE, which equal LLONG_MAX. If offset > LLONG_MAX - PAGE_SIZE, offset + len < LLONG_MAX in shmem_fallocate, which will pass the checking in vfs_fallocate. /* Check for wrap through zero too */ if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0)) return -EFBIG; loff_t unmap_start = round_up(offset, PAGE_SIZE) in shmem_fallocate causes a overflow. Syzkaller reports a overflow problem in mm/shmem: UBSAN: Undefined behaviour in mm/shmem.c:2014:10 signed integer overflow: '9223372036854775807 + 1' cannot be represented in type 'long long int' CPU: 0 PID:17076 Comm: syz-executor0 Not tainted 4.1.46+ #1 Hardware name: linux, dummy-virt (DT) Call trace: [] dump_backtrace+0x0/0x2c8 arch/arm64/kernel/traps.c:100 [] show_stack+0x20/0x30 arch/arm64/kernel/traps.c:238 [] __dump_stack lib/dump_stack.c:15 [inline] [] ubsan_epilogue+0x18/0x70 lib/ubsan.c:164 [] handle_overflow+0x158/0x1b0 lib/ubsan.c:195 [] shmem_fallocate+0x6d0/0x820 mm/shmem.c:2104 [] vfs_fallocate+0x238/0x428 fs/open.c:312 [] SYSC_fallocate fs/open.c:335 [inline] [] SyS_fallocate+0x54/0xc8 fs/open.c:239 The highest bit of unmap_start will be appended with sign bit 1 (overflow) when calculate shmem_falloc.start: shmem_falloc.start = unmap_start >> PAGE_SHIFT. Fix it by casting the type of unmap_start to u64, when right shifted. This bug is found in LTS Linux 4.1. It also seems to exist in mainline. Link: http://lkml.kernel.org/r/1573867464-5107-1-git-send-email-chenjun102@huawei.com Signed-off-by: Chen Jun Reviewed-by: Andrew Morton Cc: Hugh Dickins Cc: Qian Cai Cc: Kefeng Wang Signed-off-by: Andrew Morton --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/shmem.c~mm-cast-the-type-of-unmap_start-to-u64 +++ a/mm/shmem.c @@ -2747,7 +2747,7 @@ static long shmem_fallocate(struct file } shmem_falloc.waitq = &shmem_falloc_waitq; - shmem_falloc.start = unmap_start >> PAGE_SHIFT; + shmem_falloc.start = (u64)unmap_start >> PAGE_SHIFT; shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT; spin_lock(&inode->i_lock); inode->i_private = &shmem_falloc;