mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@amd.com>
To: Duoming Zhou <duoming@zju.edu.cn>, linux-kernel@vger.kernel.org
Cc: mturquette@baylibre.com, sboyd@kernel.org,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] clk: zynq: Prevent null pointer dereference caused by kmalloc failure
Date: Mon, 19 Feb 2024 14:35:01 +0100	[thread overview]
Message-ID: <86e1c66c-8fd4-402e-a827-cc4347d468c1@amd.com> (raw)
In-Reply-To: <20240214073318.82573-1-duoming@zju.edu.cn>



On 2/14/24 08:33, Duoming Zhou wrote:
> The kmalloc in zynq_clk_setup will return null if the
> physical memory has run out. As a result, if we use
> snprintf to write data to the null address, the null
> pointer dereference bug will happen.
> 
> The required memory is only 11 bytes, so this patch
> adds a "__GFP_NOFAIL" flag in kmalloc in order that
> the kmalloc will never return with failure.
> 
> Fixes: 0ee52b157b8e ("clk: zynq: Add clock controller driver")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
>   drivers/clk/zynq/clkc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 7bdeaff2bfd..7621c2f0046 100644
> --- a/drivers/clk/zynq/clkc.c
> +++ b/drivers/clk/zynq/clkc.c
> @@ -427,7 +427,7 @@ static void __init zynq_clk_setup(struct device_node *np)
>   			SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock);
>   
>   	tmp = strlen("mio_clk_00x");
> -	clk_name = kmalloc(tmp, GFP_KERNEL);
> +	clk_name = kmalloc(tmp, GFP_KERNEL | __GFP_NOFAIL);
>   	for (i = 0; i < NUM_MIO_PINS; i++) {
>   		int idx;
>   

Reviewed-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal

  reply	other threads:[~2024-02-19 13:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14  7:33 Duoming Zhou
2024-02-19 13:35 ` Michal Simek [this message]
2024-02-28 23:07 ` Stephen Boyd

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=86e1c66c-8fd4-402e-a827-cc4347d468c1@amd.com \
    --to=michal.simek@amd.com \
    --cc=duoming@zju.edu.cn \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@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®