Received: by 2002:ac8:45c5:0:b0:405:464a:c27a with SMTP id e5csp1236979qto; Thu, 27 Jul 2023 08:33:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFOAcYmNk6AKBuTZ4sRNpLXz0+T7SGYquM41sdcJQfTS+TqEe7Xo/KkMcndqZMoyOOyawmI X-Received: by 2002:aa7:c2c7:0:b0:521:8d64:df1c with SMTP id m7-20020aa7c2c7000000b005218d64df1cmr2413609edp.0.1690472028404; Thu, 27 Jul 2023 08:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690472028; cv=none; d=google.com; s=arc-20160816; b=kKp4KnjCBZs2p1Y4xt5AlH5OS1IcUYH7ETe8QzTx9ULnqOYI+jgcX7c48NtI3bSXZ9 +57iV5lpjRJKpBkbM6kFytV9Gj5K6juOi5Zi944oedFzqGg31r9zY4AqxvAX9tQcHye1 hKEkvj69gN27K9QFd9L6+4zNDoQQkkVl7PqRQXxcZ+hnSwUhP4/UmbhzQEB7FKhJLyMD rxQlCY1wTi7Cb8QaTUDiQs3+Flt6laJRkTVg55ItCDIQPvBhPqa7XCiJ9Gi+Qua3xmgk iAxY+hezVnP9nTxA2V8B+MBnMcVNYOb3XiUYDkT+d1IuqVVlJJCLpqks8CKxmBVj3kOP mTsQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=e+tYkLqI/WHrzy+gF3ZWvjwYtLENNnrtaJxq1JAle3Y=; fh=THe7WeyPL9TmnW9+uMJa5WK0lNnZiyW8IObKvofU9xU=; b=SLLRniwzxKn9ORgYRZNNQMz77/q0G6Pw2y1mjZKr8nl3ndLLEkw95a0FWyalQ8SE/E P9BOVNqjw2PYRnYAy48Dc1IimxkdODsnA1l6MGhUKcxHmtaJ+R+b2MHB3zL3jeCyMVnt cX2mfckHYTAL3yHwsx0XnXaraR3kCtUg9Zm4IyjA0V58v79cQLPKVl0h3P5gYOjIWsW1 YfjAoCUYdPABJ6ZtoWiy5yrtcnaxS3siarnCNVcgzc9A3X0SHVyep3KahoQCClEVsdog 7NpX9+D3/95QXkrPO8hiY1tjqngAU47PiAK/MuIeo6Pj7MDlmcUMo3qI9fy74YM56CKR B5oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HLUlE8oW; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020aa7d88c000000b005221fde56b3si1071082edq.21.2023.07.27.08.33.10; Thu, 27 Jul 2023 08:33:48 -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=@bootlin.com header.s=gm1 header.b=HLUlE8oW; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234509AbjG0PUW (ORCPT + 99 others); Thu, 27 Jul 2023 11:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233418AbjG0PUT (ORCPT ); Thu, 27 Jul 2023 11:20:19 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B37041FCF for ; Thu, 27 Jul 2023 08:20:17 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id EA7F1E0006; Thu, 27 Jul 2023 15:20:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690471216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e+tYkLqI/WHrzy+gF3ZWvjwYtLENNnrtaJxq1JAle3Y=; b=HLUlE8oW95FKHARC7HKx6eY3PtnWvzRFtTOmg8SgLOq64ABxby+KSfWbA+NhcJUVlyiHSZ Vl+FJqjQvGqeRNKNMeZk16JYDW0TF3y4mAzrZvA7fRXDW8BOCJdV0b4H2/al9pS5NnAtPX cvWHou+1dyV3AR8zbnoiTIBrZBTrYW74jqJD8XIGJiPaINvohZ5yQaRvaLwLEKYESWgOmL j19gfF1nWf5alNn/8r135+OE9Jpfol33imFbIengD0pojeZRVN5H0ROnePihUCD+BLNb/w Myz32U2fUNjWBDqn5lJnbp38lR07GbEjrjXunsw7UgawWPFXcRhj9GPbQc8Pcg== Date: Thu, 27 Jul 2023 17:20:13 +0200 From: Miquel Raynal To: Andy Shevchenko Cc: Alexander Usyskin , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Tomas Winkler , Vitaly Lubart , Zhang Xiaoxu Subject: Re: [PATCH] mtd: fix use-after-free in mtd release Message-ID: <20230727172013.7c85c05d@xps-13> In-Reply-To: References: <20230727145758.3880967-1-alexander.usyskin@intel.com> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 Hi Andy, andriy.shevchenko@linux.intel.com wrote on Thu, 27 Jul 2023 18:12:04 +0300: > On Thu, Jul 27, 2023 at 05:57:58PM +0300, Alexander Usyskin wrote: > > I case of partition device_unregister in mtd_device_release =20 >=20 > In >=20 > device_unregister() > mtd_device_release() >=20 > > calls mtd_release which frees mtd_info structure for partition. =20 >=20 > mtd_release() >=20 > > All code after device_unregister in mtd_device_release thus =20 >=20 > device_unregister() > mtd_device_release() >=20 > > works already freed memory. =20 >=20 > uses? >=20 > > Move part of code to mtd_release and restict mtd->dev cleanup =20 >=20 > mtd_release() Yup, thanks for all these suggestions, I agree with them. > > to non-partion object. > > For partition object such cleanup have no sense as partition > > mtd_info is removed. > >=20 > > Cc: Miquel Raynal > > Cc: Zhang Xiaoxu > > Fixes: 19bfa9ebebb5 ("mtd: use refcount to prevent corruption") =20 >=20 > Closes: ? Did I miss a recent update on the use of Fixes? I thought Closes was supposed to point at a bug report while Fixes would point to the faulty commit. Right now I feel like Fixes is the right tag, but if you have a source explaining why we should not longer do it like I am used to, I would appreciate a link. Thanks, Miqu=C3=A8l