Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2573819yba; Mon, 6 May 2019 08:11:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzinpTXZXeVHP1GpmHBhUB/VAFecGzLKZQObWE/t6iEQ2xn/6lvJvIvUEzFe6T7DL1uenFV X-Received: by 2002:a17:902:29c9:: with SMTP id h67mr33175379plb.114.1557155516553; Mon, 06 May 2019 08:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155516; cv=none; d=google.com; s=arc-20160816; b=C2i60d7ZRo6wiG9v1RY7m90O/x9Te4E1PSFfYHLyqEYwuGIGJ2YZjyARmaWTkpSZFT 2Os3/KOe7FpRDo7rLda/M4iyllm5UNuTAZKDkfTiw7xf8rjvotmAOFwrgeJFlzFRvNCp 8hhRWi5ZIswLEBd++EW1UQ5RhTlKqTRCHJa1+TlUqoiecsWMm6Hka4L+taod3HFwVBSR cFKnLWhCSHY7g+n2ILFfxNrZ2zAynp8xWp2ePd5KczTgYD+zmp/4RhPhP/Saj3jZ4WRv 5TqX6QDKALHrNIysHJH0p+OPA2NhMk6mJFgz/9lNyC04KEJ1mLnGP7XhV77kIfNaI7Hh T7Zg== 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=pfe+SxezyDrGdONjv/QZ5cB6x68a9lOzpshKka41L5s=; b=oF3XKxpaE7GIAUMxi5fn/vfkLyopGlO+Mw8KM3ftRoEtejOygCNKjNpgTHvvBR0UG2 3ZNqx5K5Y3LxZw3/nRKngDEWC2VJeH7/h0ZYHIeykASTjzzB7zoQ9cQc5xpwi/rtyWFg RJTI6HEZ9txjJBCx2Kx17M4Cy914FsevlSFrKwK0/1R+ivxrJpYsiucNjPX5QGv33KIO Z68CkQc1ewtGiDXwC8rQ+GiAAwDwkJdTwlaZRujH8hepTJ8YY8yA4+RZHQw4CczwA+dz Iz5i9C66VyAt55OMmiFpGwUAL9Wlq7W5y5X+1gIKFnXjoDVnqQGy6wNbDViiq0Vrho2I /XXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W0CxH65H; 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 d11si674773pgt.76.2019.05.06.08.11.39; Mon, 06 May 2019 08:11:56 -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=W0CxH65H; 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 S1727052AbfEFOf5 (ORCPT + 99 others); Mon, 6 May 2019 10:35:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:56094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbfEFOfx (ORCPT ); Mon, 6 May 2019 10:35:53 -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 50419204EC; Mon, 6 May 2019 14:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153352; bh=hljp+ch+ecoaQHcffwwaeNdZOy52z8Z9nCFkAW0YfVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W0CxH65HSv3t3xwGXN7hum0IsFGaidwbCoZysWtqxSvNnD3fU8lVVx3CJHzG9Ujto MnYPvPb+9lVu5oSpsV27FXkY/cFEm7PeZWsqBl6PYecFAAcistOSvvjRjBCjeHvG8V GeomSUZwNiukznIIuf3UGYy9fwTL35IdraBHpIDA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , "Sasha Levin (Microsoft)" Subject: [PATCH 5.0 057/122] debugfs: fix use-after-free on symlink traversal Date: Mon, 6 May 2019 16:31:55 +0200 Message-Id: <20190506143100.115753154@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@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 (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.20.1