Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3770131pxt; Tue, 10 Aug 2021 10:55:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2/9v4wlSKy/uWLAwTPJbjt1nob77em+VkOJiAygh0U+Dp5kO41Oq8z9fehuqNHmzsjnzH X-Received: by 2002:aa7:c603:: with SMTP id h3mr6284378edq.165.1628618140315; Tue, 10 Aug 2021 10:55:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628618140; cv=none; d=google.com; s=arc-20160816; b=ZYHVhuCU3xxlMSOmQTr8gOOo5dVebMyyTtXVNSN3yMVFkuuPzu9ypH7H6Vh6WSo+DL vh4OgwQBd/VhVSagdrOvikO6to3gU0vNkhXsb6nA8hXLU9kxtRJSkYA9YeheU/7nsrVL 0FDdAxaC/Hb/gJD9cy377A5dQGp1ECw5bDPz8ihJ88BD0sxLGZCHY8ndJAg4usT4x3r5 iuxRANLFcT9UkGA6XjiTWtZI5IusuIoMxjVKnBqsok34rcOTgVZ5HcpVjzTK9trOhPkt Wgy3t5R6hBSyyNifD4So0/o2+1f3dnWSS7L6SwGtTy0efc9tLAKFNvRBJzYCKmPXWd8e 85ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vhsnOrngTmpC4cgaTNbUhVe+0IRrKVgb8jaPOV32OLw=; b=ZAj3KdyCUqYcNLMiDbUwFw1IXlcs53L7UYk+YD7lIRHz39CSvWgIHub6xHwRjM5SCf 7j4HtJ46lPmZKJiRcus5QAenlv3Ngw4FbbcoNVwLzSs6g8D4R3PYUOyOArPqYi79Dzmi LWQ2osph7NHV3uF/OBHvqrgQ905Tq1EEanyZ28bdoy64unMNSIZZwmeIp/LxKGWSsWvU 9uolM/54kTbO6Zdn8MXALPfdd/14+2NY4lr+WrjE+W/Amx2z0waMSZkIRF3CjgrSLpIq WPrGZzffAdfcTmab7BywYSSQz+8au0F1IR7EY2/QlZrte+OLGs4K4i+9/LEwGV7Og44Z D58w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BX4x9MgV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ji2si21236423ejc.344.2021.08.10.10.55.15; Tue, 10 Aug 2021 10:55:40 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BX4x9MgV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbhHJRvy (ORCPT + 99 others); Tue, 10 Aug 2021 13:51:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:51962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236118AbhHJRss (ORCPT ); Tue, 10 Aug 2021 13:48:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A93E60F56; Tue, 10 Aug 2021 17:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617288; bh=juMD/gwYa8eKOqbZs0IYqt0t+hpwfZ8KU6t6B3GM0Iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BX4x9MgVVRfz7TsUI7fkW47GmufK2yNbAasoatzAnADOXi3CW8lViOYiD9WlOVRTf 6Ga1AsNknk8Q8AVLvHCXchVhHFUIlYADEQnfX/6Tp7yE+CWqaga2QIBRfTNXpchGf+ q+Ac4vdJedHfvQ0qdEdT8YDBNkvqIQ/GpzVnfYqA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c31a48e6702ccb3d64c9@syzkaller.appspotmail.com, Shreyansh Chouhan , Jan Kara , Sasha Levin Subject: [PATCH 5.10 128/135] reiserfs: check directory items on read from disk Date: Tue, 10 Aug 2021 19:31:02 +0200 Message-Id: <20210810173000.150438717@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shreyansh Chouhan [ Upstream commit 13d257503c0930010ef9eed78b689cec417ab741 ] While verifying the leaf item that we read from the disk, reiserfs doesn't check the directory items, this could cause a crash when we read a directory item from the disk that has an invalid deh_location. This patch adds a check to the directory items read from the disk that does a bounds check on deh_location for the directory entries. Any directory entry header with a directory entry offset greater than the item length is considered invalid. Link: https://lore.kernel.org/r/20210709152929.766363-1-chouhan.shreyansh630@gmail.com Reported-by: syzbot+c31a48e6702ccb3d64c9@syzkaller.appspotmail.com Signed-off-by: Shreyansh Chouhan Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/reiserfs/stree.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c index 476a7ff49482..ef42729216d1 100644 --- a/fs/reiserfs/stree.c +++ b/fs/reiserfs/stree.c @@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path) search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; } +static int has_valid_deh_location(struct buffer_head *bh, struct item_head *ih) +{ + struct reiserfs_de_head *deh; + int i; + + deh = B_I_DEH(bh, ih); + for (i = 0; i < ih_entry_count(ih); i++) { + if (deh_location(&deh[i]) > ih_item_len(ih)) { + reiserfs_warning(NULL, "reiserfs-5094", + "directory entry location seems wrong %h", + &deh[i]); + return 0; + } + } + + return 1; +} + static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) { struct block_head *blkh; @@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) "(second one): %h", ih); return 0; } - if (is_direntry_le_ih(ih) && (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE))) { - reiserfs_warning(NULL, "reiserfs-5093", - "item entry count seems wrong %h", - ih); - return 0; + if (is_direntry_le_ih(ih)) { + if (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE)) { + reiserfs_warning(NULL, "reiserfs-5093", + "item entry count seems wrong %h", + ih); + return 0; + } + return has_valid_deh_location(bh, ih); } prev_location = ih_location(ih); } -- 2.30.2