From patchwork Wed Jun 7 17:08:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 104635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp357805vqr; Wed, 7 Jun 2023 10:18:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42ABJLI0Pf+ct5uRqOnmtz3NgC8keQHHsyY7SYF7rr5NjY8ZvXOHLPM51q7W+wk/XmbcOS X-Received: by 2002:a05:6a00:179d:b0:64d:b0d8:a396 with SMTP id s29-20020a056a00179d00b0064db0d8a396mr3145341pfg.7.1686158303482; Wed, 07 Jun 2023 10:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686158303; cv=none; d=google.com; s=arc-20160816; b=yy9F2HXnBNtdwBs+CnN3gLDJ/RWT+Cjh/mgARBC3BDRk2wjK9545G06TKpXZJbLHJU //4YvnfqHIU86XpcOXDT7QlFFcMW53ij3vun0sX1Ti4TRZ//UUszsx0THl10DK2a9g0n 30M0mlOz3rxY+RMPC/lqMmwUyuSSVuHNwRcOepkuBOElLXD3d72iyfe5nukfJwnwtY8R vMY/2/o2wGO8nDOJs3OSAPrdc01xwXed+MOcBF/dq9knTJ910t76F8NN32N/8g4NzoW2 G/URFjTD8NY3YirOmSgft6FzlgzjG5UMtM0VeNKStX3l0ADu1FT88wwmmoKGzfiSHtWb TyUA== 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 :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=OKyh78clxdjUBYWd2RtYdS/EeUQhHG5NkHJJd2T0ITE=; b=c84Mj02agX8OJRkUfQydWaOF2YqNWCOZa4bHKoeUSYOXFMtLK++XVILvLggfARqZDa Wh4Ftjj2fRDTu/DniugOHeUvyOJ4R/Z3vx8OBYN57WUwgTka3ngLzMGZAfe/tbfattxf p/lO11iQ9wTdSR9Hhma3W+8KPkVKjnfZy9mWkzaAc160KoueVFmWEq+ohBVFfmzsbsLO 99dLEAxnvF+/YGAcJS4BVEjaKRvYHWreK5vt/HENs8D4SmRHzZjp/HAWRJlF9OgfMNf8 5JMIeZf7rbnPJN8rLxoPTC6cxg9QXt7LBuuP3lQF/kylmKE5YDuRNLbNUIDPzkxD79BG aVQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=RPkXP4Uq; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=cdQ6mHvF; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a185-20020a6390c2000000b0053467c7b635si3246951pge.85.2023.06.07.10.17.43; Wed, 07 Jun 2023 10:18:23 -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=@invisiblethingslab.com header.s=fm1 header.b=RPkXP4Uq; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=cdQ6mHvF; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjFGRI6 (ORCPT + 99 others); Wed, 7 Jun 2023 13:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230418AbjFGRIy (ORCPT ); Wed, 7 Jun 2023 13:08:54 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A7E11BF1; Wed, 7 Jun 2023 10:08:51 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 94B245C0114; Wed, 7 Jun 2023 13:08:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 07 Jun 2023 13:08:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t= 1686157730; x=1686244130; bh=OKyh78clxdjUBYWd2RtYdS/EeUQhHG5NkHJ Jd2T0ITE=; b=RPkXP4UqXwqtzc4+CXRx9FxVrOrEZzqZmfOzTAiQ+taGvOmATQN rj+aO8Xk1QGMQ7j3XoSZBCw8CSp/tvb7LF28DRnVJBtTuypN1Sw+C2fXhVag3Jhk /AgsNFzQA7EvlpgH2RFC+DVczoLAm2C3a6edP6BQ00Yu3VbAR/4BG3p3X9CgdWI9 EhijfUujWe3M0JLYcencH4B6liJgxTIdeFFrA79rnv/zeuasZjrPUyjbS6VbYWQj r1TDdpikdqjz8X2NrCVBtBWWAwipFetp6T+fRXXIUxhbk/SDMCfmvXACFZC9farX FIqC9OJaDO/uuV0UJnuZ+6ihPz2hkoAB1yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1686157730; x=1686244130; bh=OKyh78clxdjUB YWd2RtYdS/EeUQhHG5NkHJJd2T0ITE=; b=cdQ6mHvF+jJeoSE1SIIJc0G+qRe32 sxQMAprznL3aEwzR58XPYUuhV5XU7rSXl4+/NQfl8jpoJtyHTOEFK6zbIwz1M47p 8VOuXCUpORa5Vg5p/t18yU9QY3b/s3TTbak01SZB4RYbgBmDdWbfvhHET2Ibqykh gdiol4bOmq/aP4S5ECQWAHomQA9wFda6uexs5UeyrjTL9mXC+4g4tM8Hr5VLopnv rB7v4ikQgiNURCk6I7mvGxYxFtYcVQBQTqk2oWUuArq7OLTaR65I7nrpJIwxOjf8 HBX1c91L2DW3I+i7xByD0GI5cjiYqHMvCRwB6AWOiznDllN7A1uCwxrHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtgedguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpedvfeegkedvkefgffegkefhieejtdff keehhfelheefjeeutefgleeggfdtveeileenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 7 Jun 2023 13:08:49 -0400 (EDT) From: Demi Marie Obenour To: Jens Axboe Cc: Demi Marie Obenour , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , stable@vger.kernel.org Subject: [PATCH] block: increment diskseq on all media change events Date: Wed, 7 Jun 2023 13:08:37 -0400 Message-Id: <20230607170837.1559-1-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768065129048463836?= X-GMAIL-MSGID: =?utf-8?q?1768065129048463836?= Currently, associating a loop device with a different file descriptor does not increment its diskseq. This allows the following race condition: 1. Program X opens a loop device 2. Program X gets the diskseq of the loop device. 3. Program X associates a file with the loop device. 4. Program X passes the loop device major, minor, and diskseq to something. 5. Program X exits. 6. Program Y detaches the file from the loop device. 7. Program Y attaches a different file to the loop device. 8. The opener finally gets around to opening the loop device and checks that the diskseq is what it expects it to be. Even though the diskseq is the expected value, the result is that the opener is accessing the wrong file. From discussions with Christoph Hellwig, it appears that disk_force_media_change() was supposed to call inc_diskseq(), but in fact it does not. Adding a Fixes: tag to indicate this. Christoph's Reported-by is because he stated that disk_force_media_change() calls inc_diskseq(), which is what led me to discover that it should but does not. Reported-by: Christoph Hellwig Signed-off-by: Demi Marie Obenour Fixes: e6138dc12de9 ("block: add a helper to raise a media changed event") Cc: stable@vger.kernel.org # 5.15+ Reviewed-by: Christoph Hellwig --- block/disk-events.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/disk-events.c b/block/disk-events.c index aee25a7e1ab7de8cc82b3c3774e83489d3a86ff9..450c2cbe23d56cc0fa8fa40db9866cdae0e7a626 100644 --- a/block/disk-events.c +++ b/block/disk-events.c @@ -307,6 +307,7 @@ bool disk_force_media_change(struct gendisk *disk, unsigned int events) if (!(events & DISK_EVENT_MEDIA_CHANGE)) return false; + inc_diskseq(disk); if (__invalidate_device(disk->part0, true)) pr_warn("VFS: busy inodes on changed media %s\n", disk->disk_name);