Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3761742pxt; Tue, 10 Aug 2021 10:42:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXB116TNHrqMLKj3K6XY85+W0c35cKce4cXCdWoXkxgQzy0ckBjtBPddYwZ2bDnrioqfpX X-Received: by 2002:a05:6638:95:: with SMTP id v21mr28645916jao.80.1628617377876; Tue, 10 Aug 2021 10:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617377; cv=none; d=google.com; s=arc-20160816; b=bUue733GaGS4AWo+Nn6KESgxqj8BQXqK+cKy3aqnmrWjUFNYxCT4Ig9V66QEoR2htv z4Fn4xd/g1DvgWs8dVMemS6tJsuwcCB5Tft2bCpiQ/5LY2NFYAg4tQDCyjuNWDNBVbVE kZ9KID3oLmgKzojFr6AdOIbB5eLVojd3ffZkwEMCLPOGo5pcSWt001f0aarbSlTofFNx /7NMyDtztyHdDKpIv0WO+XPP0CbRxf121hV34Ldq6swIpcqd5R1mtEUnMpPFpQibc49C sQHIp9ACwXjA4Pu9XBAYD2zsPrs4EC6pocVpJ2rcic4gWbk8WxKN13V4INCo08qOxP8s /zgw== 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=5NvnJNh1DXh1y5y6b+PUPnOlWUauvxYN0xNrFUFyQcM=; b=Ys15obTLuLJOEkqhpDqv9uprcnficxJv3br5Cb66sS68W2nkf2ijdoyJwpc+fDjx31 ziGHMLVo6IWG7UhC//EuO2552NM5p/x9dGIRBodN0Z5eNwA29SvjudmcqptUbvexjbjx 1NhZtgOLxEW+fpJPokCgcIJzsWqJNCnbqTt+R6+B/NSKPzJOkBuUsc7v22EDZ7IGZoVd UABTwfFEE/jubkYmTIYKxkz3RgZrWUfgtf4eGDh77JRLFF0Vl74mvUaToP2Z1ARrDOc2 GO2w3I4yb2MUxG/A9wlYn1htIPtGn6b/12AtnGJrZUfPXwXGrWSxrY/NZ4IwDQ4UN9LY koNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dMwpGHo9; 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 s13si23746866ilp.102.2021.08.10.10.42.28; Tue, 10 Aug 2021 10:42:57 -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=dMwpGHo9; 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 S234989AbhHJRls (ORCPT + 99 others); Tue, 10 Aug 2021 13:41:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:44922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234842AbhHJRi1 (ORCPT ); Tue, 10 Aug 2021 13:38:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BDAF461154; Tue, 10 Aug 2021 17:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616991; bh=dTVsgaI0Ijz/iBriwJNSMb7CCOp1qtmBVnOwQDSdRcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dMwpGHo9rfYiYkn9DlsdPBVpzn1rNL1R+eqgR1VBWRgPy2gsASLE3HlDSHHbN27gV A9kS2dSMOXH7b/jXAmFjdJDa4LWakujn9PQNtOZtmHHjPKOXoZGUP0IikDr7rsTlUY L8AHIklzVWwu6UJ4nOeh1W18e6JDkay+p5KuCfw0= 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.4 81/85] reiserfs: check directory items on read from disk Date: Tue, 10 Aug 2021 19:30:54 +0200 Message-Id: <20210810172950.977785028@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172948.192298392@linuxfoundation.org> References: <20210810172948.192298392@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 9e64e23014e8..07d787145cc3 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