Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1151245ybl; Sat, 17 Aug 2019 20:21:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHPuq513pRi+JlN2yQZSWIfIx4FmFDLwG/Qz9lWDawWNNGUC0L3/qpEtoRKZocCZKdXYMY X-Received: by 2002:a17:902:b905:: with SMTP id bf5mr15280602plb.342.1566098504122; Sat, 17 Aug 2019 20:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566098504; cv=none; d=google.com; s=arc-20160816; b=hs7wHGOpT3M747F01QGAjZKl4fFLe/4qh5wNZPG4l0q+GZL7IrxWp3kKos09Dzc+8c cYPWkbTCR0uKmXn+CMPLy2HlC/LTW7BRYYj1vwPnUvm5S5Ao08qDdwULUzRHH67WrutU 4q6hxK/zOsuhLxQA5Xz84a1CEebfM9OHspUs8BCvZyNqkk4Ubtjvvfj0+WDwCBwLscuA rO/SOO3M/PpNtqEruizKfKkrHYsWMzh25qs5qZKgkHvSEzre4sUX+jI1SyVP6xk2uWUe aXkFBBA9Ki9al5cz0I284hc5y12nXtXHU64jazWwwRA7oeQFAqvlUY4DtCP7dDXZ9hLi z0TA== 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=kcWMxbdQGZI1Ki+C3vmBFZF1GbOm6oYitbF6P/0gDu8=; b=k92tdduZoD3s9u1Z5cJIlx/jfle6nYfROeuJGpKIS8u0clTd4GDdVL5zj0pCL5vTEH DUW9KgSx02g3EB9Fti4XQHzcmsMVlSFvQsYRWkytyo7+pJ1BKu2jmy2so/pr2E1VCTO6 /p5P9lJMjeno+wRMmGt88B138oGNy7qEtQSAFpUvH6138JbbbsvhZq68Ouqo7Fytmd5v IVUI+rS+qkxuxEorTxePZ20JdI8QdLP8YL4CBSZe4mUz3zNa8OL58ZQ6BBejgQlNekFP 2wn21bHuSpAnygl/woo5RJk2ul3TuJg7EmaWadZEBVnyUufuOD7fiL0/D+BVxjvfod/X x2iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=kZV5VM6c; 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 a186si6877834pge.365.2019.08.17.20.21.17; Sat, 17 Aug 2019 20:21:44 -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=kZV5VM6c; 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 S1726351AbfHRDT1 (ORCPT + 99 others); Sat, 17 Aug 2019 23:19:27 -0400 Received: from sonic309-22.consmr.mail.gq1.yahoo.com ([98.137.65.148]:44208 "EHLO sonic309-22.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726215AbfHRDT0 (ORCPT ); Sat, 17 Aug 2019 23:19:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1566098365; bh=kcWMxbdQGZI1Ki+C3vmBFZF1GbOm6oYitbF6P/0gDu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=kZV5VM6cLvFxjQP2mcKTMF88r23oUK3sIvk4uIGh9vL+rYIBc+N8zN8/KVMR23b6GsuP4tcoujVCCP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Wwpo0RSIAi1gtnuGNWEEN6wbcbD ZCg_yFXw7sRu2FFFXF0BIqLjSi0XwD0FyDzSl4Ymwkto8NWDLWUqhvAGQ41mBeMajhfmBMEHDV5t 073G2MWQkV4DdrextI2DfgkiYCQNwYu1YjJi8Tw_CDv3nl31uOKPeexl0YSwda1UvZMnzOokYIrZ 8tdkdnuduz08LFb3N3I_JWnSAslaE14_BqgLkcECpqDT8mpuyLglJBr_f8ugprkPwrs5boE12c8c yniou.57ldkNqglV.nqKkU0dVknyebLOFsyX4Kx6uELwvRVNxfwchSaFXKkPlOszJNek12tR9YL8 Dt4HEdwdngzQPIF_.duAPM5nnxZMbF.6fxWKz97L0rnKr8ofhntdUZ5wS7NnsRz3h8V0P5_MYDvy I3lS8GZKeIwgdJeJIO81zGomSoz5PgJu6CCzuNSqArozCx2ATBdN1Hn0yhslaCS7Qp..HIqj_XQd r3M_orrz5zM0wvum7KCU89JZG7ey8qTs- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Sun, 18 Aug 2019 03:19:25 +0000 Received: by smtp408.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID a3b7a5fc66b8e7b96dca9858a77755c0; Sun, 18 Aug 2019 03:19:21 +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] staging: erofs: fix an error handling in erofs_readdir() Date: Sun, 18 Aug 2019 11:18:55 +0800 Message-Id: <20190818031855.9723-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 --- 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