Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3471337pxu; Mon, 19 Oct 2020 12:58:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGdSJ7qQ56S12zlnWkWmRfxBu8UaxAH/RrWFr+pKrrDcUScF0wD/1V9okbLHbXjX652a/a X-Received: by 2002:a17:907:2095:: with SMTP id pv21mr1602691ejb.236.1603137525205; Mon, 19 Oct 2020 12:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603137525; cv=none; d=google.com; s=arc-20160816; b=qvWwtW/gvHLaDg61BpQ4NLtozMbqgCg45l/lUs6vhZDeNX/Ba3AEQBdGjcpfWZogE5 XDF4uL8erOcIgxHhAebDp7nu6UMgOCOwjCt1IMJ+hyHZ33TvjnlpSVr5J8uZWtIQPdxI a4b47nskVcHh5vLjDkorP4LJdmnOY4fYZt66o5Wo35Ydt1XvMKNKZ7JFVY8jSa7j9aZy rYh3Sh66GJsND+WTqN8DG2CBwEJVwUUH7LPfRUSLMJKzIQ2K1WY9Q4NHkTLaCdYGV2aA 3Ai3Ct3b7uR2aTtWzfwjO62L2p94EFyy8SmLFtN6mrtr1wDRPuPhL/nFI8fqBac7pyPO ISqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=kXjx4S1xqrV6x43QahaCwP/zNZYedsAHFhPliY2/W3E=; b=0lnrUsf7LNzT5uNi4DtBK3qRd9WzbhsjYlHdHpvumx0dBfTXwLpLwLCdO+CQTMiVW+ 8laFLo7D1Lpf1YL11u16HpsQIKiEHMyAyOcpDOkvWvOnfg9j6+XSXVkONWHxdppgCuQn xtew7onQXR6/o+jY0WtC/I/u9wLONZbvQmTjWAFCpr9EL/nxPDkRJT6Nz2ASy8D6Pngn 7Cjl/c0vOkjGUd5/MtowYIph2jzQcQ+mfDhh8Tl3SbNcl05+Mjev5Ltdi6cX1/ZlL7OG whLi3PruI9/goDGQWnae6iV2VqVsI7dfZbj2rx3s+s6u1iIgQASQ3A4ZnkZPCbAENK4r E/9A== 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 w15si487477edr.434.2020.10.19.12.58.23; Mon, 19 Oct 2020 12:58:45 -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 S1729978AbgJSDGJ (ORCPT + 99 others); Sun, 18 Oct 2020 23:06:09 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:58784 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728660AbgJSDGJ (ORCPT ); Sun, 18 Oct 2020 23:06:09 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 065D65D84146CC2E6BB0; Mon, 19 Oct 2020 11:06:07 +0800 (CST) Received: from [10.174.176.185] (10.174.176.185) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 19 Oct 2020 11:05:59 +0800 Subject: Re: [PATCH RFC 0/5] ubifs: Prevent memory oob accessing while dumping node From: Zhihao Cheng To: , CC: , , References: <20200616071146.2607061-1-chengzhihao1@huawei.com> Message-ID: Date: Mon, 19 Oct 2020 11:05:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200616071146.2607061-1-chengzhihao1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.176.185] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2020/6/16 15:11, Zhihao Cheng ะด??: > We use function ubifs_dump_node() to dump bad node caused by some > reasons (Such as bit flipping caused by hardware error, writing bypass > ubifs or unknown bugs in ubifs). The node content can not be trusted > anymore, so we should prevent memory out-of-bounds accessing while > dumping node in following situations: > > 1. bad node_len: Dumping data according to 'ch->len' which may exceed > the size of memory allocated for node. > 2. bad node content: Some kinds of node can record additional data, eg. > index node and orphan node, make sure the size of additional data > not beyond the node length. > 3. node_type changes: Read data according to type A, but expected type > B, before that, node is allocated according to type B's size. Length > of type A node is greater than type B node. > > Commit acc5af3efa303d5f3 ("ubifs: Fix out-of-bounds memory access caused > by abnormal value of node_len") handles situation 1 for data node only, > it would be better if we can solve problems in above situations for all > kinds of nodes. > > Patch 1 adds a new parameter 'node_len'(size of memory which is allocated > for the node) in function ubifs_dump_node(), safe dumping length of the > node should be: minimum(ch->len, c->ranges[node_type].max_len, node_len). > Besides, c->ranges[node_type].min_len can not greater than safe dumping > length, which may caused by node_type changes(situation 3). > > Patch 2 reverts commit acc5af3efa303d5f ("ubifs: Fix out-of-bounds memory > access caused by abnormal value of node_len") to prepare for patch 3. > > Patch 3 replaces modified function ubifs_dump_node() in all node dumping > places except for ubifs_dump_sleb(). > > Patch 4 removes unused function ubifs_dump_sleb(), > > Patch 5 allows ubifs_dump_node() to dump all branches of the index node. > > Some tests after patchset applied: > https://bugzilla.kernel.org/show_bug.cgi?id=208203 > > Zhihao Cheng (5): > ubifs: Limit dumping length by size of memory which is allocated for > the node > Revert "ubifs: Fix out-of-bounds memory access caused by abnormal > value of node_len" > ubifs: Pass node length in all node dumping callers > ubifs: ubifs_dump_sleb: Remove unused function > ubifs: ubifs_dump_node: Dump all branches of the index node > > fs/ubifs/commit.c | 4 +- > fs/ubifs/debug.c | 111 ++++++++++++++++++++++++++------------------ > fs/ubifs/debug.h | 5 +- > fs/ubifs/file.c | 2 +- > fs/ubifs/io.c | 37 +++++---------- > fs/ubifs/journal.c | 3 +- > fs/ubifs/master.c | 4 +- > fs/ubifs/orphan.c | 6 ++- > fs/ubifs/recovery.c | 6 +-- > fs/ubifs/replay.c | 4 +- > fs/ubifs/sb.c | 2 +- > fs/ubifs/scan.c | 4 +- > fs/ubifs/super.c | 2 +- > fs/ubifs/tnc.c | 8 ++-- > fs/ubifs/tnc_misc.c | 4 +- > fs/ubifs/ubifs.h | 4 +- > 16 files changed, 108 insertions(+), 98 deletions(-) > ping, although it is not a serious problem for ubifs, but dumping extra memory by formating specified ubifs img may cause security problem.