Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp203306ybm; Thu, 28 May 2020 20:40:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwijdEdUgfc9pf+jQsYRD7O3TQ38AlVlBLbW0nJROdsLbIfOIl4ARJT59WKVw1f15Zeflh6 X-Received: by 2002:a50:858d:: with SMTP id a13mr6282319edh.239.1590723643782; Thu, 28 May 2020 20:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590723643; cv=none; d=google.com; s=arc-20160816; b=LyVfPbyxaalue7AoUp9zXQQBK9cLv/I4efBbyplCZx7hMPs8tN5uJQADov5HMHVfM7 r3w1Q7YcYjoIAHMdjCDPTE7zIpJgkF6qXkppzoYLtc8JK44HDwKfiR01+1kI3ZpMf0sm jZpWtSnmYyJhxLlTDNqTvrRV39ZiQ3UTAS7UKbHpYmrT86LVXXmPkAFR7rEL3nJGLCMd eu0NGLdZPaRZw6G2bpGHsK8F4Z2jHGzvQ1P8Qh2R7p3Ix2LDhEtlt5ECwRe3njE01un4 txPY3vYBPu9Wqg/oq8mLMN5DfPmTpy/v25tB/eVPQJiPd4Ngk7x+AlSohExmrkshU4S+ uYqw== 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 :message-id:date:subject:to:from; bh=+tJg9cXpUuzow82K7JXpPGJpGifNXijYpYMOFvrF/5U=; b=It24+HBX7ZmDTzQNkQqB55RKy/JngiPwm/WIrQGHIB5x3JTdQ70w95rXJgExjQ1CjC 0XYIvXZ33FgPv9QGASLgEu+qbnR0FvU0b3HdCt+Q/qqn2/jopSsIAy2f4TFc6Ar1X1Q7 9fseBoTtOQ/5T75njabIlxBscbflndP1ejk5dokELE+TidlskY9e0FbnaTbyB+Wq5s66 81/qNbsGqcuqIjZnhCUAi1iNRHpOloXMUnmWqgG8RemTzFS1+mWxFzArQ7OGQsBKT/c1 OwlS03lSlKkIF+O2ana6K65maLUjGEkKjSS62iTWoM76dreW87wYb7v8fPPAvggOs+81 g+Ig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si4951470ejo.329.2020.05.28.20.40.20; Thu, 28 May 2020 20:40:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436936AbgE2DiS (ORCPT + 99 others); Thu, 28 May 2020 23:38:18 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5386 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2436641AbgE2DiR (ORCPT ); Thu, 28 May 2020 23:38:17 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 63E0621DD35E910CA2B7; Fri, 29 May 2020 11:38:13 +0800 (CST) Received: from DESKTOP-FKFNUOQ.china.huawei.com (10.67.101.2) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Fri, 29 May 2020 11:38:11 +0800 From: Zhe Li To: , , Subject: [PATCH] jffs2: fix nothing output for "ls" command Date: Fri, 29 May 2020 11:38:09 +0800 Message-ID: <20200529033809.113516-1-lizhe67@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.101.2] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Recently I find a bug that I get nothing with shell command "ls". The test steps are listed below. 1. cd $JFFS2_MOUNT_DIR 2. touch file 3. ls Finally I find that when command "ls" going into function jffs2_readdir(), it get non-zero return value from function dir_emit(). So I get nothing from "ls", absolutely. After checking my file system image, I find a raw dirent node with nsize = 0. The full_scan mounting process do not check nsize and the return value of strnlen(rd->name, rd->nsize) carefully, which causes function jffs2_readdir pass 0 to parameter namelen of function dir_emit when we use command "ls". Of course it should never happened to find a raw dirent with nsize = 0. In my opinion, this abnormal phenomenon maybe cause by bad driver or bad medium. But for rebustness reason, jffs2 should handle it. This patch add codes to check the nsize and the return value of strnlen(rd->name, rd->nsize). If abnormal node is found, use function jffs2_scan_dirty_space to deal with it. Signed-off-by: Zhe Li --- fs/jffs2/scan.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 5f7e284..ff37d92 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -1065,8 +1065,21 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo pseudo_random += je32_to_cpu(rd->version); + if (rd->nsize == 0) { + pr_err("%s(): Node nsize is zero at 0x%08x\n", __func__, ofs); + if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) + return err; + return 0; + } + /* Should never happen. Did. (OLPC trac #4184)*/ checkedlen = strnlen(rd->name, rd->nsize); + if (checkedlen == 0) { + pr_err("Dirent at %08x get zero checkedlen\n", ofs); + if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) + return err; + return 0; + } if (checkedlen < rd->nsize) { pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n", ofs, checkedlen); -- 2.7.4