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 82235C04AB4 for ; Thu, 16 May 2019 11:46:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D43920848 for ; Thu, 16 May 2019 11:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558007183; bh=IMJiCZPSYS+y4kCm9xDnxJHtTTXzXjnfjEhhpmvOUww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tT17MDCz4h7J9WFxH+nYenyJz23D1UHfcQeWUnEpAyQV62mLYvGRxM4cDXVKoXCaf NfmJtCLB+xqHW0cD2/pbTWbVLBJJRyRTDqRsoJYKQZ6lAmTGBNlHwjEWXaNd0Db/2W Yg5JQwTdp/uSo65dwAc0o/nyDVYpVZD5J/6hwEvY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbfEPLqR (ORCPT ); Thu, 16 May 2019 07:46:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:49108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727838AbfEPLkm (ORCPT ); Thu, 16 May 2019 07:40:42 -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 A56762087E; Thu, 16 May 2019 11:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558006841; bh=IMJiCZPSYS+y4kCm9xDnxJHtTTXzXjnfjEhhpmvOUww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcWotE/z0WKiOdEvle406B1BVDGeYpHi5wNaOBDQ31HTbjmBGANfhD2RqHo+tA6/i J/9zmcnSDHLows4K0wvOeR39kfr7RbnoeKlHscfBG+pOKMLZVsIdywUWf7svpB1ylh 1xFIguL92KXFa3wovU5eb1y69p18qm0jAfs3Ly+8= 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.19 10/25] securityfs: fix use-after-free on symlink traversal Date: Thu, 16 May 2019 07:40:13 -0400 Message-Id: <20190516114029.8682-10-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190516114029.8682-1-sashal@kernel.org> References: <20190516114029.8682-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 46c874419652bbefdfed17420fd6e88d8a31d9ec ] symlink body shouldn't be freed without an RCU delay. Switch securityfs 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/inode.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/security/inode.c b/security/inode.c index 8dd9ca8848e43..829f15672e01f 100644 --- a/security/inode.c +++ b/security/inode.c @@ -26,17 +26,22 @@ static struct vfsmount *mount; static int mount_count; -static void securityfs_evict_inode(struct inode *inode) +static void securityfs_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 securityfs_destroy_inode(struct inode *inode) +{ + call_rcu(&inode->i_rcu, securityfs_i_callback); } static const struct super_operations securityfs_super_operations = { .statfs = simple_statfs, - .evict_inode = securityfs_evict_inode, + .destroy_inode = securityfs_destroy_inode, }; static int fill_super(struct super_block *sb, void *data, int silent) -- 2.20.1