Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1072845ybl; Sat, 17 Aug 2019 18:06:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqy34/t8pWz4ryj8CfLAVHpBvye88Z+SKhyPsEXVeWOFcXOATRDX8EAhLJEDi3wooAOJ/dkQ X-Received: by 2002:a17:902:be15:: with SMTP id r21mr15546223pls.293.1566090383845; Sat, 17 Aug 2019 18:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566090383; cv=none; d=google.com; s=arc-20160816; b=WrKoLR6oEuMPx/5RVbafAyn2CeXp9R/dLiC4t7mZG1YcdaG2drPBhZ0aL6gsBDPtmH aabVw7BAV+aV/eS45Ven0ZckzClDC+HNrTS8GgWH/0M/j0SPhYFi92BjQTCTFCPrHP3m ftxqbxJNH2xM7d7n23ajmUq6v2D0pnl585Zs1mDmkbUPy52MaEmX85ygFFa5ISGvAGF8 1wdB8dQzzdMm7yT8OLmwQfuvgY8o0mIM569H1pF5Xseuo2MuN6XNTyUpDg1cfOnnp8fJ qRfKIRYpUTZdim8yy3aSi5Ftq5X/WBsftCZKMicBSeoOJ6XJ/fn3eQDUmtuWdeCVhVhj 6l1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pBWBwyARZnrzm33VPsM+sotY6iI5K4m2Qacgfi12VPg=; b=04E93JvAKvgtbfRCc02uV6SDqrBjEnyGQR/RvUWYfECAxuW4FJl12b0QZFGf7BuRfG Mw7t196vAcRrZg2BnImuVDO5bb9fOIotb2kugGUEUg70MTP8Dt/7eufyAUuieQ2wJWJ2 igzlV8NEUvsg7SiCIx9/CeEttXlO8oQjn4OiAaH2IRkgz3Zt3DZHBdWCeJhS6YyVsYdy qpPHQUptgsTUX0U3rzv8MSTiViQ1p2OsHM7W0eJK/TwXvCtFWE0b6WxTYmoUjRJkWV/9 1dkDcQxghlMmqW1Px6fgoqbsZ2sSG3yfuWAxSxEclB/VmW+lpZ+5dbu/diU/YdTaKj73 hm9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=N8kGHyih; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si7372967pfb.132.2019.08.17.18.05.40; Sat, 17 Aug 2019 18:06:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=N8kGHyih; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbfHRAy0 (ORCPT + 99 others); Sat, 17 Aug 2019 20:54:26 -0400 Received: from sonic314-47.consmr.mail.ir2.yahoo.com ([77.238.177.173]:34838 "EHLO sonic314-47.consmr.mail.ir2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726097AbfHRAyZ (ORCPT ); Sat, 17 Aug 2019 20:54:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1566089662; bh=pBWBwyARZnrzm33VPsM+sotY6iI5K4m2Qacgfi12VPg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=N8kGHyihl8flFPtk1lEDvNKD7qeQrwa2VZG22wFLvMjekeH9ihFDMrlwOGDNyGYNGcTXvqxha5azq0xQM8TB9UDM6EfNh13tE0Vw7PlA65CZelCReG/Ng9VcyUeBJDf3/vrpfx/WDf3OHAz/Ut9ruvSkW9jmQtzfYcJWHbkZd+Lg4V7FVwK93qGUZuvPVWNsk7pP0mWFsQ8dvNYY1lP5XQKXyO0Fv921yZrTUmYrD4KWvTYfATBcEKiPHBa0OMMoZHZ1HCkbu/o4L5vi95XgUOr/OWcW7iWDh9AvW1fg9u67DJWhwZSFkDeKClwv7WQ1WWhO7J2uB2fkLbAT3WcYew== X-YMail-OSG: d7OXBJkVM1nW9fPWmebywH7Y56nwVgJNGgdGo3dOnKUoiafHfJGqeoMZ2Z1L63_ 1NCcUccshIblqErhprGtdqNBn5Id0FHAwByqLrJLy3D8- Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 18 Aug 2019 00:54:22 +0000 Received: by smtp405.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 97deb381fe076b668cd11f47aa9377ca; Sun, 18 Aug 2019 00:52:21 +0000 (UTC) Date: Sun, 18 Aug 2019 08:52:11 +0800 From: Gao Xiang To: Richard Weinberger Cc: Greg Kroah-Hartman , Al Viro , linux-fsdevel , devel , linux-erofs , linux-kernel , Andrew Morton , Stephen Rothwell , tytso , Pavel Machek , David Sterba , Amir Goldstein , Christoph Hellwig , Darrick , Dave Chinner , Jaegeuk Kim , Jan Kara , torvalds , Chao Yu , Miao Xie , Li Guifu , Fang Wei , Gao Xiang Subject: Re: [PATCH] erofs: move erofs out of staging Message-ID: <20190818005202.GA3088@hsiangkao-HP-ZHAN-66-Pro-G1> References: <20190817082313.21040-1-hsiangkao@aol.com> <1746679415.68815.1566076790942.JavaMail.zimbra@nod.at> <20190817220706.GA11443@hsiangkao-HP-ZHAN-66-Pro-G1> <1163995781.68824.1566084358245.JavaMail.zimbra@nod.at> <20190817233843.GA16991@hsiangkao-HP-ZHAN-66-Pro-G1> <20190818000408.GA20778@hsiangkao-HP-ZHAN-66-Pro-G1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190818000408.GA20778@hsiangkao-HP-ZHAN-66-Pro-G1> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 18, 2019 at 08:04:11AM +0800, Gao Xiang wrote: > On Sun, Aug 18, 2019 at 07:38:47AM +0800, Gao Xiang wrote: > > Hi Richard, > > > > On Sun, Aug 18, 2019 at 01:25:58AM +0200, Richard Weinberger wrote: > > [] > > > > > > > While digging a little into the code I noticed that you have very few > > > checks of the on-disk data. > > > For example ->u.i_blkaddr. I gave it a try and created a > > > malformed filesystem where u.i_blkaddr is 0xdeadbeef, it causes the kernel > > > to loop forever around erofs_read_raw_page(). > > > > I don't fuzz all the on-disk fields for EROFS, I will do later.. > > You can see many in-kernel filesystems are still hardening the related > > stuff. Anyway, I will dig into this field you mentioned recently, but > > I think it can be fixed easily later. > > ...I take a simple try with the following erofs-utils diff and > a directory containing enwik9 only, with the latest kernel (5.3-rc) > and command line is > mkfs/mkfs.erofs -d9 enwik9.img testdir. > > diff --git a/lib/inode.c b/lib/inode.c > index 581f263..2540338 100644 > --- a/lib/inode.c > +++ b/lib/inode.c > @@ -388,8 +388,7 @@ static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh) > v1.i_u.compressed_blocks = > cpu_to_le32(inode->u.i_blocks); > else > - v1.i_u.raw_blkaddr = > - cpu_to_le32(inode->u.i_blkaddr); > + v1.i_u.raw_blkaddr = 0xdeadbeef; > break; > } > > I tested the corrupted image with looped device and real blockdevice > by dd, and it seems fine.... > [36283.012381] erofs: initializing erofs 1.0 > [36283.012510] erofs: successfully to initialize erofs > [36283.012975] erofs: read_super, device -> /dev/loop17 > [36283.012976] erofs: options -> (null) > [36283.012983] erofs: root inode @ nid 36 > [36283.012995] erofs: mounted on /dev/loop17 with opts: (null). > [36297.354090] attempt to access beyond end of device > [36297.354098] loop17: rw=0, want=29887428984, limit=1953128 > [36297.354107] attempt to access beyond end of device > [36297.354109] loop17: rw=0, want=29887428480, limit=1953128 > [36301.827234] attempt to access beyond end of device > [36301.827243] loop17: rw=0, want=29887428480, limit=1953128 > [36371.426889] erofs: unmounted for /dev/loop17 > [36518.156114] erofs: read_super, device -> /dev/nvme0n1p4 > [36518.156115] erofs: options -> (null) > [36518.156260] erofs: root inode @ nid 36 > [36518.156384] erofs: mounted on /dev/nvme0n1p4 with opts: (null). > [36522.818884] attempt to access beyond end of device > [36522.818889] nvme0n1p4: rw=0, want=29887428984, limit=62781440 > [36522.818895] attempt to access beyond end of device > [36522.818896] nvme0n1p4: rw=0, want=29887428480, limit=62781440 > [36524.072018] attempt to access beyond end of device > [36524.072028] nvme0n1p4: rw=0, want=29887428480, limit=62781440 > > Could you give me more hints how to reproduce that? and I will > dig into more maybe it needs more conditions... I think I found what happened here... That is not a bug due to lack of check of on-disk ->u.i_blkaddr (seems block layer will handle access beyond end of device) but actually a bug of erofs_readdir: diff --git a/fs/erofs/data.c b/fs/erofs/data.c index fda16ec8863e..5b5f35d47370 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -329,6 +329,8 @@ static int erofs_raw_access_readpage(struct file *file, struct page *page) trace_erofs_readpage(page, true); + WARN_ON(1); + bio = erofs_read_raw_page(NULL, page->mapping, page, &last_block, 1, false); @@ -379,6 +381,8 @@ static int erofs_raw_access_readpages(struct file *filp, /* the rare case (end in gaps) */ if (unlikely(bio)) __submit_bio(bio, REQ_OP_READ, 0); + + WARN_ON(1); return 0; } diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 637d70108d59..ccca954438ed 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -80,8 +80,10 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) unsigned int nameoff, maxsize; dentry_page = read_mapping_page(mapping, i, NULL); - if (IS_ERR(dentry_page)) - continue; + if (IS_ERR(dentry_page)) { + err = PTR_ERR(dentry_page); + break; + } de = (struct erofs_dirent *)kmap(dentry_page); It's a forever loop due to error handling of the read_mapping_page above. I will fix that in another patch and thanks for your report! Thanks, Gao Xiang > > Thanks, > Gao Xiang > > > > > Thanks, > > Gao Xiang > > > > > > > > Thanks, > > > //richard