Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2873477rwb; Mon, 15 Aug 2022 13:04:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR5VsmQXCVcN7J89z9eOnC/ItZEbh14FCiRMDHrHRt2d411hVOK8X7WRiAcNW4QYTee4l7v0 X-Received: by 2002:a05:6402:2b8b:b0:43a:5475:f1ae with SMTP id fj11-20020a0564022b8b00b0043a5475f1aemr15806946edb.363.1660593848188; Mon, 15 Aug 2022 13:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593848; cv=none; d=google.com; s=arc-20160816; b=Wi5jOBNMOCANXjU1NzRJPB0q+327PO2O09JmjbzdbEeZHAIkNRBS71g6QJR9a55Q/3 CiTe4CfnwIDXDAjLyG/SwLmAXhf83J5ii6583+GYkDBnqezVDr8hQV1GVUEHDA8cBimF zUqy78oMZXjcAAKvHm+yalqIEa7YH7pWIUFQpZwA6S7+jOu8qLfZBo/87jiMyWHoT9Iv XYPoAXorRK3wCtaMSqUOVGlY2B9n4mhIte2GKmvDpHYz1trvnWySS8xZNBy05lhkFYra weYISa9zGcj6b/6xEdpYMcfddj1ke7rpy7HLZSgv88OK6lplDE4y/H9Mb+YtA75XZ5gN /Biw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2AW6tuR5qNhHkeVzYD3zf/FIo01PCZVlyuw1698X0uA=; b=ugTYh6zUzE/co0Lx4R5BPumJcNZOsvMr9E+OR4oGIX7Q443epN4L6iTblo13B/dIcv sRVfC63yrSQYXzBmFSWM/IHHfe6qZH/9mJwcSA8ITMQ5L8XPvGMgL0BwdOyuAkMWrga9 YOGKnqQNW3ZCiyV3YJpjJjjpNipAoHPZL55afdpSM2Iy3GQsX3Hi2gjkrXJHAMv2oNpM C/EFQ1QhmL12cnkq/hui0sPzlrni6cCTwFirf4mQ6LsUSXFvY7y4Gmm+4eId0Lo7r0Gf uagIuHycBR23pVE1TYFMRtbGgm2MjOqEFYFjZ/NOZuP5J/RQXrpeXgGdJLD3zKyv/pVD EOIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wZMngG01; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb35-20020a1709076da300b00732fa7c5058si7785897ejc.300.2022.08.15.13.03.41; Mon, 15 Aug 2022 13:04:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wZMngG01; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345017AbiHOTsJ (ORCPT + 99 others); Mon, 15 Aug 2022 15:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345333AbiHOTq0 (ORCPT ); Mon, 15 Aug 2022 15:46:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A35436CF62; Mon, 15 Aug 2022 11:49:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9049161154; Mon, 15 Aug 2022 18:49:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48340C433D7; Mon, 15 Aug 2022 18:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589343; bh=U9HD4eLoKwLkfAjESfyRq2IJZfDXUJqsumUKnIQZxmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wZMngG0172joGa6Mht0RSIz+DabqCLjZVsJZ3/wyP3XhbbGJ4a1knVsfVuVjUhfbG W6OnwO206oM4dh9Gxl02D5qMojEZ27aCPeSmbnS/T11eEszIpL4rZx21CKBfzqyMnu 87lq8HBaxfg1YEpiNmr38e+D6/f4n/qsCBjhAeQo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Al Viro Subject: [PATCH 5.15 688/779] __follow_mount_rcu(): verify that mount_lock remains unchanged Date: Mon, 15 Aug 2022 20:05:32 +0200 Message-Id: <20220815180406.758484405@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro commit 20aac6c60981f5bfacd66661d090d907bf1482f0 upstream. Validate mount_lock seqcount as soon as we cross into mount in RCU mode. Sure, ->mnt_root is pinned and will remain so until we do rcu_read_unlock() anyway, and we will eventually fail to unlazy if the mount_lock had been touched, but we might run into a hard error (e.g. -ENOENT) before trying to unlazy. And it's possible to end up with RCU pathwalk racing with rename() and umount() in a way that would fail with -ENOENT while non-RCU pathwalk would've succeeded with any timings. Once upon a time we hadn't needed that, but analysis had been subtle, brittle and went out of window as soon as RENAME_EXCHANGE had been added. It's narrow, hard to hit and won't get you anything other than stray -ENOENT that could be arranged in much easier way with the same priveleges, but it's a bug all the same. Cc: stable@kernel.org X-sky-is-falling: unlikely Fixes: da1ce0670c14 "vfs: add cross-rename" Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/namei.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/namei.c +++ b/fs/namei.c @@ -1461,6 +1461,8 @@ static bool __follow_mount_rcu(struct na * becoming unpinned. */ flags = dentry->d_flags; + if (read_seqretry(&mount_lock, nd->m_seq)) + return false; continue; } if (read_seqretry(&mount_lock, nd->m_seq))