Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp876123pxb; Fri, 13 Aug 2021 08:14:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4cyWIG5dD1CU7ti9TQco67h1UnQ4zNq/F6cS4VDIW0UZluBS6FtzO2Tl3qu0TvTTRzhOF X-Received: by 2002:aa7:c606:: with SMTP id h6mr3754319edq.363.1628867649103; Fri, 13 Aug 2021 08:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867649; cv=none; d=google.com; s=arc-20160816; b=ZyDSUO8G3nzo72HqRrewBT0CZWXS9bx7J/M8iaxlwvGrg0e8KgfVBft6IyQ1Or3lmn URZABeEHIXxgkOWhj19A6B5hD+MEM7bEHDR/WQylNg4L9H8bNaxoZHxN1qO9ySN4iYMD 1qV5RPCzaAee4fwQ3Vi5mEYz3Capw6OUnZMzzOFARuRnhrh/qttyMjS+JDKfb34sf2tp 2toMZV0xo/FwFWqi+Gejvh1RwKMJ2BBeY+lL4bpyCYs/S5sP5YmlbsW0GexTTYmxsEUZ HINCbrQEf6HQ4KmEMEjlt4KGtLjsR8cBpS/TGaG2VyJI0j3AZUqcyPdcxaLZ3EQ9QxUQ NbUQ== 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=5uGxuMvXTzCHugAcwsoCQio3of21UXxuQ+Yhy8Cw6YI=; b=Jm5Jzd8SKBUzcSVWiwV31woKIgA7cM/sPUkq5HIymYMnTzFBqOGdhjCD1OO1Z+VJrI Cwle7Nj62GdCEOVYRa/zpbPvSfjuoGcHHBdHA4ZK2yaWc78oslt3z1Jkht4uFq+H3oOa HWizKWa2YGLfnTJ+ZD7qiJByJejUHM3qBiJKaJ5GNSLrubEwaAmHMkUSxPnZLF/Vx9pL BHzr/+RgmnqnQEqzMijdXSMPOrU3xkXMYTCd9z8XneqXa9CoK7Kc6AQVarmK/fUBN3IS GIcEJuewPBkLNiMgsjdL4tG4yk5VjkzJV5aRov6b7WuqBIraf+qiIUZtAhyeoVmYA/b6 FHiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V7UZPxPM; 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 g17si2105085ejo.93.2021.08.13.08.13.45; Fri, 13 Aug 2021 08:14: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=V7UZPxPM; 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 S241452AbhHMPLn (ORCPT + 99 others); Fri, 13 Aug 2021 11:11:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:53778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241805AbhHMPKv (ORCPT ); Fri, 13 Aug 2021 11:10:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F33061103; Fri, 13 Aug 2021 15:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867424; bh=2wtNd8DLtIwTEgErKq3pVhARqyZ3RE7JTqyuOrqoI7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V7UZPxPMavHCLEwy4+laoA8gAweWlYdfCu07hpFQ44JEJUnuqeBo5L4lJHXfFnrI/ FfQ0Xg6Q2S1UEgwPNH2BlsxwOl8WzM3lwLlOf1Gm/0Nh9pBbx9vkOeqeJo6Ut5Q5b5 4nl/s3WL/0u7SoCyV25CnntU6jCHHqfZlDD/3juA= 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.9 24/30] reiserfs: check directory items on read from disk Date: Fri, 13 Aug 2021 17:06:52 +0200 Message-Id: <20210813150523.223823137@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.445553924@linuxfoundation.org> References: <20210813150522.445553924@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 25b2aed9af0b..f2f7055303ca 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