From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A3A7C433F5 for ; Sat, 8 Oct 2022 19:12:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F7976B0071; Sat, 8 Oct 2022 15:12:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A7756B0073; Sat, 8 Oct 2022 15:12:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86EEC6B0074; Sat, 8 Oct 2022 15:12:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 743CC6B0071 for ; Sat, 8 Oct 2022 15:12:32 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3FC681607A7 for ; Sat, 8 Oct 2022 19:12:32 +0000 (UTC) X-FDA: 79998728544.12.9F0269E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 195FA40031 for ; Sat, 8 Oct 2022 19:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jltrTTngI5+i4SrxqnMducvxr3z9ztoNRgWqy5Yg5Vc=; b=FRd/EQ0pfESUdqddbaFYYHkSOB knXxf8NqJUPmkij9EHZ/XMf1uihqgy6aFxGatF2c2c+MPn2VjCzjrauucZ3vvc4c6CRVWHuLvm2tn 9TzuHyTdj81e4OhdbxFP66MtBMudFWz6UC0AF1pPvbv1lnSQThfunqLZ7SZXlSxFlwFJSXF+X+Uju c4ganqrcx6NWXJMGsCJNKV8yrJT4xNALl0T0kaR3I0xoDUCh2jc6/PMlvcpVoKO5PQi7WhNx88LFe dQVbBEhO8W+0GqaA5MZutsAT4xuSEe+M4y0s3/hku4/n6Vr371DyP1UbUuYTIJdaG0RATIcBgwKqb W5L2d3/Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ohFFO-002tNm-Nv; Sat, 08 Oct 2022 19:12:30 +0000 Date: Sat, 8 Oct 2022 20:12:30 +0100 From: Matthew Wilcox To: Andrew Morton Cc: syzbot , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Vishal Moola Subject: Re: [syzbot] UBSAN: array-index-out-of-bounds in truncate_inode_pages_range Message-ID: References: <000000000000117c7505e7927cb4@google.com> <20220901162459.431c49b3925e99ddb448e1b3@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220901162459.431c49b3925e99ddb448e1b3@linux-foundation.org> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665256351; a=rsa-sha256; cv=none; b=bXcZNDYQpzcOkeI2Fj5LA8kZFZ7D2lC0alku4OCh9bs92zWl2athe9bDQOidvjVRGvRrGy OTb85x6u2I28Zj+YajxBlYvu+qbOYF2elbj+OSZFFNA0xl37M6NCmp+59sEzwYirnlKwC+ 1vywm3DyHVpx46tEodUxD1d1BEANH5U= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="FRd/EQ0p"; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665256351; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jltrTTngI5+i4SrxqnMducvxr3z9ztoNRgWqy5Yg5Vc=; b=28NLuFOyn2SsRzb4yo1mmgJQgxstJj5Z2qCNdAdNZi60A+ePDdB4b1T3djcO74sQzYCJV9 4zdq9uWo7Erft47PJRlokhnxBJBpJ0bBojhRbqjgD1LChnx8pBWS/MMEOoHbpxmweSGJgO 5hJYmrqEXH1U1+Ei9tNTBBdevlNWUEU= Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="FRd/EQ0p"; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Stat-Signature: uftinmq5hqbm65nqi45uiub44jdxcmuf X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 195FA40031 X-Rspam-User: X-HE-Tag: 1665256350-466596 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: On Thu, Sep 01, 2022 at 04:24:59PM -0700, Andrew Morton wrote: > On Wed, 31 Aug 2022 17:13:36 -0700 syzbot wrote: > > > Hello, > > > > syzbot found the following issue on: > > > > HEAD commit: 89b749d8552d Merge tag 'fbdev-for-6.0-rc3' of git://git.ke.. > > git tree: upstream > > console output: https://syzkaller.appspot.com/x/log.txt?x=14b9661b080000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=911efaff115942bb > > dashboard link: https://syzkaller.appspot.com/bug?extid=5867885efe39089b339b > > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 > > userspace arch: i386 > > > > Unfortunately, I don't have any reproducer for this issue yet. > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > Reported-by: syzbot+5867885efe39089b339b@syzkaller.appspotmail.com > > > > ntfs3: loop0: Different NTFS' sector size (1024) and media sector size (512) > > ntfs3: loop0: RAW NTFS volume: Filesystem size 0.00 Gb > volume size 0.00 Gb. Mount in read-only > > ================================================================================ > > UBSAN: array-index-out-of-bounds in mm/truncate.c:366:18 > > index 254 is out of range for type 'long unsigned int [15]' > > That's > > index = indices[folio_batch_count(&fbatch) - 1] + 1; > > I looked. I see no way in which fbatch.nr got a value of 255. NTFS is involved. I stopped looking at that point; it seems to be riddled with buffer overflows. > I must say, the the code looks rather hacky. Isn't there a more > type-friendly way of doing this? Looking at the three callers, they all want to advance index. We should probably pass &index instead of index and have find_lock_entries advance it for them. Vishal, want to take this on?