Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2010832imm; Tue, 10 Jul 2018 11:33:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeCNL0F8M+JGY8IdR8mZQBt0rrVshi4pRyXzWQbLRB27XN6As2ovq29HcJsya4f1EG0mIZw X-Received: by 2002:a62:49cf:: with SMTP id r76-v6mr26268970pfi.235.1531247586615; Tue, 10 Jul 2018 11:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247586; cv=none; d=google.com; s=arc-20160816; b=MLW4vrMkQQkVSQIeydrb7llYZxj3B8lkb+SWQexb2sfbY9zE9o6MKQQC7ptVy33KNk 4o2LCVvskMF0FlNxz+kGY5ggJ4ieNvK7sGzAZtKFDlo+0Ry1nadXBYMAbPP7KoBBQTgS kuAMKcCkb1YdDZ+eGWnHqGKonpRwlVfqrbsDedmWPcd2HSg2pLrnVvmea4c3to/lykue P+42uQHI7ipeH/F/4TNrDZ0YpC+TAlb4cEVCAYz5kRlOTZ6YkEBnN1ynE038PmrRTxjJ 4B0y7k5e0YDkGZ8mnh/Eep/udQp42tgu27jTqFqxibo14k77l3Y0kLRDdnBwW3nJ6hAO fk2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nNMO8CRvqDQ7VOsw2a7b4wAsbCg5p2Y0y01bSouLKOY=; b=FY1BBUWUZr0mWSfy1ifEkSGgpZkPBP0+UxhC0u7B6tRxDT7T7qWBBcLoVrMqVtWrSJ 3MVSAbjboQUeMOWwH12kqFB6T7QXm8EOkRzoGR2dNSIxMZx8tlCNt0TCMy29574dT8O9 WjdKI1yjC4+l60+/I78ATk30i3yk3AgYwcx8RPNM2BvX0Yv0wfQP3R2x7xjbBLITn8KR Gv4R1FO3cqrT2I9GN/O3hcA04zifOsFWitMqOp0GsBkw5LQ9cZ5WK/61JcreQSXClG+j tyWWIfp7kTJTqki0c2hkdkP5nz8ec2tq+C0t9kR7JvrChqB1ZD9phntVJKEnP/dzfBVp TjAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68-v6si3254782pff.55.2018.07.10.11.32.51; Tue, 10 Jul 2018 11:33:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388082AbeGJSab (ORCPT + 99 others); Tue, 10 Jul 2018 14:30:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45584 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388073AbeGJSab (ORCPT ); Tue, 10 Jul 2018 14:30:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1BAACEB4; Tue, 10 Jul 2018 18:30:18 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org Subject: [PATCH 4.9 30/52] ext4: verify the depth of extent tree in ext4_find_extent() Date: Tue, 10 Jul 2018 20:24:58 +0200 Message-Id: <20180710182452.159573838@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit bc890a60247171294acc0bd67d211fa4b88d40ba upstream. If there is a corupted file system where the claimed depth of the extent tree is -1, this can cause a massive buffer overrun leading to sadness. This addresses CVE-2018-10877. https://bugzilla.kernel.org/show_bug.cgi?id=199417 Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/ext4_extents.h | 1 + fs/ext4/extents.c | 6 ++++++ 2 files changed, 7 insertions(+) --- a/fs/ext4/ext4_extents.h +++ b/fs/ext4/ext4_extents.h @@ -103,6 +103,7 @@ struct ext4_extent_header { }; #define EXT4_EXT_MAGIC cpu_to_le16(0xf30a) +#define EXT4_MAX_EXTENT_DEPTH 5 #define EXT4_EXTENT_TAIL_OFFSET(hdr) \ (sizeof(struct ext4_extent_header) + \ --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -881,6 +881,12 @@ ext4_find_extent(struct inode *inode, ex eh = ext_inode_hdr(inode); depth = ext_depth(inode); + if (depth < 0 || depth > EXT4_MAX_EXTENT_DEPTH) { + EXT4_ERROR_INODE(inode, "inode has invalid extent depth: %d", + depth); + ret = -EFSCORRUPTED; + goto err; + } if (path) { ext4_ext_drop_refs(path);