From: Eli Billauer <eli.billauer@gmail.com>
To: Ma Ke <make24@iscas.ac.cn>, arnd@arndb.de, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
stable@vger.kernel.org
Subject: Re: [PATCH] char: xillybus: Fix error handling in xillybus_init_chrdev()
Date: Mon, 10 Mar 2025 15:45:46 +0200 [thread overview]
Message-ID: <4cd852e0-6d6d-fcb4-6e4c-e6f861f429db@outbound.gmail.com> (raw)
In-Reply-To: <20250310022811.182553-1-make24@iscas.ac.cn>
Hello,
Thanks for your patch.
However, as far as I understand, applying it will cause a Use After Free
(UAF) error by cdev_del(), as the call to kobject_put() unwinds the
memory allocation made by cdev_alloc().
Or have I missed something?
Regards,
Eli
On 10/03/2025 4:28, Ma Ke wrote:
> After cdev_alloc() succeed and cdev_add() failed, call cdev_del() to
> remove unit->cdev from the system properly.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: 8cb5d216ab33 ("char: xillybus: Move class-related functions to new xillybus_class.c")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> drivers/char/xillybus/xillybus_class.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/xillybus/xillybus_class.c b/drivers/char/xillybus/xillybus_class.c
> index c92a628e389e..045e125ec423 100644
> --- a/drivers/char/xillybus/xillybus_class.c
> +++ b/drivers/char/xillybus/xillybus_class.c
> @@ -105,7 +105,7 @@ int xillybus_init_chrdev(struct device *dev,
> dev_err(dev, "Failed to add cdev.\n");
> /* kobject_put() is normally done by cdev_del() */
> kobject_put(&unit->cdev->kobj);
> - goto unregister_chrdev;
> + goto err_cdev;
> }
>
> for (i = 0; i < num_nodes; i++) {
> @@ -157,6 +157,7 @@ int xillybus_init_chrdev(struct device *dev,
> device_destroy(&xillybus_class, MKDEV(unit->major,
> i + unit->lowest_minor));
>
> +err_cdev:
> cdev_del(unit->cdev);
>
> unregister_chrdev:
prev parent reply other threads:[~2025-03-10 13:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 2:28 Ma Ke
2025-03-10 13:45 ` Eli Billauer [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=4cd852e0-6d6d-fcb4-6e4c-e6f861f429db@outbound.gmail.com \
--to=eli.billauer@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=make24@iscas.ac.cn \
--cc=stable@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
all inboxes | Powered by JetHome®