Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2548496yba; Mon, 6 May 2019 07:51:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGnDH+qQsIHV1QYSgPXEiL/ycbhHhdu3xruUiy7FGibfCooRZMHyB7MU2czP9zTcG8unRh X-Received: by 2002:a17:902:2b89:: with SMTP id l9mr33559092plb.331.1557154275582; Mon, 06 May 2019 07:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557154275; cv=none; d=google.com; s=arc-20160816; b=si1iDdrtNqIKQTG70PDZwVAPJ4yV120J33Y2c7+PmZ/uEpAMejZXIzg2jx4BnsBi+A bDqXxmkk8r6MNVuxTx5SJJ7uyxWkbOuvZs7DkGbpkPLKSOjn6IVqOy1u2Q737xvCuzUn UmJvfOWjW4ckY8mrkhO1DA1MYPuBzI0uHzu3Ecmb4Hc5MBZfe2uKOR8gbd9rqum0S+po TITIQPGpM4tDlx0PSfXymzSE9oyFjlMaPp2EE+EMxb4+0foh4nhEE4gLD8onBdLN1rGY HnEiQbhPfiR2tdQvY/9ey5rKhlWvL6vqukA1tMP/6NJF0YCNzkNYZeMtS+Bf0cE/WuBf xInA== 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=oZtgyAGiQUfJDvbRcjF90gCYlTDNb+U7/ju87Qy8jes=; b=dhGVXgpkemGaNunVEZ27A3hq5STIVf9J0QY84VWHCZtljjS/2MGFQIfCVjXA4imzTs mLEaAR/MBlelM7nF+AiYi+AqAIlK4u1URgd8p2AFO9sub3RBhH4Beo0Pi7lX5qs0r+ln ar4ZvRibl7fajAdWLYcBlhKnSXhv6RuKN5q/qKfm5Z8m0BFW9Q4OpuZPcaK1Y3p5/6Vb Rq7/DEHvKB21xqh6GWk0WU5O4u0NwCIEZrEqPIBveG5tPH50eAg/ugdjAwa+T8zHomgq s88FCPOU12e5uAKyZHyDqZghbnyyKs5+C7hP7SjroE1w2QhYYwQFwt3PSZQj8lPRJVYp pQ3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NAFf8ULk; 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 g5si15366729plp.120.2019.05.06.07.50.59; Mon, 06 May 2019 07:51:15 -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=NAFf8ULk; 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 S1728860AbfEFOuM (ORCPT + 99 others); Mon, 6 May 2019 10:50:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:51504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729597AbfEFOtj (ORCPT ); Mon, 6 May 2019 10:49:39 -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 C0E0621530; Mon, 6 May 2019 14:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557154179; bh=Hnb7z3+7JBqf/LXbuVAtgRZVI934LRCWUyNEAg07ttQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAFf8ULk5aPoDrmm/RMZsHcbxDwIyRb20j4GBjXSLxjNX5wgr4hDA9BngI1pks2BS 3oKNei4pRsFsXc6SsZRbY1qKA+BQMCXRFm5tpV3IKaHkRUEk8878vLOopEEWJhGYbj QxeJfEbBOWocv4BhqhWsUD6iANfqsfNLcFAgEfqM= 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.9 41/62] debugfs: fix use-after-free on symlink traversal Date: Mon, 6 May 2019 16:33:12 +0200 Message-Id: <20190506143054.696253573@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143051.102535767@linuxfoundation.org> References: <20190506143051.102535767@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 77e9cd7a0137..20ee612017bf 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