Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3796446img; Mon, 25 Mar 2019 18:44:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAJlTFE/L+mS2SHlAjZOLKj2tPF2Y7xqqWs615R2oYcu3gmLTdHaa1vGotolV7ahU9elUj X-Received: by 2002:aa7:91d7:: with SMTP id z23mr27613030pfa.137.1553564685571; Mon, 25 Mar 2019 18:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553564685; cv=none; d=google.com; s=arc-20160816; b=XSZSNwspglntVEa+RAN5sA8iwrBQSwc1othr/9Fv4JlYqYy7hosuegqB2DsM5ojh38 iYuOH1tHu2B1d4JdqS48/7TnZ6W68wcqzallTvwKQiaa+wGOrgUXa8FPABsk95dl3TaB NvZsmmFMLzWV8tQ1xeMqpSaagCzsCmYXWHQVTvMTi1XOFLu1exPKlRu2H1ZWA4EB9rGo hZT+3anES1Knbroawkw6frYP3mE5D/QbjwXwwzlgN27ikvjY/ZUewiaKajGaLp8BQtdi xzICC/H1GkMxP+WAqNa+/fY0DMlwZ+LljX1RIFYy0kmdoMWeOEdj07XMzgfNtkGNHPK9 DPGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=HUfHgr+tc1id4+TwDmQfceRvAbvOvmf8V7ZlsZhn4GQ=; b=QrJ+/2VH7eHCa+PUPDZYCQNotCgtBRhnCBUxBqwNRLCSJ6nBISUAZv75PrKYaci5fd A20c1Jtu+QVV+blT4nPJFJPZql5QjsTsTZOkeTH7AwiP+u8KDyF91nsvr8tZwW2PG4fS 7bmY4SxmwqaZDWkyPyIo0lwX8ugdf50H2h0PtI5HRdS3zZskyRe/Ffqul0Zlx+cEGNhU /AWDIRud3rv2wUVwV55cK5OFwP+K241mHgu9IbKokqaEkqt+ADaJKkiatFPHb6wgPbsE zKoDM/vf1ACNnryyfpl5EmmCo/5bIwfDbqkzP5XcYalrw5lOp+hwGlaD0q4tFmPJjGqq 5eOA== ARC-Authentication-Results: i=1; mx.google.com; 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 v25si5804826pgo.317.2019.03.25.18.44.24; Mon, 25 Mar 2019 18:44:45 -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; 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 S1730634AbfCZBnm (ORCPT + 99 others); Mon, 25 Mar 2019 21:43:42 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:58700 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfCZBnm (ORCPT ); Mon, 25 Mar 2019 21:43:42 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1h8b7p-0004dB-S9; Tue, 26 Mar 2019 01:43:37 +0000 Date: Tue, 26 Mar 2019 01:43:37 +0000 From: Al Viro To: Linus Torvalds Cc: syzbot , Alexei Starovoitov , Daniel Borkmann , linux-fsdevel , Linux List Kernel Mailing , syzkaller-bugs Subject: debugfs: fix use-after-free on symlink traversal Message-ID: <20190326014337.GX2217@ZenIV.linux.org.uk> References: <0000000000006946d2057bbd0eef@google.com> <20190325045744.GK2217@ZenIV.linux.org.uk> <20190325211405.GP2217@ZenIV.linux.org.uk> <20190325233731.GS2217@ZenIV.linux.org.uk> <20190326013858.GU2217@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190326013858.GU2217@ZenIV.linux.org.uk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 95b5e78c22b1..f25daa207421 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)