Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3781330pxt; Tue, 10 Aug 2021 11:10:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6B5zyGURidZTDvL4ySpzM7LyF9oetw5eKyZs3IjNXlMSHKKJIXUpb/z0FvoDWQMfUhkTk X-Received: by 2002:a05:6402:524b:: with SMTP id t11mr6594306edd.330.1628619009768; Tue, 10 Aug 2021 11:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628619009; cv=none; d=google.com; s=arc-20160816; b=wCR2ZsFDu20I9ipb7OfbRHqw/MLcGgoJDIO+qhSuf1vMjePG7xKA3CWNpFgxRi4hbi JCxFx0r2fzQeXk+sSAhnX+em+DxwLHILR22h6SgwHhnQcRQS3h/cfnzZsvjFHltLbfNW qAxZF30g33pk0y2ZIgkTVEBS4lXrm8Won6cyq5Nb9Dzvz1jPOnfWVyCZeLzD5Sm2bhrO hpD6+daKVsyuJSSC93x0Ydnz0hFZt1+3dyLLKqeoiQWkFoxPTz1Q/b/LQhxxtBo5O6ID atkhaWsXmYemty3LvBR43mYpUMTiTqsX21fEOdALjUGTv1T0hvYOOxV1AcZfqq7lytsC 9u0w== 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=ltyXZVYBo2iSGTxRxvTlnSv1bSQ4BbxTNnrVwmnBBosEsLoSfDNNzI46BgItmbPbU8 TClRsUHGheXB8o+6IDFp1XvMLoR/m5wT2ZRqNJ9mdEevjBg0TXo9vXhc6NPsO6OOA3ga /zqUaPVz16Ighajm6ZnenhVDiYDvPCW9ygA/jLEEUDMvSdN58ssm5QP+f/u/mcKdUSpZ +MvTdCiQOvcaPXRbJ+XZifx4pr7XQ6vv3dSoitcxmzRIxoNergWJ4XxYXrRW4TNVy18M j6I8wmgvpnlDK/bMFWLRlFmusiDqH91tCwRaE1Ort7PlnWxuKdUfDnv7AJUthpzW26cS jQ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K5fOzKXz; 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 h23si8165906edj.326.2021.08.10.11.09.41; Tue, 10 Aug 2021 11:10:09 -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=K5fOzKXz; 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 S238875AbhHJSIe (ORCPT + 99 others); Tue, 10 Aug 2021 14:08:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:34378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238244AbhHJSDw (ORCPT ); Tue, 10 Aug 2021 14:03:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5AD136140B; Tue, 10 Aug 2021 17:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617686; bh=juMD/gwYa8eKOqbZs0IYqt0t+hpwfZ8KU6t6B3GM0Iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5fOzKXzbRIY/y/H08AFWxXu5ktLuWposPXrhmxgNzgodhkKFB8F5WvDdqqo5fhLR zr5aC00vi5nbfgcuN+Z/JZoliXLneKyhPFYXkPXEosLN2csUZdY/vHrGFWUO2rLUW2 mN7xMWuY+vhUu+TrLjGcWdyyTS5KUXhJU2XLnv/4= 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.13 167/175] reiserfs: check directory items on read from disk Date: Tue, 10 Aug 2021 19:31:15 +0200 Message-Id: <20210810173006.451200178@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810173000.928681411@linuxfoundation.org> References: <20210810173000.928681411@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