Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp784125ybt; Fri, 19 Jun 2020 13:43:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPd8p4E3ocGLPKWSfxmSmYi1Rk1K7oacK9SUYi/WsQCM+khUOmvhypef585grCQT2yPcmr X-Received: by 2002:a17:906:e115:: with SMTP id gj21mr5139114ejb.528.1592599394525; Fri, 19 Jun 2020 13:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592599394; cv=none; d=google.com; s=arc-20160816; b=TcvwCkUHGLWXBqB1LKE4qzEketgztnG8Mk/CY/4kYz5chY2vFeKm9rQhus2+Xs0+cE lXjpQEQYMALjtZ0kZjIEDeJDSToPfIBElBXhuVlZ7dKX8JwTOM5rrsD63o/bnPXlhi7i kMyFrQaD4/uF06IPmtTCkMgTUMfqPSY1Z8F+dku3OKiVnZ931d4JBV7wKiBbFKvPlRPk l0W/BVGU+G9WLPvDQj0s/HuPjqi5+WalAhMrw2u2a6XvZ8JiWQnvIS3laEnSa5ae0UiY NKHETjLJ0/i+B4JMMHanmFLqXBrnF3jgcQPg5ctk8KQmmDQy9T61eJJLNNru3DXgOCQe sZHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9yxx1ROn2hlBDrtW3KmE3LN2dhfRIu+aJJQdJ4GRKRM=; b=WVSe0I2HuKC8HHpBOrNLvlWco154AWFpz/KhwhngTcTpxVqSJGGxTyvLrQHxxDUMQF WH8lUeAA/BQbGdXn61gw/cKS2dJit2w+2zwehlganr8+F4dIV0rJp8qhNVZihCwRvwv4 55FmjgGRT2ktFFgmLGZ8XtXQXePTnkk5IliGJMmEM3JdVIsjFzw9hVtzT9di7UHn4tcC unawgbdRO2bPcmt2wDa7gmYKR617HNWtsgWYc13G0mGh/ymWCXg6IRbgJoppNeMMKPs9 WLUD8VTcK6A6mOeAK6wYeIQKpXBu5MO2nG0lDYIVJ6dz5zqZvFae2rhb52TgkCB341o3 nPKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="q6/esZGr"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q21si4355759edw.46.2020.06.19.13.42.52; Fri, 19 Jun 2020 13:43:14 -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=@kernel.org header.s=default header.b="q6/esZGr"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390805AbgFSPCN (ORCPT + 99 others); Fri, 19 Jun 2020 11:02:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:57924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390715AbgFSPBa (ORCPT ); Fri, 19 Jun 2020 11:01:30 -0400 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 9FBB620734; Fri, 19 Jun 2020 15:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578890; bh=gIfZMGZem2W05Cjy5nXcdrpBntSc1KU60HG6biDtdV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q6/esZGrkf94+7OSnV2dLoQVtxFGoW3JKhwNoa5vZKqv52sA+gfaAXs31k9Ehpj7k Mf0kKc0AUL72vnT92+XocMpKhA+cKjSwXE1nkeUlHizPfRoXZVl5mBVL+6OWSWf24a POvIOSOLysLHpJR3GPk10N+gGKiLhpkwt668bmZ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harshad Shirwadkar , Theodore Tso , stable@kernel.org Subject: [PATCH 4.19 196/267] ext4: fix EXT_MAX_EXTENT/INDEX to check for zeroed eh_max Date: Fri, 19 Jun 2020 16:33:01 +0200 Message-Id: <20200619141658.156666851@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@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: Harshad Shirwadkar commit c36a71b4e35ab35340facdd6964a00956b9fef0a upstream. If eh->eh_max is 0, EXT_MAX_EXTENT/INDEX would evaluate to unsigned (-1) resulting in illegal memory accesses. Although there is no consistent repro, we see that generic/019 sometimes crashes because of this bug. Ran gce-xfstests smoke and verified that there were no regressions. Signed-off-by: Harshad Shirwadkar Link: https://lore.kernel.org/r/20200421023959.20879-2-harshadshirwadkar@gmail.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/ext4_extents.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/fs/ext4/ext4_extents.h +++ b/fs/ext4/ext4_extents.h @@ -157,10 +157,13 @@ struct ext4_ext_path { (EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1) #define EXT_LAST_INDEX(__hdr__) \ (EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1) -#define EXT_MAX_EXTENT(__hdr__) \ - (EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1) +#define EXT_MAX_EXTENT(__hdr__) \ + ((le16_to_cpu((__hdr__)->eh_max)) ? \ + ((EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) \ + : 0) #define EXT_MAX_INDEX(__hdr__) \ - (EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1) + ((le16_to_cpu((__hdr__)->eh_max)) ? \ + ((EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) : 0) static inline struct ext4_extent_header *ext_inode_hdr(struct inode *inode) {