Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2554544yba; Mon, 6 May 2019 07:57:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9VCJYGxE/Gmka8+L2k0E+DArywryb1vwggv1kdXeEYxm0e9Yz867/1mjOsL2Ko/wlqXJh X-Received: by 2002:a63:5012:: with SMTP id e18mr32162202pgb.383.1557154646442; Mon, 06 May 2019 07:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557154646; cv=none; d=google.com; s=arc-20160816; b=S+y1+OHqKRIldhi3IoI1bl0KXkEvyaRUdXZL/erasio0gednPQU9Y5A4PX5iPxBZWR tceabg2v1rr5O2QVjFuwTft/OQQ0UZN6Q/KBLZnx88RcUyKW3GfPFwss7weJi3nZhfu4 diI9UjJ1tpBSMXCmwrgfEvp5V5nqYMTN+qnDt0cZUXz4NCCdEV+zPpcjBUVNyNKsrkyO 3H3F4wVywOWo3jEADzK32erX/rOV+IOkzNJbi0eSHz8UN8oPqxaZbJgA8OZyvp8Ilrwq amNOGKbLL4KMGAD4ln6aCgqBztCNsjPG+l/MxYmFGU7QeubydjQSQ5pp6xk31PcTeDor TslA== 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=rGbj0GOQE5eisIJu7ocTJYUsjvnqhxa1neGpd/bRhk8=; b=Sl6U0P+38Nt6gFXCFJqD7L7SgoZXpg1D8HHgotbONFYdy67s7+KKPCMDXn5auBo3Dc y5VcZ5kRtMFSDytaf7zjmUrvGX0VOiprNg5ivO3+95PPl9AoVPxSjCGn7E0NsdQKbw8r cE4FfXEra5CNpBx6SDIQcSPmjoHfwst3jOLIbRI5Lne4upBQeoEjRBTVto+rWhOCYJyS MmzY3MTTeyR50QMPsRt5AVzB4+vZlK9p+tGuZWgR0b0DQm0D36ilTPFdmAE8wIbJYn6v YDNRNUjCza7NECysgpwTeux5VnMUqlw+wSaE+hcobfEeSAEz6avta/K4YdiShcWyyHSj 0tKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="GR3V8/rU"; 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 p13si8088155pgh.417.2019.05.06.07.57.10; Mon, 06 May 2019 07:57:26 -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="GR3V8/rU"; 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 S1727444AbfEFO4V (ORCPT + 99 others); Mon, 6 May 2019 10:56:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:41866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727693AbfEFOpN (ORCPT ); Mon, 6 May 2019 10:45:13 -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 308972053B; Mon, 6 May 2019 14:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153912; bh=+52cvG3pHsqSgjG/lMIyF9g7CcFQcev64IC0EDoxeF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GR3V8/rU8/PU3cnjxg5ANjKW5PYeZSKLNIv0rvveMxazpwtNpMgFN1oWKr1SgbhUX 2O5q9A/UKPP5EyAN9BxYWdpZS4BSur8glMLSSDjpdV8WJt/WAtWNghcn5eZXbA3apA LpWpYxqYqYOSUBHBGITlQzYwu9slp8WPh/BeIrC4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Sasha Levin Subject: [PATCH 4.14 41/75] debugfs: fix use-after-free on symlink traversal Date: Mon, 6 May 2019 16:32:49 +0200 Message-Id: <20190506143056.946616088@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143053.287515952@linuxfoundation.org> References: <20190506143053.287515952@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 [ 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 --- 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 ccfe1e1cb6bc..f4df6feec271 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -170,19 +170,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 struct vfsmount *debugfs_automount(struct path *path) -- 2.20.1