Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1554987ybl; Sun, 18 Aug 2019 05:56:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqw15JRQTqKxrydMbzTgjdVy14LKxienNeAbz29WAsRWtBvKaEq/h4VpX4naKoAHDecy6Uq5 X-Received: by 2002:a17:902:543:: with SMTP id 61mr17954882plf.20.1566132993270; Sun, 18 Aug 2019 05:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566132993; cv=none; d=google.com; s=arc-20160816; b=vQNlnaP8AKjJh8itrdrGXpcyK9hsUxPxq/37sScGcpWBXfLLtwnnsQzx3PCcO4CkoW aXR/twqlrrtf/AUZcQPjLQy99O9cZf5nnmMlI4gNOOQdJZN5UBrKUDZIVAcuL3rHsUGg URmpSiAlVOyUeb0wv0T4OLfTix0qIVTszs8rANNx1pCpCXvEhfv0r2h7z0HAKVFGBiZC DaXr9svEOlkHMBiR22xqsY+vFlDh53CmuT3HZjaU7/dvbiP1o0Z1wqmJRihFef3mFKVU yklAiGWMezrlsGnWTEkDV5zWxmzocczSok9KC6Hijxi5d1C9tT7HK5kfzfvfgGNOQ8zg nJWA== 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=jKgTuEY61Ia3/tSy7knI2OLWYhEXkTOsi1PJnFLa0EQ=; b=fhG/3K9KVNra8x4xtT2xCeBl22156FZP0/Igf0YeRZ+PKq9KT/w4z5Sj53l2gc3jL8 li/M52CytEx31v9s5Zsu6zUhbMIxl5ICXdtTE5d0CX42jvrLViNx2w+OFuefszU1ymtr 9RQ2Zx4YtiGcmOqn4XriK+kWtfP20S2IRpqnwqHnm3KCeoIizB44QkGHU41HLn84gRkY kB4lOLGqEWr+7U/XI9gTM6LiQU6nkOksFPCQ+wDdeYvwi9IHjGt6T4uuBbQbzTHmQ2U0 UcAjnbETBy8MnBxV7E8Q3ga2Ru55PkVTzsHYP+19dJPdMutWxb9Ge7z6Dyyxb5M3OXS/ JMjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=oazOFWB3; 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 s20si7749517pgi.499.2019.08.18.05.56.16; Sun, 18 Aug 2019 05:56:33 -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=oazOFWB3; 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 S1726649AbfHRMzY (ORCPT + 99 others); Sun, 18 Aug 2019 08:55:24 -0400 Received: from sonic304-22.consmr.mail.ir2.yahoo.com ([77.238.179.147]:42911 "EHLO sonic304-22.consmr.mail.ir2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725786AbfHRMzY (ORCPT ); Sun, 18 Aug 2019 08:55:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1566132921; bh=jKgTuEY61Ia3/tSy7knI2OLWYhEXkTOsi1PJnFLa0EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=oazOFWB3FynD6KvVTxwuFf1QKUr8XIVmw4nfNtrwh+B+lZXgs7WOyaLHjBysPnTXK47PdcRoCUjJ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GHZ1JP8vCaoX__uro02x2sW2C0z6uqm VLPpjtOPcK0q4y.teTI08sw2K0CcmDxhnnf6JZR_6sXDsQYSAnqtF8dGF4GtTTkdOUx22HRG4fTK 2229OQmJKRVBFKels66fPaTJuSKMGNL01vNAasfUTTVCbNo.JmgY58e_HnmC8iUFdLoc4jJrNOak _LuDoEFExE3d_97ffM0C0qqObZzG14_upCFGNDfgNwZA4BDefYMKQ3zYM4Y0_Iy4CnJA6ppdctsu Wrhk13prswf19UrPx6kibGpGiUDgXJFUNYmPiLHKPe1.m2wZOnOkwTNhLNCrr2pn1FNHlU3hX_IJ 5hBgFCUirjm9wSxLIu8hzrk.sGUkgNvAXuabk5M5d7bH_DQcdSJTYXekSSrQBqCptwIA5XwhXSK_ qz.KbTXbkZK2xhQW80ZwxEvCrEmdO5ITPT2IfbfEyGdpmxB03BwXjR3UszsllwFg6fpOsMAjaop3 cP97lIuOTaMcm1iHK2BXGN.5FK70wtZQXmg21xQq2 Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Sun, 18 Aug 2019 12:55:21 +0000 Received: by smtp422.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 1fc0e4804ad770b0a11e2771bf1d5885; Sun, 18 Aug 2019 12:55:18 +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 v4] staging: erofs: fix an error handling in erofs_readdir() Date: Sun, 18 Aug 2019 20:54:57 +0800 Message-Id: <20190818125457.25906-1-hsiangkao@aol.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190818123858.GA24535@hsiangkao-HP-ZHAN-66-Pro-G1> References: <20190818123858.GA24535@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+ Reviewed-by: Chao Yu Signed-off-by: Gao Xiang --- changelog from v3: - kill message when memory allocation fails as suggested by Matthew; [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 staging-testing tree 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/staging/erofs/dir.c b/drivers/staging/erofs/dir.c index 5f38382637e6..77ef856df9f3 100644 --- a/drivers/staging/erofs/dir.c +++ b/drivers/staging/erofs/dir.c @@ -82,8 +82,15 @@ 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)) { + 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