Received: by 10.223.185.116 with SMTP id b49csp2553759wrg; Thu, 15 Feb 2018 13:32:00 -0800 (PST) X-Google-Smtp-Source: AH8x225k7F6of+fl9UiJatYo7Hmpu1U7GL2eCtgCQmcQPHwORUScVPKLXATI7nM83GQKbnPCYrMv X-Received: by 10.99.3.8 with SMTP id 8mr3283218pgd.5.1518730320120; Thu, 15 Feb 2018 13:32:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518730320; cv=none; d=google.com; s=arc-20160816; b=NpJfMIbGfh2IyNK068ueO4zMfSaHYV7G8oEpdlPxqA9Fwrk4oLHwrLSneqmgRrYBEt aSUmWVEqeafixWjkPIYiaZooZ9H/QCxMdbKsYx2pM5AhbeivOrqlRFrQjneMp+8q3/tk tswSFbozPEgGnk4EunHcX+eXMAW2IEbbBRRybzL3/uGkT9SyCXZJ0wAiBWozdrZ5l8I4 h6mbICkUnsAJIj14kXQvNChQ0oNLW8bxAC/Uw+AVQg4EoehRE+h4S/yWylLuDUHYVBIR WsUxMBPZUn+gZxJ0io2bC90nwKUrItByERCHkQMSJqE0nREp/5PSdJneuSt6L9hB+tDy UxzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Bv00ad9DCKZfh3Q+4gTFTRQaQCYhg0PU99Ntixrj5BM=; b=GZdvW9ftP3NbxfvSsuPk12dVyc9pupH3sXXgMMiDmontbiFJiM76BMO0XSE2isA/Q6 dBGJfhIYNWz3D3AJpWxT5eCVxAMzrj1CrFySmNIzdyACavO9gqPi6MA2+QLMRDQrpK9s h5YcBoIcQhBkhqdHEERs+K1QcIHQJ0W81uQ0KEHliwMGyjgXA7AU/9bKFrt4JFtYDdsI 0BzA9PNR0uSupcm3iQFeUyE58RQiZHTN6rnEG7gtx70lXCjLM2v20URf2BBapDl23N/v wKMGoFFecIZ6PRjee3JP1dchlcAUSU9ixnHn/b6fqVTyvCu923s7POeCMkXMpZ1XBsPj ZNLQ== 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 m22si154914pgv.643.2018.02.15.13.31.44; Thu, 15 Feb 2018 13:32:00 -0800 (PST) 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 S1163498AbeBOP06 (ORCPT + 99 others); Thu, 15 Feb 2018 10:26:58 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:53268 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163369AbeBOP0y (ORCPT ); Thu, 15 Feb 2018 10:26:54 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E1206FB4; Thu, 15 Feb 2018 15:26:53 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Viro , Andrew Morton , Andrey Konovalov , Cong Wang , Linus Torvalds , Eric Biggers Subject: [PATCH 4.9 35/88] nsfs: mark dentry with DCACHE_RCUACCESS Date: Thu, 15 Feb 2018 16:17:02 +0100 Message-Id: <20180215151227.488773470@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.437136975@linuxfoundation.org> References: <20180215151222.437136975@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang commit 073c516ff73557a8f7315066856c04b50383ac34 upstream. Andrey reported a use-after-free in __ns_get_path(): spin_lock include/linux/spinlock.h:299 [inline] lockref_get_not_dead+0x19/0x80 lib/lockref.c:179 __ns_get_path+0x197/0x860 fs/nsfs.c:66 open_related_ns+0xda/0x200 fs/nsfs.c:143 sock_ioctl+0x39d/0x440 net/socket.c:1001 vfs_ioctl fs/ioctl.c:45 [inline] do_vfs_ioctl+0x1bf/0x1780 fs/ioctl.c:685 SYSC_ioctl fs/ioctl.c:700 [inline] SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691 We are under rcu read lock protection at that point: rcu_read_lock(); d = atomic_long_read(&ns->stashed); if (!d) goto slow; dentry = (struct dentry *)d; if (!lockref_get_not_dead(&dentry->d_lockref)) goto slow; rcu_read_unlock(); but don't use a proper RCU API on the free path, therefore a parallel __d_free() could free it at the same time. We need to mark the stashed dentry with DCACHE_RCUACCESS so that __d_free() will be called after all readers leave RCU. Fixes: e149ed2b805f ("take the targets of /proc/*/ns/* symlinks to separate fs") Cc: Alexander Viro Cc: Andrew Morton Reported-by: Andrey Konovalov Signed-off-by: Cong Wang Signed-off-by: Linus Torvalds Cc: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- fs/nsfs.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -90,6 +90,7 @@ slow: return ERR_PTR(-ENOMEM); } d_instantiate(dentry, inode); + dentry->d_flags |= DCACHE_RCUACCESS; dentry->d_fsdata = (void *)ns->ops; d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry); if (d) {