public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Jiazi Li <jqqlijiazi@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>, Jiazi Li <lijiazi@xiaomi.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] char: misc: init list head only when needed
Date: Sat, 4 Sep 2021 08:32:09 +0200	[thread overview]
Message-ID: <YTMS6cIGLwqxA0t9@kroah.com> (raw)
In-Reply-To: <853e8529c18c4a71c36b49f9598961fbc3f39682.1628921932.git.lijiazi@xiaomi.com>

On Mon, Aug 16, 2021 at 06:12:32PM +0800, Jiazi Li wrote:
> If a module successfully registers a misc device.
> Then, due to some bugs, use same address register misc device
> again, init list head will corrupt misc_list, resulting in oops
> when using misc_list.

Then fix those bugs that try to register the misc device more than once?

Does that happen in any in-kernel drivers or is this just a failure of
external drivers that are not submitted to the kernel tree?

> In this scenario, do not init list head, if registration is
> successful, init list head is also not required.
> 
> Signed-off-by: Jiazi Li <lijiazi@xiaomi.com>
> ---
>  drivers/char/misc.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index ca5141e..2451640 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -176,7 +176,6 @@ int misc_register(struct miscdevice *misc)
>  	int err = 0;
>  	bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR);
>  
> -	INIT_LIST_HEAD(&misc->list);
>  
>  	mutex_lock(&misc_mtx);
>  
> @@ -185,7 +184,7 @@ int misc_register(struct miscdevice *misc)
>  
>  		if (i >= DYNAMIC_MINORS) {
>  			err = -EBUSY;
> -			goto out;
> +			goto err2;
>  		}
>  		misc->minor = DYNAMIC_MINORS - i - 1;
>  		set_bit(i, misc_minors);
> @@ -195,7 +194,13 @@ int misc_register(struct miscdevice *misc)
>  		list_for_each_entry(c, &misc_list, list) {
>  			if (c->minor == misc->minor) {
>  				err = -EBUSY;
> -				goto out;
> +				/*
> +				 * if module use same address double register,
> +				 * init list will corrupt misc_list

I do not understand the text here at all, sorry.

thanks,

greg k-h

      reply	other threads:[~2021-09-04  6:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-16 10:12 [PATCH] char: misc: init list head only when needed Jiazi Li
2021-09-04  6:32 ` Greg Kroah-Hartman [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=YTMS6cIGLwqxA0t9@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=jqqlijiazi@gmail.com \
    --cc=lijiazi@xiaomi.com \
    --cc=linux-kernel@vger.kernel.org \
    /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