From mboxrd@z Thu Jan 1 00:00:00 1970 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=ham 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 397C4C2D0D1 for ; Sun, 29 Dec 2019 18:14:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02205207E0 for ; Sun, 29 Dec 2019 18:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577643257; bh=mW4EO8dmtkIggbvuTHjWqsJV+OdBn4CaRMcl3crir5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UWtp1AriXORuKylYhMNj/Gg5ZypzLOxTudA9F5Xl6ph34xJI52WXzk9fl1XZoF4Dg I6/5euGOVeO+leBWCoXB/YGwU97rP8CDp/7Gm8UxkqkFcMaUDMISjYPreH0vsouas6 2JArxS+we0K08VV8fzSwEs5P8cVlAii95bgrswEQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbfL2R1K (ORCPT ); Sun, 29 Dec 2019 12:27:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:48976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728352AbfL2R1G (ORCPT ); Sun, 29 Dec 2019 12:27:06 -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 72FE3207FF; Sun, 29 Dec 2019 17:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640425; bh=mW4EO8dmtkIggbvuTHjWqsJV+OdBn4CaRMcl3crir5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2STaphIvp1TwOv6mD8wpqmDVS+6p+ymD5RnZ3/8wS3f+b7+zUvnULlMrCPNZxJwFP 0wCkn+wpoA4H/oYNzIBYgSp5hfmH7YUMMR8hTsGXURmAjkU22InfEVYjIEbSQPHYH9 C7bVz0kuQWPn5OpDjMM6d474enPb2McDxab4Hls4= 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.14 152/161] ext4: check for directory entries too close to block end Date: Sun, 29 Dec 2019 18:20:00 +0100 Message-Id: <20191229162447.625240197@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162355.500086350@linuxfoundation.org> References: <20191229162355.500086350@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -76,6 +76,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";