Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp999753ybt; Fri, 19 Jun 2020 21:08:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXoEXlDaSKk7bOeotL3ySmSNqsu7ebSshCuXfc4rk6GXwjnizfilMKmiXyADPlfrWzsAKq X-Received: by 2002:a17:906:380a:: with SMTP id v10mr492276ejc.255.1592626082946; Fri, 19 Jun 2020 21:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592626082; cv=none; d=google.com; s=arc-20160816; b=qzG6L6o1WQiBCFpZ9Ox3qtG0ktiERieRpUASMzgVSSLF28GA7woqK36ugHfQhwTm7x KBp6ssI/1IV4ppm0wI7aYdAzuloSA6m5w72Fm3IV2D6sh7vTQLqmRdgTDJBxd/HnW0Zj wvEkoJXCY69uuRQudq3AHDKKKvYaFIEC/+upCzaTFcKqRi+RSbIjIxUaAbwce9iryVLl zj1W86aRI2VmuBNqnRWTgIpKZXwbx3LtZRHTW8BGZcYfUNiECJz6O5kix2ht1cyXr6bJ v5vtO11QVAgsqo+vb3cp9rXFe0lprNckHXozWKKv3llnQJdFim++HaoFkoK5kt6e2yVH ar4Q== 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=gUSde34WrtQcnvy9nwVU2a7gu38GAyEJlgEYXNsEvd4=; b=mHqNQkF+xA4R9pte7ZVF6BwUBo0+bCf4oBWa4e089v9SOnG/Xr0+yz5xUs2ozJ8vSl hvsm3NuGaUxfxN4AYcRQzy+piFKW9I4cZBhA+m6999kIOspuhHVvVXmtbbDVWQzkyCX8 h/oImC0NunT6z6VoGT3lNwTbFUxFebRAGKbKlqaIxQzY6/nKlYjEdLfy2zglkiOf2qs2 z0Jzzo2m85tls1Tkhrz+0hjNS+4CcqOP9q0ta7ruyJAr4pjvYqpBU1cHrafYue1igdCQ 9HAslXe+An1/3KE3YEkjo6YIc3dGT9tWgn6WdjfnnVNekP3cRYkv+w5R7rVpoRcIN/Pc FWBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=neCFEXLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s26si711099ejz.453.2020.06.19.21.07.40; Fri, 19 Jun 2020 21:08:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=neCFEXLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388117AbgFSQrv (ORCPT + 99 others); Fri, 19 Jun 2020 12:47:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:59106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388196AbgFSOk4 (ORCPT ); Fri, 19 Jun 2020 10:40:56 -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 7A010208B8; Fri, 19 Jun 2020 14:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577655; bh=F32g8YyTxc+h/frpxGIHoJ+5HtmH+lMD8vj0E1M3+VA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=neCFEXLEB3QQNBSkMPFbVbttbuVxtsyIq/uoW6TjoCwkCl7F85YOiUADGws5vu3L0 CC5EObVY1klpHITkV2oA/AxFWBzrWYoS5Ct974tJMCbUc6DTWvY9VAxE98Jq3lPjim eUOU6mMuI6P0l3jTIVb+fpwdr4K5rlavmUI53UQs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7d2debdcdb3cb93c1e5e@syzkaller.appspotmail.com, "Eric W. Biederman" Subject: [PATCH 4.9 036/128] proc: Use new_inode not new_inode_pseudo Date: Fri, 19 Jun 2020 16:32:10 +0200 Message-Id: <20200619141622.106634403@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@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 From: Eric W. Biederman commit ef1548adada51a2f32ed7faef50aa465e1b4c5da upstream. Recently syzbot reported that unmounting proc when there is an ongoing inotify watch on the root directory of proc could result in a use after free when the watch is removed after the unmount of proc when the watcher exits. Commit 69879c01a0c3 ("proc: Remove the now unnecessary internal mount of proc") made it easier to unmount proc and allowed syzbot to see the problem, but looking at the code it has been around for a long time. Looking at the code the fsnotify watch should have been removed by fsnotify_sb_delete in generic_shutdown_super. Unfortunately the inode was allocated with new_inode_pseudo instead of new_inode so the inode was not on the sb->s_inodes list. Which prevented fsnotify_unmount_inodes from finding the inode and removing the watch as well as made it so the "VFS: Busy inodes after unmount" warning could not find the inodes to warn about them. Make all of the inodes in proc visible to generic_shutdown_super, and fsnotify_sb_delete by using new_inode instead of new_inode_pseudo. The only functional difference is that new_inode places the inodes on the sb->s_inodes list. I wrote a small test program and I can verify that without changes it can trigger this issue, and by replacing new_inode_pseudo with new_inode the issues goes away. Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/000000000000d788c905a7dfa3f4@google.com Reported-by: syzbot+7d2debdcdb3cb93c1e5e@syzkaller.appspotmail.com Fixes: 0097875bd415 ("proc: Implement /proc/thread-self to point at the directory of the current thread") Fixes: 021ada7dff22 ("procfs: switch /proc/self away from proc_dir_entry") Fixes: 51f0885e5415 ("vfs,proc: guarantee unique inodes in /proc") Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- fs/proc/inode.c | 2 +- fs/proc/self.c | 2 +- fs/proc/thread_self.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -417,7 +417,7 @@ const struct inode_operations proc_link_ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) { - struct inode *inode = new_inode_pseudo(sb); + struct inode *inode = new_inode(sb); if (inode) { inode->i_ino = de->low_ino; --- a/fs/proc/self.c +++ b/fs/proc/self.c @@ -53,7 +53,7 @@ int proc_setup_self(struct super_block * inode_lock(root_inode); self = d_alloc_name(s->s_root, "self"); if (self) { - struct inode *inode = new_inode_pseudo(s); + struct inode *inode = new_inode(s); if (inode) { inode->i_ino = self_inum; inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); --- a/fs/proc/thread_self.c +++ b/fs/proc/thread_self.c @@ -55,7 +55,7 @@ int proc_setup_thread_self(struct super_ inode_lock(root_inode); thread_self = d_alloc_name(s->s_root, "thread-self"); if (thread_self) { - struct inode *inode = new_inode_pseudo(s); + struct inode *inode = new_inode(s); if (inode) { inode->i_ino = thread_self_inum; inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);