[PATCH v2] mtd: Fix refcounting with MTD_PARTITIONED_MASTER

Miquel Raynal miquel.raynal at bootlin.com
Thu Aug 3 23:44:50 PDT 2023


Hi Alexander,

alexander.usyskin at intel.com wrote on Tue, 1 Aug 2023 08:45:47 +0000:

> Hi Miquel,
> 
> > -----Original Message-----
> > From: Miquel Raynal <miquel.raynal at bootlin.com>
> > Sent: Monday, July 31, 2023 12:09
> > To: Richard Weinberger <richard at nod.at>; Vignesh Raghavendra
> > <vigneshr at ti.com>; Tudor Ambarus <tudor.ambarus at linaro.org>; Pratyush
> > Yadav <pratyush at kernel.org>; Michael Walle <michael at walle.cc>; linux-
> > mtd at lists.infradead.org
> > Cc: Miquel Raynal <miquel.raynal at bootlin.com>; Winkler, Tomas
> > <tomas.winkler at intel.com>; Usyskin, Alexander
> > <alexander.usyskin at intel.com>; Zhang Xiaoxu <zhangxiaoxu5 at huawei.com>
> > Subject: [PATCH v2] mtd: Fix refcounting with MTD_PARTITIONED_MASTER
> > 
> > The logic is way too convoluted, let's clean the kref_get/put section to
> > clarify what this block does, hopefully solving the refcounting issue
> > when using CONFIG_MTD_PARTITIONED_MASTER at the same time:
> > - Iterate through all the parent mtd devices
> > - Grab a reference over them all but the master
> > - Only grab the master whith CONFIG_MTD_PARTITIONED_MASTER
> > Same logic must apply in the put path, otherwise it would be broken.
> > 
> > Cc: Tomas Winkler <tomas.winkler at intel.com>
> > Cc: Alexander Usyskin <alexander.usyskin at intel.com>
> > Cc: Zhang Xiaoxu <zhangxiaoxu5 at huawei.com>
> > Fixes: 19bfa9ebebb5 ("mtd: use refcount to prevent corruption")
> > Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
> >   
> 
> I've put it on top of my "[PATCH v2] mtd: fix use-after-free in mtd release",
> looks ok, but I have had no problems with refcounting before...
> IMO, we need both this patch and my patch as they fix different issues.
> 
> Tested-by: Alexander Usyskin <alexander.usyskin at intel.com>
> 

Actually I don't think this patch fixes anything, besides the
simplification of the helpers which are (IMHO) more readable now.

Zhang, are you sure you test on the latest mtd/next branch? Because I
see no refcounting issue here, with/without PARTITIONED_MASTER.

Thanks,
Miquèl



More information about the linux-mtd mailing list