Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1152503ybl; Sat, 17 Aug 2019 20:23:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqweVFO6j2RRHDJqiaN55mVB7Ez50CWy5fZzlqU7GMUO9L6zjnJltAPFTIp1wy8d5IJqSzOO X-Received: by 2002:a17:90a:d149:: with SMTP id t9mr13705709pjw.58.1566098638011; Sat, 17 Aug 2019 20:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566098638; cv=none; d=google.com; s=arc-20160816; b=iz9AX1WoNyrXhw2/xL3nr5L2GDpkpnHn51yHPed26pPuqXmW+LbffyPkZpdHt8sFcQ /vWJ7PTJDkg13Ijxg/O5+ke3i6/XDNqxFkyAv1+0MAVzJik9zUIgVNkD4rRLz64s9Fbq 0sbv0dCMaQDzD6DR/4T3XmdsAFzAzP//+u+CLzKoW8idMMZl4SDOoPg2fB+I9qau/8xa 1IGhdM4rbo+E4N+dfnH6VNTyKAsIVwgP0ALJrkaPvV8daN/eUethSQoro9do6/N+8ZvX 0Nlbp7gXmzoLP+uWqCnOLer86tJxpUsMQUniIQ0zMmVS5ECSjt27C4KjFOmsEtzvVxyb 49lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=VL+r3q3bHO+kJBlNK0FTX8eiBkYwN0lcRePyte3rpuA=; b=FIoic1cx2YZd3PKA6KBVsblWqApcGcg58DfA6XK3Lo+F4FsxNmziZHTUwB4RxW6Sda 4JMyd2H6nTyuQ0qhBTUOTYOKND6W4WkfNsk/Fdj+PvL1zgB7ez4//ouetreQ1HO2z889 +gBvbb7wcUxCpOQPizNnTT1+rw7hsmPcEf1riyvcnjYRqwHseyt4aoozN0Iyb5B22/22 cRezW6I32zDBgrM21MFHoW9+ZrtNAQ16D9BdWLC7VCUxZqj/HS4s3t7yqlvGvfsWWyqW OZlnuuBDK7hN2p5uR9uQCBt61J2fPfVIt97tv/J3hNVRbaDR/FFjThQOrf6uJaBeiuhM FvwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=kIAGp1nW; 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 c127si7584604pfc.191.2019.08.17.20.23.43; Sat, 17 Aug 2019 20:23:57 -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=kIAGp1nW; 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 S1726504AbfHRDV2 (ORCPT + 99 others); Sat, 17 Aug 2019 23:21:28 -0400 Received: from sonic303-19.consmr.mail.ir2.yahoo.com ([77.238.178.200]:38635 "EHLO sonic303-19.consmr.mail.ir2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726416AbfHRDV2 (ORCPT ); Sat, 17 Aug 2019 23:21:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1566098486; bh=VL+r3q3bHO+kJBlNK0FTX8eiBkYwN0lcRePyte3rpuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=kIAGp1nWCsOw/k1KQomjIlaawsK4/bzOKoPFXUuxOhrXsklJYDZTMJi7uvE6MLOTPsh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dybzwATfXZwsPVlL6j9V36OCyyo5QbGtKP 3MCO1vaa_5g3Kz0sQEEigyIGXqigw8mVg8mIfKtknC9DiivY6wg77QKWPdxFMuuXn6McCiq8QZoe FXBJD.xai6iwdA6WkHeSpwHP2MG4mIHBzkjS4.tzoALwvrt7xyicM2jQnvFtvhOVCXBRzdi1bw47 hhEcZTMSw0Vp48eXXk5tVYPwRGy0hBGk8M9UbSFdrCePl6_qtcgrCKa2Ga_r7P8K0UZBaH8dRxC_ EGd8h.2q1bq9tGtsB3a05CCzoyNaSt6dFT9ZbifDF.DLzToZNlR4hJWpgoKwXTkz6oODPKkYb9CP RC1KQ90QMjgiae99qSLe84w0lKgQV5gwiJWDfMbXc.Y2LDBVN1BINoQCkhlSTGsMqvPncaO3Xr23 ALaxLwowm4PRQtPjUDBs0lZWjsIYzwp1eHUWa5FOZJU8ZrBiK7YmOqVN5Kp3QnqWMv1YKqv55dZV Jz0cMAHHRIKk4aJ76MKwuDs2_mv3rMj0- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Sun, 18 Aug 2019 03:21:26 +0000 Received: by smtp408.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d0778e91ef06b470a11982e764e03f0c; Sun, 18 Aug 2019 03:21:25 +0000 (UTC) From: Gao Xiang To: Chao Yu , Richard Weinberger , Matthew Wilcox , Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org Cc: LKML , linux-erofs@lists.ozlabs.org, Chao Yu , Miao Xie , Fang Wei , Gao Xiang , stable@vger.kernel.org Subject: [PATCH v3 RESEND] staging: erofs: fix an error handling in erofs_readdir() Date: Sun, 18 Aug 2019 11:21:11 +0800 Message-Id: <20190818032111.9862-1-hsiangkao@aol.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190818030109.GA8225@hsiangkao-HP-ZHAN-66-Pro-G1> References: <20190818030109.GA8225@hsiangkao-HP-ZHAN-66-Pro-G1> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gao Xiang Richard observed a forever loop of erofs_read_raw_page() [1] which can be generated by forcely setting ->u.i_blkaddr to 0xdeadbeef (as my understanding block layer can handle access beyond end of device correctly). After digging into that, it seems the problem is highly related with directories and then I found the root cause is an improper error handling in erofs_readdir(). Let's fix it now. [1] https://lore.kernel.org/r/1163995781.68824.1566084358245.JavaMail.zimbra@nod.at/ Reported-by: Richard Weinberger Fixes: 3aa8ec716e52 ("staging: erofs: add directory operations") Cc: # 4.19+ Signed-off-by: Gao Xiang --- [RESEND] --> add the missing v3 version in subject, no logic change. changelog from v2: - transform EIO to EFSCORRUPTED as suggested by Matthew; changelog from v1: - fix the incorrect external link in commit message. This patch is based on the following patch as well https://lore.kernel.org/r/20190816071142.8633-1-gaoxiang25@huawei.com/ and https://lore.kernel.org/r/20190817082313.21040-1-hsiangkao@aol.com/ can still be properly applied after this patch. drivers/staging/erofs/dir.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/staging/erofs/dir.c b/drivers/staging/erofs/dir.c index 5f38382637e6..eb430a031b20 100644 --- a/drivers/staging/erofs/dir.c +++ b/drivers/staging/erofs/dir.c @@ -82,8 +82,17 @@ 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 (dentry_page == ERR_PTR(-ENOMEM)) { + errln("no memory to readdir of logical block %u of nid %llu", + i, EROFS_V(dir)->nid); + err = -ENOMEM; + break; + } else if (IS_ERR(dentry_page)) { + errln("fail to readdir of logical block %u of nid %llu", + i, EROFS_V(dir)->nid); + err = -EFSCORRUPTED; + break; + } de = (struct erofs_dirent *)kmap(dentry_page); -- 2.17.1