Received: by 10.223.185.116 with SMTP id b49csp2378438wrg; Thu, 15 Feb 2018 10:41:12 -0800 (PST) X-Google-Smtp-Source: AH8x224X1rY22OQOAwM2J/sy9LHC6vASPuNed9xIz5qCYW40g8U6pqGTEpzSHzXCuqqzaWsIyS7Y X-Received: by 10.101.75.193 with SMTP id p1mr2995082pgr.63.1518720072001; Thu, 15 Feb 2018 10:41:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518720071; cv=none; d=google.com; s=arc-20160816; b=NbeNPEKyA1gJPnac+kmNR+PrlbxXH/xqdBThWPQft4yVfofvuXIdtDSIennjDDlTVD 1D+aMR1Bj/sxNKjBMVqJu5dtVGWHw+81bvPPJlVIGI1RgGiTrP916tnWlFhGncMRiaUQ s+6ceSKlTp/feXPa3eZy/XGzrLATK1dVYnxxqQqsKKtBRRsYvVrLv35H4pMgYg48yfb/ I0TbaJs1KMCkYWz7x/EOP2oXJ/4GlXitZBga/5IQ0m64MIyU5J8HwKSrSWtO7SERqEg8 ENjdAxzFsB5nfL6764Vzh57XCZEgxFuG1Xk7rJ/z1U8TeDvw8wWrdCXSR7uqHaOKin78 0emQ== 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=Ce65ZQ7KSD9iENQh1X5DYM4YKt5Pd+NNYUCxAR5ePxk=; b=MzvrKUXPieHDZvVH5bqPB7dDwXC3a55vYrX985bMzEK+Qwd/0TuJGMMNUgxNRX09H1 19gLhRwWEUS14sNdNJNMwKJwtJCiBgGgaFMDktLpDMf5o/nPqROKGpqi5WnkCQ5m79Ht QZnZ446Bom5Fuei5UXhaaHb6iO9Q/wCXUROx3RoG3EpW30DjneaDNvTLu3xvOAZ3pd6s jAIDKT/d0ZSVtPXXHNSH+27rOuJyobVyOqLPJ5VNRI/4LFW86grRLvhecxGdJbIDeiKb sS8Rxqhyho/UXYj0XPP11R828it1H4y0IxInV26n/KtEdT3VEYHvWT+w48H0u+nVvfyY Sxyg== 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 v204si197721pgb.212.2018.02.15.10.40.57; Thu, 15 Feb 2018 10:41:11 -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 S1162770AbeBOPXu (ORCPT + 99 others); Thu, 15 Feb 2018 10:23:50 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51584 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162739AbeBOPXr (ORCPT ); Thu, 15 Feb 2018 10:23:47 -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 50A82E66; Thu, 15 Feb 2018 15:23:33 +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.4 070/108] nsfs: mark dentry with DCACHE_RCUACCESS Date: Thu, 15 Feb 2018 16:17:07 +0100 Message-Id: <20180215151232.115260005@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.267507937@linuxfoundation.org> References: <20180215151222.267507937@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.4-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 @@ -95,6 +95,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) {