Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp311130yba; Mon, 20 May 2019 09:07:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWkXQqvRV288uJQO1wxuSwE0jLG87BkIBQ4Qxf/3UvNo00SUSNnkPupAyBE5KYAZga52hN X-Received: by 2002:a65:64c9:: with SMTP id t9mr75640923pgv.221.1558368428904; Mon, 20 May 2019 09:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558368428; cv=none; d=google.com; s=arc-20160816; b=lRa/HEnIudb4SsBANFhLHNSvw+hFwOAbPbF9euVnRqrYOoAOF2yz1G7Sh59rWgpGvh X37JI8RvTMUeyyhX6nrNODI1ca6pzs/8A0Y4TBVKuhBhyvtOtG4ojJYiJn3jSB+Rk5ey 0edFPtKsfN2nsoii9z9w/r2/YvBa0Bi38b4iJRNuVaafYtXjYc81c+nDVJdNNJYfSHbC cuQpL/WsUm5kJffBSB3kAGZ/8VAChEO8JbvARncUDsRrmMj6EX7ou6lnJOAcw1uuQc13 oCjNqJlSwr1Ew8G8yhFiGMpe27dqJYn+nX87S32glPlozQJer/eRzKZbG4ER7Kbpx4gI PTgg== 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=0e+LWs3aW5VaevWtA+UqHn97EgIVJIBf6j1CwYTzevU=; b=eM+o4Lspf7f4LZQfxqwfHEXvYM39fv/riLKZ3XRJTSevh5qZAeTzzKc7Lg7rMJNDz1 OqIWubaCpSiHNsKZRrscli7aFJkaDlRKSoWaBOAVy6+IXwM6FXsj8p1IypFKm1Up+ijD qSE25XBwWMiKZ6kV3B7Bd8tiyaMo6tEwmYQy1QYOhVtm+NU4Z/yd8Gxhut5/mAgoQsB+ aQJ2YCuDJKb3fYjvuqt7GOUPqvelF2g0CZuzEDjHzYp0A4FbtJ3XBcin3y6kqP51aK2D 5ynzpk2gJy2Q5YciZB4pvzfecqtGr0NcRwN5lPNLMV7FlPI7bSTjxU2RUR8musyaGImj CmCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kzm46XQ8; 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 o4si18229547pls.391.2019.05.20.09.06.53; Mon, 20 May 2019 09:07:08 -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=kzm46XQ8; 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 S2389158AbfETMZq (ORCPT + 99 others); Mon, 20 May 2019 08:25:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:40958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389147AbfETMZo (ORCPT ); Mon, 20 May 2019 08:25:44 -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 46BB3214DA; Mon, 20 May 2019 12:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355143; bh=Y+8Y21qUCRMYjTUDfur/iQJvKkhuVBO32bLyVOUL494=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzm46XQ8snnfvLOD4aoSluf2zRdhGJJ+sqVCtPIVDcyFpy8UjzLoC9SQiduxGd668 RPdfbOErynIFto5+WWO2VZ2GL+cdE4X9M1bdKnWoAMvz4VIFZkqWgFbvNo9UUtw98c zVrnZ0TNfcQKT6FXVGxqFLwTWhJEHjHph6QcFaO4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sahitya Tummala , Theodore Tso , Andreas Dilger , stable@kernel.org Subject: [PATCH 4.19 087/105] ext4: fix use-after-free in dx_release() Date: Mon, 20 May 2019 14:14:33 +0200 Message-Id: <20190520115253.290028376@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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: Sahitya Tummala commit 08fc98a4d6424af66eb3ac4e2cedd2fc927ed436 upstream. The buffer_head (frames[0].bh) and it's corresping page can be potentially free'd once brelse() is done inside the for loop but before the for loop exits in dx_release(). It can be free'd in another context, when the page cache is flushed via drop_caches_sysctl_handler(). This results into below data abort when accessing info->indirect_levels in dx_release(). Unable to handle kernel paging request at virtual address ffffffc17ac3e01e Call trace: dx_release+0x70/0x90 ext4_htree_fill_tree+0x2d4/0x300 ext4_readdir+0x244/0x6f8 iterate_dir+0xbc/0x160 SyS_getdents64+0x94/0x174 Signed-off-by: Sahitya Tummala Signed-off-by: Theodore Ts'o Reviewed-by: Andreas Dilger Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/namei.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -871,12 +871,15 @@ static void dx_release(struct dx_frame * { struct dx_root_info *info; int i; + unsigned int indirect_levels; if (frames[0].bh == NULL) return; info = &((struct dx_root *)frames[0].bh->b_data)->info; - for (i = 0; i <= info->indirect_levels; i++) { + /* save local copy, "info" may be freed after brelse() */ + indirect_levels = info->indirect_levels; + for (i = 0; i <= indirect_levels; i++) { if (frames[i].bh == NULL) break; brelse(frames[i].bh);