From: Frederic Barrat <fbarrat@linux.ibm.com>
To: Kunwu Chan <chentao@kylinos.cn>,
ajd@linux.ibm.com, arnd@arndb.de, gregkh@linuxfoundation.org,
mpe@ellerman.id.au, mrochs@linux.vnet.ibm.com
Cc: kunwu.chan@hotmail.com, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cxl: Fix null pointer dereference in cxl_get_fd
Date: Mon, 4 Dec 2023 11:43:12 +0100 [thread overview]
Message-ID: <c914f4ba-253d-4b57-bdd2-4c95d40bbf91@linux.ibm.com> (raw)
In-Reply-To: <20231204020745.2445944-1-chentao@kylinos.cn>
On 04/12/2023 03:07, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
>
> Fixes: bdecf76e319a ("cxl: Fix coredump generation when cxl_get_fd() is used")
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
> drivers/misc/cxl/api.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
> index d85c56530863..bfd7ccd4d7e1 100644
> --- a/drivers/misc/cxl/api.c
> +++ b/drivers/misc/cxl/api.c
> @@ -419,6 +419,10 @@ struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
> fops = (struct file_operations *)&afu_fops;
>
> name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
> + if (!name) {
> + put_unused_fd(fdtmp);
> + return ERR_PTR(-ENOMEM);
> + }
That works, but you might as well follow the existing error path:
name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
if (!name)
goto err_fd;
Fred
> file = cxl_getfile(name, fops, ctx, flags);
> kfree(name);
> if (IS_ERR(file))
next prev parent reply other threads:[~2023-12-04 10:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 2:07 Kunwu Chan
2023-12-04 10:43 ` Frederic Barrat [this message]
2023-12-05 9:28 ` Kunwu Chan
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=c914f4ba-253d-4b57-bdd2-4c95d40bbf91@linux.ibm.com \
--to=fbarrat@linux.ibm.com \
--cc=ajd@linux.ibm.com \
--cc=arnd@arndb.de \
--cc=chentao@kylinos.cn \
--cc=gregkh@linuxfoundation.org \
--cc=kunwu.chan@hotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=mrochs@linux.vnet.ibm.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®