Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5311097rwd; Tue, 23 May 2023 23:05:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42xLoySeT0g6mV6kUAPf0okqFhi4nZTkBFy7NjN4zbVSGpWh9tnlKtJisgnDP3ZbqoXDJ5 X-Received: by 2002:a17:90b:364e:b0:255:2cee:62c8 with SMTP id nh14-20020a17090b364e00b002552cee62c8mr12817569pjb.19.1684908308646; Tue, 23 May 2023 23:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684908308; cv=none; d=google.com; s=arc-20160816; b=C3MBQAsHoKjdFMjte5gYrV1sn+uK4SiM9swQAZ1+Pg4PYobYOo+MdUhrUTDfX/fCnU aCAO2/owVoTEqdp0SW6+oP4JmdMax/h7JM/YS97dajDlck7yKijS49pL4ILDSlwUBxzj DkZnCiMd8YzTfAjYAV45SdIu1Anaf5gaRGu70UNQVodtakmyKT4soxIsBhNaIYgUHbRZ KucFmqZH7ea0sLchDNolWyq8lZSD7XOujbigBDNM4b45yOv/uYFQatTSaF3NwdVwcBiy ApfzJuWsmv+wqad72BWG4S1Pb/yQ6rwZWXe7DBTW+fH4eHvtuESG6gR0+i6JE0lFIOGb tWww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=x+N6WV/CyF+wzcgIuD5OCrwWYrJjwwC1z6uAEEubo1c=; b=cB/KdzUU4uO8cHKpWFdXUAExoBi3/vUeyI6w8+dEZ0WXrMN7EX7KAhX6BpmWv/FNKp 50VfhVMG2eb4nkZ+ACpHLLTAFoEv/nFK4TKcsHHNe5j61gkPKTYx5yxo24UGScnTnocN MUoEhrVjrAdFIG+MrAiUuKcYZ3muAqJLe2FSLgeWrw5t8iZm5cURGaeK+FCd/+MCmlo5 fqz4GS5DCX2ekElI2d58ObiW/LzPxP9oyYeEBHkA4J4Eip8FGQ00cDBuqAV91Y4hEZDg loY3Ur1Aw4/nWp09/dBO/VkgUmQ7ny1A8fKR0lJobPFXtVWNMuelco6ZjLILWmNvIM7o Tl5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Z6UOwVj6; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g10-20020a17090a7d0a00b002528f40700dsi675463pjl.153.2023.05.23.23.04.55; Tue, 23 May 2023 23:05: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=@infradead.org header.s=bombadil.20210309 header.b=Z6UOwVj6; 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 S239573AbjEXF6Y (ORCPT + 99 others); Wed, 24 May 2023 01:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239564AbjEXF6U (ORCPT ); Wed, 24 May 2023 01:58:20 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB71C198 for ; Tue, 23 May 2023 22:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=x+N6WV/CyF+wzcgIuD5OCrwWYrJjwwC1z6uAEEubo1c=; b=Z6UOwVj6yiJqAeVLNAZ5XhFLod 2EeVpQrzvSFp1FuDVe5FS9XKyvLxPCovJLnu8rRx4dRQJcQT3/vRc+NZbl6b//WJVDbFpktB4KteQ +pDPdy9X+pjQqYQfLAA5BjRsMwUDKyNs+2c9bz7Wn5LvjOlQrGdi6yrqgkaJjELWFStL0HOkcels2 B7kuxD/oOE3yHM9u284tmeBGKOVrnGpcEQbSwYXtGgzYMRbORVw6dCvO1j17V2GUnVJiTRqYeTFyQ v8tyhtAWI+yggCuYTzbKsUqal3i16OWiJ25sHZ6w03k6Hbb6ovbNjFUsXceTprqjU3doItbgE/JRX 4A/pAHoQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q1hVh-00CRpm-1c; Wed, 24 May 2023 05:58:09 +0000 Date: Tue, 23 May 2023 22:58:09 -0700 From: Christoph Hellwig To: Vincent Whitchurch Cc: Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@axis.com Subject: Re: [PATCH 1/2] ubi: block: Fix use-after-free of gendisk Message-ID: References: <20230523-ubiblock-remove-v1-0-240bed75849b@axis.com> <20230523-ubiblock-remove-v1-1-240bed75849b@axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230523-ubiblock-remove-v1-1-240bed75849b@axis.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 On Tue, May 23, 2023 at 03:12:16PM +0200, Vincent Whitchurch wrote: > static void ubiblock_cleanup(struct ubiblock *dev) > { > + int first_minor = dev->gd->first_minor; > + > /* Stop new requests to arrive */ > del_gendisk(dev->gd); > /* Finally destroy the blk queue */ > dev_info(disk_to_dev(dev->gd), "released"); > put_disk(dev->gd); > blk_mq_free_tag_set(&dev->tag_set); > - idr_remove(&ubiblock_minor_idr, dev->gd->first_minor); > + idr_remove(&ubiblock_minor_idr, first_minor); I think the real fix here is to implement the free_disk method and free the idr there. That ensures the ID can't be reused until the disk is entirely freed as well.