Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp4406ybm; Mon, 20 May 2019 10:50:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhz3cEiQrECG9NlvhSgwq5hLX3ATwwlRTMksepX6DATDPzc4QgbCrULwrWn827GeOOdEfK X-Received: by 2002:a63:3e47:: with SMTP id l68mr75663050pga.85.1558374657892; Mon, 20 May 2019 10:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558374657; cv=none; d=google.com; s=arc-20160816; b=aHvBmXkcOfUJIZJ/ENUllScnTtwlI6AsUrrX8rN28vnysTTRN5ZVXTt6hKpzCfusa6 K43ZwoX4Cxt2sc0ugd4jAv2pv37fy0kL3HWACeWpH++NsITUgSABEJOUZvhiL0d4ectQ N5hyAlcjg858GwEl9d7vwUHo9MfOiR88PtISETIJI+HFwfP6YqsEMaGPIrT7B1FVNIg1 0xma8NIFmY6QJI6CIDiY7n8rpnYt1fUrZA2JHUNU5ME0WeavbDzK/ckDNSKC3ZlxEMx1 J6GiA0irIh5Xfx638sEqCUtsjq70NyWbidCYbYsfZYs3s2GRTuwk1NdfQg5d1SaVjSyg sOQw== 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=02LvYz70vCMxIneatfDkKPDNhFlKvx9KqhzaTw45TnU=; b=nop/bAAlu7wToImLnQRMhE8iymkC2GQ2ZTah+aCx8/42zycnsgquQ1Ml2NBoN7gBrU qHsQI7EWEIpOTNP2N0HYZ2CaEHl+AcnVB51cLHDdJbCUYFF6DJpzF9c9Cxm25PE5Ek0S RX0Az21Ht4vwUh1RqxEWph6BmoEb8vBgjpK9QdJomO+sASLKDFzm7XP+3VKxaaq4r8Pl tz/Nn34zrPToY/YDtfXhSNFFfuhn6Y1XtRuOwZgWFo68lqw6M9jsNscw0EIxvmCbgeOM 4U0dBEPllLyBm1zEEpF2VPscVMcY97Amie1fXWEeXjJehp4B9vLgOiOBDTZIbvO8PnNd Fi/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RZvHopNV; 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 c19si7094256pfn.0.2019.05.20.10.50.41; Mon, 20 May 2019 10:50:57 -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; dkim=pass header.i=@kernel.org header.s=default header.b=RZvHopNV; 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 S2391123AbfETMfl (ORCPT + 99 others); Mon, 20 May 2019 08:35:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391116AbfETMfj (ORCPT ); Mon, 20 May 2019 08:35:39 -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 DDFE221726; Mon, 20 May 2019 12:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355738; bh=VpgFCPF+VQV+9StQj8r5gpwZ4Ry5MHG0rcvGOeYFJvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RZvHopNVrN25yJrDFAKdZMhW83yYrt8vS1u7iPZI102EUnE77MvK5S0ymTzG04klC VuyOGVmpRDBvlemxXFG32vBeXcUMzVMkHpkTGYaI3WaLcmdRo7Q5YKPiMAIe6x2qIm BLIIpyhkwgrlAD76K6+3N13dt3jNktAskZmaySyo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sriram Rajagopalan , Theodore Tso , stable@kernel.org Subject: [PATCH 5.1 107/128] ext4: zero out the unused memory region in the extent tree block Date: Mon, 20 May 2019 14:14:54 +0200 Message-Id: <20190520115256.274122345@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@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: Sriram Rajagopalan commit 592acbf16821288ecdc4192c47e3774a4c48bb64 upstream. This commit zeroes out the unused memory region in the buffer_head corresponding to the extent metablock after writing the extent header and the corresponding extent node entries. This is done to prevent random uninitialized data from getting into the filesystem when the extent block is synced. This fixes CVE-2019-11833. Signed-off-by: Sriram Rajagopalan Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/extents.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1035,6 +1035,7 @@ static int ext4_ext_split(handle_t *hand __le32 border; ext4_fsblk_t *ablocks = NULL; /* array of allocated blocks */ int err = 0; + size_t ext_size = 0; /* make decision: where to split? */ /* FIXME: now decision is simplest: at current extent */ @@ -1126,6 +1127,10 @@ static int ext4_ext_split(handle_t *hand le16_add_cpu(&neh->eh_entries, m); } + /* zero out unused area in the extent block */ + ext_size = sizeof(struct ext4_extent_header) + + sizeof(struct ext4_extent) * le16_to_cpu(neh->eh_entries); + memset(bh->b_data + ext_size, 0, inode->i_sb->s_blocksize - ext_size); ext4_extent_block_csum_set(inode, neh); set_buffer_uptodate(bh); unlock_buffer(bh); @@ -1205,6 +1210,11 @@ static int ext4_ext_split(handle_t *hand sizeof(struct ext4_extent_idx) * m); le16_add_cpu(&neh->eh_entries, m); } + /* zero out unused area in the extent block */ + ext_size = sizeof(struct ext4_extent_header) + + (sizeof(struct ext4_extent) * le16_to_cpu(neh->eh_entries)); + memset(bh->b_data + ext_size, 0, + inode->i_sb->s_blocksize - ext_size); ext4_extent_block_csum_set(inode, neh); set_buffer_uptodate(bh); unlock_buffer(bh); @@ -1270,6 +1280,7 @@ static int ext4_ext_grow_indepth(handle_ ext4_fsblk_t newblock, goal = 0; struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; int err = 0; + size_t ext_size = 0; /* Try to prepend new index to old one */ if (ext_depth(inode)) @@ -1295,9 +1306,11 @@ static int ext4_ext_grow_indepth(handle_ goto out; } + ext_size = sizeof(EXT4_I(inode)->i_data); /* move top-level index/leaf into new block */ - memmove(bh->b_data, EXT4_I(inode)->i_data, - sizeof(EXT4_I(inode)->i_data)); + memmove(bh->b_data, EXT4_I(inode)->i_data, ext_size); + /* zero out unused area in the extent block */ + memset(bh->b_data + ext_size, 0, inode->i_sb->s_blocksize - ext_size); /* set size of new block */ neh = ext_block_hdr(bh);