From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C23CC04AB4 for ; Thu, 16 May 2019 11:44:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 401072087E for ; Thu, 16 May 2019 11:44:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558007078; bh=FXDuVxiBXbsl4QZDdR6w/GeJ6pexSEJO3wfr+1TAQfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yreEKW0zuc/LmjrnAmSJc9hgdlmU+d5z2ALETRSedumdNFjECTARE+EgKuGRZjecY hEyv+5qPlFkEOLUhgmdaOTsa1p+ZToUBd6o8Fq7rN9NBAH1cZLx69LxMXcfrw1DqgP p7q1SDh+LiFJ37fyxnvoGm9pOr1Jvh8oM708zJ98= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727410AbfEPLod (ORCPT ); Thu, 16 May 2019 07:44:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:49954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728056AbfEPLlR (ORCPT ); Thu, 16 May 2019 07:41:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5D2BA216FD; Thu, 16 May 2019 11:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558006877; bh=FXDuVxiBXbsl4QZDdR6w/GeJ6pexSEJO3wfr+1TAQfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3LvwTK0Iy4KzN6Vs3jGwxjXOt9bmdWjvCUwNZVXyrkFkJueu3ej8KUnvO1ZOcqAZ /NG6VW1mVQXgtAIBjpB6rlrpu6au+MOSo2xN14rk2hwYn6ZoJdrgXfL2MBYgEpQjcf K2dfzo+p1Yb7lMZ+04fsqt5QJKRaoOJTXnMdN1Wg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Al Viro , Sasha Levin , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 08/16] apparmorfs: fix use-after-free on symlink traversal Date: Thu, 16 May 2019 07:40:59 -0400 Message-Id: <20190516114107.8963-8-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190516114107.8963-1-sashal@kernel.org> References: <20190516114107.8963-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: From: Al Viro [ Upstream commit f51dcd0f621caac5380ce90fbbeafc32ce4517ae ] symlink body shouldn't be freed without an RCU delay. Switch apparmorfs to ->destroy_inode() and use of call_rcu(); free both the inode and symlink body in the callback. Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- security/apparmor/apparmorfs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 0e03377bb83ea..dd746bd69a9b2 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -126,17 +126,22 @@ static int aafs_show_path(struct seq_file *seq, struct dentry *dentry) return 0; } -static void aafs_evict_inode(struct inode *inode) +static void aafs_i_callback(struct rcu_head *head) { - truncate_inode_pages_final(&inode->i_data); - clear_inode(inode); + struct inode *inode = container_of(head, struct inode, i_rcu); if (S_ISLNK(inode->i_mode)) kfree(inode->i_link); + free_inode_nonrcu(inode); +} + +static void aafs_destroy_inode(struct inode *inode) +{ + call_rcu(&inode->i_rcu, aafs_i_callback); } static const struct super_operations aafs_super_ops = { .statfs = simple_statfs, - .evict_inode = aafs_evict_inode, + .destroy_inode = aafs_destroy_inode, .show_path = aafs_show_path, }; -- 2.20.1