From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 30 Sep 2016 11:02:47 +1000 From: Dave Chinner To: Christoph Hellwig Cc: Wei Fang , viro@ZenIV.linux.org.uk, akpm@linux-foundation.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [RFC][PATCH] vfs,mm: fix a dead loop in truncate_inode_pages_range() Message-ID: <20160930010247.GQ9806@dastard> References: <1475151010-40166-1-git-send-email-fangwei1@huawei.com> <20160929134357.GA11463@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160929134357.GA11463@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: On Thu, Sep 29, 2016 at 06:43:57AM -0700, Christoph Hellwig wrote: > Can you please add a testcase for this to xfstests? Seems like a copy of tests/xfs/071 (exercises read/write at the highest page of the page cache) with an added ftruncate as a generic tests would be a good start? Cheers, Dave. -- Dave Chinner david@fromorbit.com -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Subject: Re: [RFC][PATCH] vfs,mm: fix a dead loop in truncate_inode_pages_range() To: Christoph Hellwig References: <1475151010-40166-1-git-send-email-fangwei1@huawei.com> <20160929134357.GA11463@infradead.org> CC: , , , , From: Wei Fang Message-ID: <57EDB7C1.9040606@huawei.com> Date: Fri, 30 Sep 2016 08:54:25 +0800 MIME-Version: 1.0 In-Reply-To: <20160929134357.GA11463@infradead.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: OK, I'll do this. Thanks, Wei On 2016/9/29 21:43, Christoph Hellwig wrote: > Can you please add a testcase for this to xfstests? > > Thanks! > > . > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 29 Sep 2016 06:43:57 -0700 From: Christoph Hellwig To: Wei Fang Cc: viro@ZenIV.linux.org.uk, akpm@linux-foundation.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [RFC][PATCH] vfs,mm: fix a dead loop in truncate_inode_pages_range() Message-ID: <20160929134357.GA11463@infradead.org> References: <1475151010-40166-1-git-send-email-fangwei1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1475151010-40166-1-git-send-email-fangwei1@huawei.com> Sender: owner-linux-mm@kvack.org List-ID: Can you please add a testcase for this to xfstests? Thanks! -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Wei Fang To: , CC: , , Wei Fang , Subject: [RFC][PATCH] vfs,mm: fix a dead loop in truncate_inode_pages_range() Date: Thu, 29 Sep 2016 20:10:10 +0800 Message-ID: <1475151010-40166-1-git-send-email-fangwei1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: We triggered a deadloop in truncate_inode_pages_range() on 32 bits architecture with the test case bellow: ... fd = open(); write(fd, buf, 4096); preadv64(fd, &iovec, 1, 0xffffffff000); ftruncate(fd, 0); ... Then ftruncate() will not return forever. The filesystem used in this case is ubifs, but it can be triggered on many other filesystems. When preadv64() is called with offset=0xffffffff000, a page with index=0xffffffff will be added to the radix tree of ->mapping. Then this page can be found in ->mapping with pagevec_lookup(). After that, truncate_inode_pages_range(), which is called in ftruncate(), will fall into an infinite loop: * find a page with index=0xffffffff, since index>=end, this page won't be truncated * index++, and index become 0 * the page with index=0xffffffff will be found again The data type of index is unsigned long, so index won't overflow to 0 on 64 bits architecture in this case, and the dead loop won't happen. Since truncate_inode_pages_range() is executed with holding lock of inode->i_rwsem, any operation related with this lock will be blocked, and a hung task will happen, e.g.: INFO: task truncate_test:3364 blocked for more than 120 seconds. ... [] call_rwsem_down_write_failed+0x17/0x30 [] generic_file_write_iter+0x32/0x1c0 [] ubifs_write_iter+0xcc/0x170 [] __vfs_write+0xc4/0x120 [] vfs_write+0xb2/0x1b0 [] SyS_write+0x46/0xa0 The page with index=0xffffffff added to ->mapping is useless. Fix this by checking the read position before allocating pages. Cc: stable@vger.kernel.org Signed-off-by: Wei Fang --- mm/filemap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 1345f09..6946346 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1674,6 +1674,10 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos, unsigned int prev_offset; int error = 0; + if (unlikely(*ppos >= inode->i_sb->s_maxbytes)) + return -EINVAL; + iov_iter_truncate(iter, inode->i_sb->s_maxbytes); + index = *ppos >> PAGE_SHIFT; prev_index = ra->prev_pos >> PAGE_SHIFT; prev_offset = ra->prev_pos & (PAGE_SIZE-1); -- 1.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org