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_PASS,URIBL_BLOCKED,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 C2A90C282E3 for ; Wed, 24 Apr 2019 14:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 899A921905 for ; Wed, 24 Apr 2019 14:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556116511; bh=+a3uMyxXBT8XRn1KsgiM7jtVc6BioHrrcNiCFQhJN0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k9S3PJqT5w89vj/grK1ux4w01Xh8xoBr15Nw7CuUuqOif4G5DLCvb6DYpR8gRZ5Y1 MrnZDHIEPorOoRrgx7XqH/nwBKhKypHxvzLquk14IuLjmOQxY2m76WnaO46g9puZdv 5DAQ4ukdzva5zdUaQqtt6yMNgd7zDkf+DzLx9zCo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731306AbfDXOfK (ORCPT ); Wed, 24 Apr 2019 10:35:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:38922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731267AbfDXOfH (ORCPT ); Wed, 24 Apr 2019 10:35:07 -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 07753218FD; Wed, 24 Apr 2019 14:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556116506; bh=+a3uMyxXBT8XRn1KsgiM7jtVc6BioHrrcNiCFQhJN0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S9mPwb8HHPwNIyXmrfMvYEE16NOtcNTJIrdNcGY+thm6tCXcTf8b+6NIefkkoydYD 2Qj1g5jC6A9qt70iJ5FDHcIUycHOzSXiI01DbsonGJ8jcI0vHgXnXz0y7F9kq1mhjF 3RMUW8ENr4Euikndcy1SQCGFv4hR942RGM5CJu4E= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Al Viro , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 34/66] debugfs: fix use-after-free on symlink traversal Date: Wed, 24 Apr 2019 10:33:08 -0400 Message-Id: <20190424143341.27665-34-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190424143341.27665-1-sashal@kernel.org> References: <20190424143341.27665-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro [ Upstream commit 93b919da64c15b90953f96a536e5e61df896ca57 ] symlink body shouldn't be freed without an RCU delay. Switch debugfs to ->destroy_inode() and use of call_rcu(); free both the inode and symlink body in the callback. Similar to solution for bpf, only here it's even more obvious that ->evict_inode() can be dropped. Signed-off-by: Al Viro Signed-off-by: Sasha Levin (Microsoft) --- fs/debugfs/inode.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 29c68c5d44d5..c4a4fc6f1a95 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -163,19 +163,24 @@ static int debugfs_show_options(struct seq_file *m, struct dentry *root) return 0; } -static void debugfs_evict_inode(struct inode *inode) +static void debugfs_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 debugfs_destroy_inode(struct inode *inode) +{ + call_rcu(&inode->i_rcu, debugfs_i_callback); } static const struct super_operations debugfs_super_operations = { .statfs = simple_statfs, .remount_fs = debugfs_remount, .show_options = debugfs_show_options, - .evict_inode = debugfs_evict_inode, + .destroy_inode = debugfs_destroy_inode, }; static void debugfs_release_dentry(struct dentry *dentry) -- 2.19.1