Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2077546ybp; Thu, 10 Oct 2019 01:47:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGNcl+jcnQd4XtdQ2ieUaTGx7meOQBDMtFWyTLGbFU5nZ9HKeCHZQyG3W0atmiQF6eULTM X-Received: by 2002:a17:906:3009:: with SMTP id 9mr7143767ejz.124.1570697223472; Thu, 10 Oct 2019 01:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697223; cv=none; d=google.com; s=arc-20160816; b=CIa1LO3DJsu+BT2WvkmLEIUn40GOI8Gko+nF1JhPL6XVWoMNCH9iujqlIKAXkh6tl0 M5ZYmbbPCuyvRWEe32LYvtgTg56b6dfyage2b6aFs48GaX8FqwV2FM0O5hL/qnBDlvDB ayyqVYb6kp8LKRdPVv0c3YzzxFX7nV7B3yIhXPpYRdlw+K7h09lJ1XP4ZxRIQjNGPyjx hBYImTdIQizj+JiQhPNE4Ugf4vLyKa36PaPp+jxT1S51TrFgXii6NBqlAmmgx1VKO5JW faKklm1pW5wJ9f0c+84lHiWHAKVEE2X/CwhnCWkCKMAJycf+vdZ8XqTA+EDZvYBTZqXI 99yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HMfOzoaXpKehktpfUhewIYA3uIQxLWEIgPBlzicV680=; b=FWF1F3gtQMKeGlqPVYeVQo62KgN3EpvohSH8XlM5rVRujtv4GJ7kUxdLQwp1wQukWT 9m5QlhtbsoSz9zgUJfoMtHl5L22BKKp6OaWlzGWwj2CVsv7RS6fUSGA/7rNGqIogpuGV pb4b3vvudHiD1N7S5S8PHV9cG9F+oLNVQpEqgMy9MLsUOoQ3IRY8/NUqulALtn1v7M0O CImiBX8Sj/dPB8aaj0P/fk5KUmOMgQ3Nv1Tbj0+ARmh3D+toigpH5NKHnhBgYBIrHNGc 2/z1+y9tCVIbTFgmcs1HNlGJuo2f8L4UzWm1lZUeVcbHA4mm1BT4xaL9NfjPoVPCFpNg QAbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YWyy48K0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25si2762671eds.40.2019.10.10.01.46.40; Thu, 10 Oct 2019 01:47:03 -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=@kernel.org header.s=default header.b=YWyy48K0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388162AbfJJIny (ORCPT + 99 others); Thu, 10 Oct 2019 04:43:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:48798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388809AbfJJInw (ORCPT ); Thu, 10 Oct 2019 04:43:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6968B2054F; Thu, 10 Oct 2019 08:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697031; bh=dUfoJ06dfJh7PJfwdIjVvdHLfqLkWv7LXNM+7K9/uJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWyy48K0zBnLTV9fdE1oygelk75bjkgu7AkalIYRe96P3ZlS/AuXrKsNbNPeHcDeT Nk17MokiIJvg5QoekydbXzD9MspY3dxyE+M4Xix1dd8xna2vzzLN5aSrvMyVXkltXs 9DHRdkgIstBau6nxKRLiNfL+7P6k/dFNRnhhtPEo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger , Chao Yu , Gao Xiang Subject: [PATCH 5.3 143/148] staging: erofs: fix an error handling in erofs_readdir() Date: Thu, 10 Oct 2019 10:36:44 +0200 Message-Id: <20191010083620.967516461@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gao Xiang commit acb383f1dcb4f1e79b66d4be3a0b6f519a957b0d upstream. 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 Link: https://lore.kernel.org/r/20190818125457.25906-1-hsiangkao@aol.com [ Gao Xiang: Since earlier kernels don't define EFSCORRUPTED, let's use original error code instead. ] Signed-off-by: Gao Xiang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/erofs/dir.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/drivers/staging/erofs/dir.c +++ b/drivers/staging/erofs/dir.c @@ -99,8 +99,15 @@ static int erofs_readdir(struct file *f, 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 = PTR_ERR(dentry_page); + break; + } de = (struct erofs_dirent *)kmap(dentry_page);