Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp872297pxb; Fri, 13 Aug 2021 08:10:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+MX5fKHNFifbljTOWDlJ76lK8Z/ozPPN5w+NVcdDum+47glld+Pa0ObYQtBY7QC4XjnNe X-Received: by 2002:a05:6602:20d2:: with SMTP id 18mr2385022ioz.85.1628867400929; Fri, 13 Aug 2021 08:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867400; cv=none; d=google.com; s=arc-20160816; b=XbJC4C/mld3NlY6ayzgQ4hDQH54MTHs3Kx/ZNXIZbyRS8SvFcxbR0Km/fCx4pdMW1b m99SejjFXsooQbASvEm7P5dFd47TCFcyskfC8Gf43hg2BHsxzvet/XTqEakbPnP45mwP pLpHtS8T290GTJWjEYjuPAvvaoC+fMtHjXekMQVfAZK8msAKz7acSiy8vZxk/wkuKMwR a49nqanspUhz8sSfA+cfx+xohQ+XBFYkrtR6yRiZQdLMSFDgrR2BUhfVOL5cP/9d1yKn GvSKHqlHLb8sxBysvj57MqsFtddrSYyRKKUYCsNGt6qmRzJZTvxVZ8vKw5OJlo7mZqrn I2hQ== 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=MbrxY7ky1kietB79JKvV/ldhn3rq7HYGYKCEuwXVlUs=; b=AU25XCBHER16PJ1e3lsULDqEBev1pA/YZtTvvwil9fg1i85erKInt678M00bxJ4G4u HbMUXnDZeGTT95/VtdQhQcALWuPziaF5RRSaFSNbV6kkyrzpoEQK6BZWaHWXxo9hrfvY u24aaH8fL0u/RN0I+z8dXXueZkDCJ4Q2PXj3fEgdf53YkwK1QM9dNSpqgZVdPgc/hsIM xFnr10bapMEftTnVWUVXZTJ4bqmkgwU/T6q6kvcUXHIYhGYQi8fnsK1mYl3vyjoyzgpw vyvPi3Xd60HstnByQs2ghOjSXY0/UUyhx2NU4EHaSep6v9ZmnE6JopR0xrRGL+u7aWQ/ D98w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eJm6wohK; 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 z14si1905076ilq.148.2021.08.13.08.09.49; Fri, 13 Aug 2021 08:10:00 -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=eJm6wohK; 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 S241185AbhHMPI4 (ORCPT + 99 others); Fri, 13 Aug 2021 11:08:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:51292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241190AbhHMPIu (ORCPT ); Fri, 13 Aug 2021 11:08:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8AC2461103; Fri, 13 Aug 2021 15:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867304; bh=Fra+xviE6GKyepm+SKDA3lXdcyo451/6M8Jg6WcLpuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eJm6wohKllJSwGcuLPQ11T60XH5sqKnQ3rjFDd8L+bvJyFyeljzO9FByMmOUqA1s5 LCEWtsaw1oFQOVG0riRzku1kdEBBwHkpebQ5APDW8nZMIKd4weX3d/ESf5Ls9SaP5q 1fhMqwDuaQ6Oguq0ki13Q2tpt1lNpEr+CIIXI8Cc= 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 4.4 19/25] reiserfs: check directory items on read from disk Date: Fri, 13 Aug 2021 17:06:43 +0200 Message-Id: <20210813150521.340772188@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150520.718161915@linuxfoundation.org> References: <20210813150520.718161915@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 33b78ee9fb9e..13322c39e6cc 100644 --- a/fs/reiserfs/stree.c +++ b/fs/reiserfs/stree.c @@ -386,6 +386,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; @@ -453,11 +471,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