From patchwork Thu Jan 2 22:07:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11A60C3276D for ; Thu, 2 Jan 2020 22:46:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC1B720863 for ; Thu, 2 Jan 2020 22:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578005174; bh=srK+AwUov53SvNhhGdeEi7tX841wok/s60+s1aXhuaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UhYagPCpztQ+Qc1M6NUoo3xz8cr9RyAnsUroUvqNWhi4EMCdFZedv9FJbKOM+RdfU Lc52FGpZRhGrgIp5j9jhLR8NPtBFhD4D2Y6aA23xhN2psCsxE+8ilYAuqVxsf2bPf7 ytYVgBfzN2oV2iFABx6IqVNTCdTe27mb8qhr0/As= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730249AbgABWbJ (ORCPT ); Thu, 2 Jan 2020 17:31:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:35846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730239AbgABWbF (ORCPT ); Thu, 2 Jan 2020 17:31:05 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E082D20866; Thu, 2 Jan 2020 22:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004265; bh=srK+AwUov53SvNhhGdeEi7tX841wok/s60+s1aXhuaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rKjhRzx1m3xQlN5dJwt73xlsor+Z9BEc961KKXZeUkAFsG+Tx8vl4GWpNqr0TfmSU F+mlWkmSX9xH1ca83TlflyUKXrkZ6ntLJ00Rc4pUr6KzHT2v8zLMlaCeAzGJIc2mxE rSfZQIiTr9376e7gq5tS0veeixHA2qYvxRbPG3Qw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Theodore Tso Subject: [PATCH 4.9 107/171] ext4: check for directory entries too close to block end Date: Thu, 2 Jan 2020 23:07:18 +0100 Message-Id: <20200102220602.014456443@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jan Kara commit 109ba779d6cca2d519c5dd624a3276d03e21948e upstream. ext4_check_dir_entry() currently does not catch a case when a directory entry ends so close to the block end that the header of the next directory entry would not fit in the remaining space. This can lead to directory iteration code trying to access address beyond end of current buffer head leading to oops. CC: stable@vger.kernel.org Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20191202170213.4761-3-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/dir.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -75,6 +75,11 @@ int __ext4_check_dir_entry(const char *f error_msg = "rec_len is too small for name_len"; else if (unlikely(((char *) de - buf) + rlen > size)) error_msg = "directory entry overrun"; + else if (unlikely(((char *) de - buf) + rlen > + size - EXT4_DIR_REC_LEN(1) && + ((char *) de - buf) + rlen != size)) { + error_msg = "directory entry too close to block end"; + } else if (unlikely(le32_to_cpu(de->inode) > le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))) error_msg = "inode out of bounds";