Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3757499pxt; Tue, 10 Aug 2021 10:36:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhrpWtt1u8j8MbMXKTz5Kq6E4it9vofuKm4o0NMcdVSx7Dx5C5NAJ0qMUJU7Tn3qrfM/5e X-Received: by 2002:a17:906:404:: with SMTP id d4mr28891876eja.449.1628616992061; Tue, 10 Aug 2021 10:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628616992; cv=none; d=google.com; s=arc-20160816; b=ZSE9eMT0QAKQ7j4iy8BbBZ3/LYTQffU9xDamiwJtQdTqs/B2bRuMoOSnfbo9gTtVVD l2OTMH3FsHN/4mtYOpXR0CjapdjJFKHrANVXP8ZEPI5oa/2GTDgak3jICoM/A8ui+NoW ZKI3IWCG5YI37q5cNDG30zebMS8+L3uu83HfqY0BMW3nK7fnmQrFO5JPXfCkZU0InPKd HiBqc26uTSEMOVlAfX08idsbLqkTDz4XopFhw+e+wFnldPEXuL6YFtvo0wUeFYXmpE+t sKeIoEFTvYZtwv/r+uyb8rvzRqgwI2oTDjZuhgV4vsn3RsjwjPqQ1aNQZywm9adBVccw KEOg== 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=AqZZXKQ9DSBHwU4H1MiNRbQNda1zPc2qxaftTqtS/bU=; b=rLa0zN6HeH6OQhpq6+BwicZmfANQPRgfTc1dUxy0+3NXUDfjr3y4OpqF2yK4i8QEmF owtbCQJuCRQ+YHHaiFjW2edIdWg0Zspek5+Qj7mlpyGkcbbGutOvkyrKyBqUQRTtx20i DxpInwZzeYz5wESuFBsBfN3D3CecPmkpD4UeWORbZMDPe2yEiLR9GLE6gMc2S5xVAOlT xXXrGQEMM9Y7LsC7OPPv9/YwQMGwac+7rbpVUiI2E5/Yi1KzLgEAPMHX+Rk7WXJtAS77 nQsl7idAXwpv2S5TpXNlShxkN40C+CCV7ZsGRHciIe1kNTRREXkJ9Rll2XPHyvHxLqL7 2gbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wuvibdVV; 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 y14si20971183edt.174.2021.08.10.10.36.07; Tue, 10 Aug 2021 10:36:32 -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=wuvibdVV; 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 S232752AbhHJReZ (ORCPT + 99 others); Tue, 10 Aug 2021 13:34:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:36686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbhHJRdi (ORCPT ); Tue, 10 Aug 2021 13:33:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 59564610CC; Tue, 10 Aug 2021 17:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616795; bh=hVRjeIKeqGzKqDwszUGsi+lUR5UdWKTKaBB8H9mmTzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wuvibdVVIEEtZO7NEv6BYa7yqgHn68jnSs4Vd5u11cY0hS/G3QRiAMuDXOrqJNNWX 0Szat1paaBSMayovGluhBfc4AoPrAA+vybGw9jtaA2zVkX3Wolt007B9h/uDBACCB/ IPU3UQ3uEx16tfbM7r2NPA1lW+6325DJmOwWh5ls= 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.19 51/54] reiserfs: check directory items on read from disk Date: Tue, 10 Aug 2021 19:30:45 +0200 Message-Id: <20210810172945.892055610@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172944.179901509@linuxfoundation.org> References: <20210810172944.179901509@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 5229038852ca..4ebad6781b0e 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