Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2960607imu; Mon, 19 Nov 2018 08:39:28 -0800 (PST) X-Google-Smtp-Source: AJdET5dJpOKDx3lero5PaJOAYlo2bG39SobnBlk9Omu6PREHLgChU/FWLljDc0P3NCwcshSP64EA X-Received: by 2002:a63:ff16:: with SMTP id k22mr20824775pgi.244.1542645568175; Mon, 19 Nov 2018 08:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645568; cv=none; d=google.com; s=arc-20160816; b=QSh2ERywLVKn99ZOY9S0uKhf/opuE75IIbcw7ui/dW+4PWx8cIYq42i96uHtphuvaF nMLmivAsmngM/mnM4elt6QBhuOU/+D+xvWG8SssQR8Ix+TRYZJvN85u/jrrGZJNlc5Tx 7DKzN3cISHWxLDovheOEcfaKaxrBqtgkZ/XaH4PQg+M0SAwdF0yKt1ECgEjSYRikt6UI Co6MGbRe+HIrp0JzlqQtNB/7VptptnZjGysGV6JfUrV4JEnrrmXdb20EXf+gSSVNUFWZ JqhErJb5lqASLDA+3dXTnyJvvhaHxS21FJG2wqprIspCoMyRaIWgVK405O8AoGbXqYRs ijiA== 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=nlVSjM7EPh5isnFASBb12ZCCtA5stYvjZVsbsunzba8=; b=vQXCj8jtdfnP357GwcZV5yUvFv0UKr/O2YZCxQhXr5fnm7qb9+Yyx7VAbBnDtp8QuQ KgigcnnerolMPygddeT9HI/5vm155K7HRJWK4Nl3q2T5oTCaoOq5wrfoTjPEaZmJdhPz ishecMsYZv6VfSB0cRSHdzwvPg9f6d7Jh2gZ4rUAqjx7O0h60oZPdiM216w34et0cwgA CuO+6nSxec1GcnJ6p5wbRme6Ef3X0vXEaaIrlezm2XRuCj30WJWIp16nWINLG2CYK2yI TaAnhArN8AXvaxVTHAh4sgKf91Eiv10fMsyfYuaG7OPQXy8TdJuDTFKs3noXa0GjRoxk 2UKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dXDm6E1p; 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 x3si30971727pgj.493.2018.11.19.08.39.12; Mon, 19 Nov 2018 08:39:28 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dXDm6E1p; 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 S1732492AbeKTDCj (ORCPT + 99 others); Mon, 19 Nov 2018 22:02:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:34930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732476AbeKTDCf (ORCPT ); Mon, 19 Nov 2018 22:02:35 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 5AE7E20989; Mon, 19 Nov 2018 16:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645505; bh=rgOK3BIZaq0IEDCcf3XFisQ7OMob6jzmXE4uZgiCDyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXDm6E1phaJXM7uflFUCL7vOOGFW9t0PVpuEPjN6C0m5Pl2YtP0tolvLRY1UI4jeB D6y7gtNhcDg7LqLmHtYcWVcDaVMKdm9qxdAeY+sFZ2zpO7yfB/ZFCN76SaO/9MuJcx RIpG2vRHI/qqX2wZUeOAdex5vL4M40XZN3bObV7E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Eric W. Biederman" , Benjamin Coddington Subject: [PATCH 4.19 150/205] mnt: fix __detach_mounts infinite loop Date: Mon, 19 Nov 2018 17:27:37 +0100 Message-Id: <20181119162638.599154127@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Coddington commit 1e9c75fb9c47a75a9aec0cd17db5f6dc36b58e00 upstream. Since commit ff17fa561a04 ("d_invalidate(): unhash immediately") immediately unhashes the dentry, we'll never return the mountpoint in lookup_mountpoint(), which can lead to an unbreakable loop in d_invalidate(). I have reports of NFS clients getting into this condition after the server removes an export of an existing mount created through follow_automount(), but I suspect there are various other ways to produce this problem if we hunt down users of d_invalidate(). For example, it is possible to get into this state by using XFS' d_invalidate() call in xfs_vn_unlink(): truncate -s 100m img{1,2} mkfs.xfs -q -n version=ci img1 mkfs.xfs -q -n version=ci img2 mkdir -p /mnt/xfs mount img1 /mnt/xfs mkdir /mnt/xfs/sub1 mount img2 /mnt/xfs/sub1 cat > /mnt/xfs/sub1/foo & umount -l /mnt/xfs/sub1 mount img2 /mnt/xfs/sub1 mount --make-private /mnt/xfs mkdir /mnt/xfs/sub2 mount --move /mnt/xfs/sub1 /mnt/xfs/sub2 rmdir /mnt/xfs/sub1 Fix this by moving the check for an unlinked dentry out of the detach_mounts() path. Fixes: ff17fa561a04 ("d_invalidate(): unhash immediately") Cc: stable@vger.kernel.org Reviewed-by: "Eric W. Biederman" Signed-off-by: Benjamin Coddington Signed-off-by: Eric W. Biederman Signed-off-by: Greg Kroah-Hartman --- fs/namespace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/namespace.c +++ b/fs/namespace.c @@ -695,9 +695,6 @@ static struct mountpoint *lookup_mountpo hlist_for_each_entry(mp, chain, m_hash) { if (mp->m_dentry == dentry) { - /* might be worth a WARN_ON() */ - if (d_unlinked(dentry)) - return ERR_PTR(-ENOENT); mp->m_count++; return mp; } @@ -711,6 +708,9 @@ static struct mountpoint *get_mountpoint int ret; if (d_mountpoint(dentry)) { + /* might be worth a WARN_ON() */ + if (d_unlinked(dentry)) + return ERR_PTR(-ENOENT); mountpoint: read_seqlock_excl(&mount_lock); mp = lookup_mountpoint(dentry);