Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2938519rdh; Wed, 27 Sep 2023 18:58:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDSJlTG/VwzEvtRoOjGH/wfRp6jZv7TIKFKe3fs2kSWhbXpDPZVAAZf1BWLVu/LtS6EzW2 X-Received: by 2002:ac8:5707:0:b0:419:5c43:9d1a with SMTP id 7-20020ac85707000000b004195c439d1amr3537876qtw.68.1695866318928; Wed, 27 Sep 2023 18:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695866318; cv=none; d=google.com; s=arc-20160816; b=q4zVsRuuJBXtENUwxhi+uh6uCiSz77+NJqUJU9D0eiCJDZKIm0BXpQCpx9JjjQsztg cCHlinB41r0s1QNuRF/LNeQx+5R3LlDZ4bQqO7uqm1koLvlSq14arIwQRc2Y5cMVe7K2 sljJE5a/cwdcryslqxtAJg7GIF/QCfYPd0ucZ0diMK6nwBg3R6oL3QfWR6UIMDq82bfj ZUGPgt6iwkM2Jh9+k6U99zw9o9bahN9qjmHQia6MzmdmLCMU1gBYsqVw/UhzpVY+Hr/Y h8/YqyPlF31n2FdF8CFn4LfZlanz595fnuP6/9V2+wMqD9LkgSeHb/uSx0bwaOVNNVwh oJUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Y5BdNredrDHTYUunP3kApqKLWcDG2AzXoWP37/0LaLo=; fh=ggAtyYCLjQC+aEaWV6nS5QgUNtsrjVB3JQO9PZCF1so=; b=FinOdMzdZoku04gvaniQIItbKqRpSnrkQRE6lauK/mxlbgooOB+xFI769pJxPEgvGy n5ki4/d9Y13AzzlrWa++IyGf8h2adkwWV9IgnNKRS28pQQtz8lbxKso1NGRJDhemAUic nDUXvdTheLCtvSI/YLOVM/Qh64A+TzM5TaIAMcerq1gJ/yBJCDOf1+VdVgzHENuDAOUS 27mJ/a1xbcX4Wh/8Nq+ZxbOMeDl8D1CsPWS49rIyW83Vk4ES1AexgoWtS2FbV0vgpoLD AuOBz6IHjnujqBYPGB6+admrLpFFu4Hh2kfeECi/2O08vJPOccCd0s/y5INBpMHKUR/V UAKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="ndvyW/v5"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i12-20020a633c4c000000b00582f1f73c82si10034500pgn.381.2023.09.27.18.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 18:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="ndvyW/v5"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 35BEE81133BB; Wed, 27 Sep 2023 15:29:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbjI0W3d (ORCPT + 99 others); Wed, 27 Sep 2023 18:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjI0W3d (ORCPT ); Wed, 27 Sep 2023 18:29:33 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8632102; Wed, 27 Sep 2023 15:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Y5BdNredrDHTYUunP3kApqKLWcDG2AzXoWP37/0LaLo=; b=ndvyW/v5AnnTWjFcOaHmQtJ2tQ BC/6lzWxYgmdgHXT3PvPZcC090LQrp5ml02Ae1GnoSZckoSqvjoU59jpnfAR30t9sQc4/Tr/mYnNI X6fsO3Ipq3PoKVycIJsEvT0+99hFr4CUSn/aQRGG2eC0g6Iw2svNRD/I3rMzmeTP9B1nb7c4dqeqA JN6364DWbEtruq3HNM0pL9YLgknS628sDSI3CSoX5x4axSRNWXVW2YPZpfLHfh77TVYhq6vn6Ypxd WcP/K9r5N10De0XaKEEw5J4cGIg6JXFmGw4wiy5LDY2ZiUC1DhwwA6Vw2c8s4Kjh2Vk+HNoezE5u+ 4u/hMT3A==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1qld1m-00CP4N-2B; Wed, 27 Sep 2023 22:29:07 +0000 Date: Wed, 27 Sep 2023 23:29:06 +0100 From: Al Viro To: Christoph Hellwig Cc: Christian Brauner , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Fenghua Yu , Reinette Chatre , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dennis Dalessandro , Tejun Heo , Trond Myklebust , Anna Schumaker , Kees Cook , Damien Le Moal , Naohiro Aota , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org, linux-nfs@vger.kernel.org, linux-hardening@vger.kernel.org, cgroups@vger.kernel.org Subject: Re: [PATCH 03/19] fs: release anon dev_t in deactivate_locked_super Message-ID: <20230927222906.GO800259@ZenIV> References: <20230913111013.77623-1-hch@lst.de> <20230913111013.77623-4-hch@lst.de> <20230913232712.GC800259@ZenIV> <20230926093834.GB13806@lst.de> <20230926212515.GN800259@ZenIV> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230926212515.GN800259@ZenIV> Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 15:29:35 -0700 (PDT) On Tue, Sep 26, 2023 at 10:25:15PM +0100, Al Viro wrote: > Before your patch: foo_kill_super() calls kill_anon_super(), > which calls kill_super_notify(), which removes the sucker from > the list, then frees ->s_fs_info. After your patch: > removal from the lists happens via the call of kill_super_notify() > *after* both of your methods had been called, while freeing > ->s_fs_info happens from the method call. IOW, you've restored > the situation prior to "super: ensure valid info". The whole > point of that commit had been to make sure that we have nothing > in the lists with ->s_fs_info pointing to a freed object. More detailed example: take a look at NFS. We have ->get_tree() there call sget_fc() with nfs_compare_super() as possible 'test' callback. It does look at ->s_fs_info of the superblocks found on the list of instances for fs type in question. Moreover, it proceeds to call nfs_compare_mount_options(), which chases pointers from that (at the very least fetch ->client in nfs_server instance ->s_fs_info points to and dereferences that). We really, really do not want nfs_free_server() happen while the superblock is visible in the instances list. Now, in your tree nfs_free_sb() call nfs_free_server(). *Without* having called kill_super_notify() first - you do that only after the call of ->free_sb(). So with this series applied we have UAF on race between mount and umount. For NFS. No block devices involved. Old logics had been "after generic_shutdown_super() the private parts of superblock belong to filesystem alone; they might be accessed by methods called from RCU pathwalk, but that's it". I still don't see any clear rules for the new one. And the more I'm looking, the more sceptical I get about the approach you've taken, TBH...