Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3030680rwb; Mon, 15 Aug 2022 16:29:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/6ty7CPqTUp8D4UcMdox+bPXEByEpjUx/zpV02vrglZPMztEirGm3zfWm2QPihVhbt+rV X-Received: by 2002:a17:907:60c7:b0:731:2be4:f72d with SMTP id hv7-20020a17090760c700b007312be4f72dmr11753196ejc.639.1660606192589; Mon, 15 Aug 2022 16:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660606192; cv=none; d=google.com; s=arc-20160816; b=MJehB/HFJe77vzJhA5J4hZe1lhTZOCDDaH2LtuMKthhxD8BCqa4RTZ5j9NEg7E5f8R rU6h4QpQ5S21UHD49l9sEWEpAYIJ72jqFHJEtNyOdhtccsdoFvUVE85JodcIvkTNSD16 3z1/5fuuQKy4I6Hf/P8SK7WPjDQjYjKjZ1+ZB2BDaxNqmB0RG48fF9cMQJl18AwLz1EP QZoI1EJgll+hmEB192KvBlbGZnul6fCXzoo4uUiZXzYQDpYRjEW3wwPhAMVIOqNuXXYB zMX+CWgSezXa1Fi3fziKappzKLAcT6yDt2Bf61ny3fVPH8NaRIZyTOWjX5EVDNNzQf/F DQyg== 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=DfzrCyOkVpjJqmfIp85I8q7bEECttzLB/9dKXWhJD1Q=; b=tLweEjF7eKyO5MUC3A+CGmBifCj+R8meSOe3WMQzdAG1Q3SBoCatsCc4b1zyo3WJVQ b8+IVotc77+qxyLRE5pNV6pWoJwVF1dDiKnGo2OBTJQ1QiQe/IyLV/LIatF+t9PvosFg AHOqrrWoEprM/lCyMMB9ezfmaVQrryaAcbG19tfAo9ov5+dBXGegEZy9I7UXQmFBBKz/ tgA6SCjxpzG5Lnxlh5bQNfBwNYOMYjxiJTswZDfjl/Tv/rMblg6HCk0Mk4ugbP+cfnul 61/X8AsIO6t8SmMvuP86DJpALnoeC1dw/9hJXql5uRhSZaB5DEJpKh4yVmWVgoc2kUix GoMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ooYuRksg; 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 e19-20020a056402191300b0043dcf90c94asi10111414edz.67.2022.08.15.16.29.12; Mon, 15 Aug 2022 16:29:52 -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=ooYuRksg; 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 S1346065AbiHOXNP (ORCPT + 99 others); Mon, 15 Aug 2022 19:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245715AbiHOXMZ (ORCPT ); Mon, 15 Aug 2022 19:12:25 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7BF4DB0C; Mon, 15 Aug 2022 13:00:31 -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 sin.source.kernel.org (Postfix) with ESMTPS id 99C04CE12C3; Mon, 15 Aug 2022 20:00:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A8AAC433D7; Mon, 15 Aug 2022 20:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593627; bh=NeiVTxAhI6nx6NjJa+fD0XlyRj4AyPMiZ3D5AsiipeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ooYuRksgowJjXg19BevQrInGcSXbAji9JEpeKpnYMvAjnWsq54sNyYWU2tj505D6v SAAM9lhawbyX9JjfnmsCtzbu3phumxiqOC1q9kL0ZvEu5tE/Xv8bdUzBergTT6Wsg7 WIGuOtEDj0A++qmoFAw9HzCtufhK9QPNgWI8pvZI= 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.18 0978/1095] __follow_mount_rcu(): verify that mount_lock remains unchanged Date: Mon, 15 Aug 2022 20:06:17 +0200 Message-Id: <20220815180509.584528994@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 @@ -1511,6 +1511,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))