public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Hyunwoo Kim <imv4bel@gmail.com>
Cc: arnd@arndb.de, Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] char: pcmcia: synclink_cs: Fix use-after-free in mgslpc_ops
Date: Fri, 16 Sep 2022 16:54:11 +0300 (EEST)	[thread overview]
Message-ID: <21d84319-4d1a-8d8e-a098-947772406faf@linux.intel.com> (raw)
In-Reply-To: <20220916134751.GA234676@ubuntu>

On Fri, 16 Sep 2022, Hyunwoo Kim wrote:

> A race condition may occur if the user physically removes
> the pcmcia device while calling ioctl() for this tty device node.
> 
> This is a race condition between the mgslpc_ioctl() function and
> the mgslpc_detach() function, which may eventually result in UAF.
> 
> So, add a refcount check to mgslpc_detach() to free the structure
> after the tty device node is close()d.
> 
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>

> @@ -2517,9 +2548,14 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
>  	if (debug_level >= DEBUG_LEVEL_INFO)
>  		printk("%s(%d):mgslpc_open(%s) success\n",
>  			 __FILE__, __LINE__, info->device_name);
> +
> +	kref_get(&info->refcnt);
>  	retval = 0;
> +	mutex_unlock(&remove_mutex);
>  
> +	return retval;
>  cleanup:
> +	mutex_unlock(&remove_mutex);
>  	return retval;

Just move the cleanup label instead.


-- 
 i.


  reply	other threads:[~2022-09-16 13:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-16 13:47 [PATCH v3] char: pcmcia: synclink_cs: Fix use-after-free in mgslpc_ops Hyunwoo Kim
2022-09-16 13:54 ` Ilpo Järvinen [this message]
2022-09-16 14:03   ` Hyunwoo Kim
2022-09-16 14:05     ` Ilpo Järvinen

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=21d84319-4d1a-8d8e-a098-947772406faf@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=imv4bel@gmail.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