mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Baokun Li <libaokun1@huawei.com>, <richard@nod.at>,
	<miquel.raynal@bootlin.com>, <vigneshr@ti.com>,
	<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Cc: <patchwork@huawei.com>, <yukuai3@huawei.com>,
	Hulk Robot <hulkci@huawei.com>
Subject: Re: [PATCH -next] ubi: fix race between ctrl_cdev_ioctl and ubi_cdev_ioctl
Date: Tue, 2 Nov 2021 21:01:40 +0800	[thread overview]
Message-ID: <decf845d-ce14-cfb7-9500-73f271b7a38e@huawei.com> (raw)
In-Reply-To: <20211101013739.236430-1-libaokun1@huawei.com>

在 2021/11/1 9:37, Baokun Li 写道:
Hi, Baokun
> diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
> index a7e3eb9befb6..708b1b96de01 100644
> --- a/drivers/mtd/ubi/build.c
> +++ b/drivers/mtd/ubi/build.c
> @@ -467,6 +467,7 @@ static int uif_init(struct ubi_device *ubi)
>   	if (err)
>   		goto out_unreg;
>   
> +	spin_lock(&ubi->volumes_lock);
>   	for (i = 0; i < ubi->vtbl_slots; i++)
>   		if (ubi->volumes[i]) {
>   			err = ubi_add_volume(ubi, ubi->volumes[i]);
> @@ -475,11 +476,13 @@ static int uif_init(struct ubi_device *ubi)
>   				goto out_volumes;
>   			}
>   		}
> +	spin_unlock(&ubi->volumes_lock);
>   
>   	return 0;
>   
>   out_volumes:
>   	kill_volumes(ubi);
> +	spin_unlock(&ubi->volumes_lock);
>   	cdev_device_del(&ubi->cdev, &ubi->dev);
>   out_unreg:
>   	unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);

There still exist one place that ubi_attach_mtd_dev() may race with 
ubi_remove_volume():

ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name)

     goto out_debugfs;

...

out_debugfs:

     ubi_debugfs_exit_dev(ubi);

out_uif:

    uif_close(ubi);      // Another process does ioctl to remove volume, 
which may cause volume double free.


      reply	other threads:[~2021-11-02 13:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01  1:37 Baokun Li
2021-11-02 13:01 ` Zhihao Cheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=decf845d-ce14-cfb7-9500-73f271b7a38e@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=hulkci@huawei.com \
    --cc=libaokun1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=patchwork@huawei.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®