[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200221233216.3b2038f8@collabora.com>
Date: Fri, 21 Feb 2020 23:32:16 +0100
From: Boris Brezillon <boris.brezillon@...labora.com>
To: Vitor Soares <Vitor.Soares@...opsys.com>
Cc: linux-kernel@...r.kernel.org, linux-i3c@...ts.infradead.org,
Jose.Abreu@...opsys.com, corbet@....net, Joao.Pinto@...opsys.com,
arnd@...db.de, wsa@...-dreams.de, gregkh@...uxfoundation.org,
bbrezillon@...nel.org, broonie@...nel.org
Subject: Re: [PATCH v3 4/5] i3c: add i3cdev module to expose i3c dev in /dev
On Wed, 19 Feb 2020 01:20:42 +0100
Vitor Soares <Vitor.Soares@...opsys.com> wrote:
> +static int i3cdev_detach(struct device *dev, void *dummy)
> +{
> + struct i3cdev_data *i3cdev;
> + struct i3c_device *i3c;
> +
> + if (dev->type == &i3c_masterdev_type)
> + return 0;
> +
> + i3c = dev_to_i3cdev(dev);
> +
> + i3cdev = i3cdev_get_drvdata(i3c);
> + if (!i3cdev)
> + return 0;
> +
> + /* Prevent transfers while cdev removal */
> + mutex_lock(&i3cdev->xfer_lock);
> + cdev_del(&i3cdev->cdev);
When cdev_del() returns there might be opened FDs pointing to your
i3cdev [1] ...
> + device_destroy(i3cdev_class, MKDEV(MAJOR(i3cdev_number), i3cdev->id));
> + mutex_unlock(&i3cdev->xfer_lock);
> +
> + ida_simple_remove(&i3cdev_ida, i3cdev->id);
> + put_i3cdev(i3cdev);
... and you call put_i3cdev() here which frees the i3cdev object,
leading to potential use-after-free if any of the fops (ioctl, read,
write) are called on those dangling FDs. That's exactly the kind of
nightmare I'd like to avoid.
> +
> + pr_debug("i3cdev: device [%s] unregistered\n", dev_name(&i3c->dev));
> +
> + return 0;
> +}
> +
[1]https://elixir.bootlin.com/linux/latest/source/fs/char_dev.c#L587
Powered by blists - more mailing lists