Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp79760yba; Mon, 20 May 2019 05:21:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyL1ObpDx3EcvKRjgWdxj4CtMWpd7tuiNxoTIGQ/axRJvpVNkyejCv88TZ85C+iZrMyZzju X-Received: by 2002:a63:6647:: with SMTP id a68mr58785046pgc.292.1558354863648; Mon, 20 May 2019 05:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558354863; cv=none; d=google.com; s=arc-20160816; b=AD/Zx1pSzLDi5IEYIRhEMbc8mh8i4eoIxKZzHViA13m5p94MDo4liqsfbMPhIOeeCy o3C8nLn4/GuloJdCoEviGBNlp09CdctoxVVLITq6e5p6YrD356A6My3QQjRIV9zTKWfG Db1RUAAQoOjmhyurED3ptQQgfQ9GuVSWIjDrjhCRLQRiMLN4ReYi2IabNVcupBWa5kKP eNY3hs9n8IycFOEno3vgDxxGzdSnm0mnVNDexMDZEnwr7pXlZNGcz+MJA7LimLqdZEwq c5WFy0GmMvAljBFtd93UbJbOOP+vbMWkL3wuxTVwtdfXcBi921ULnC9k9EXOc2YZ6Ceh j/2g== 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=U/1lnNDJFXT2KTSG2CdXfhjby7xiGDFOJzdroFAerek=; b=aoPkxP69xJulQP8JR3JBymz2O2BnV08SJyf8wLpK2N1ytYDMpFipHX5CECYPdYs/V9 kvLDcGMehrUqPy082bK4WB2QcU3kzc92B3E0iX4dTW940qRfZ+0iIrBL4wLWjsweeeqR NhTqYNmafAjQOXPZ6ultcHWtp3vG/EH/uNbRdoClcMshk5hw8SZMdBkKfiRY9D3Kr3mB aaFZCgBBpw8oKKOtnwEXa+W860QtPJkChKYOo+W5jN16n0GuZeJjzKnhNIEV7QDuuAvq C40hlIeE7t2FCgLScz5IXtC7Z92Rj8o4ubOWqgZh9KwqkJj6nQAz1Jt1PPFRoijxY4E1 IoxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DAr2r8Fs; 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 b8si18958760ple.370.2019.05.20.05.20.48; Mon, 20 May 2019 05:21:03 -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=DAr2r8Fs; 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 S2387627AbfETMRp (ORCPT + 99 others); Mon, 20 May 2019 08:17:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:58744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387611AbfETMRl (ORCPT ); Mon, 20 May 2019 08:17:41 -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 908E021726; Mon, 20 May 2019 12:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354661; bh=hJhvb1Dms8MsY1g+rT6DS/w0wdxn/uWL5NtjZwJQrT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DAr2r8Fsk7cub1qOgXWSNoBKZl6pZJQ9NVt/EGNGIWTDprZp9NZtydvaSf7MSxcgJ p7jnGmdVcpQvLL0hGADGymqFjCSek7LcOiKh9xtRnhGv0DByQUahk2UO/jDzUYfXbk VLghhireTN03ueK1mIWXqzaYyL7tCMMiKAwAPOV8= 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 4.9 41/44] ext4: zero out the unused memory region in the extent tree block Date: Mon, 20 May 2019 14:14:30 +0200 Message-Id: <20190520115235.768655787@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115230.720347034@linuxfoundation.org> References: <20190520115230.720347034@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 @@ -1047,6 +1047,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 */ @@ -1138,6 +1139,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); @@ -1217,6 +1222,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); @@ -1282,6 +1292,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)) @@ -1307,9 +1318,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);