mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>,
	barebox@lists.infradead.org
Subject: Re: [PATCH] of: fdt: fix overflow caused by fdt_prop extending beyond fdt
Date: Tue, 19 Nov 2024 20:23:49 +0100	[thread overview]
Message-ID: <9452ada7-6515-458e-80e0-a5da01fec3a0@pengutronix.de> (raw)
In-Reply-To: <20241119183530.1629261-1-abdelrahmanyossef12@gmail.com>

On 19.11.24 19:35, Abdelrahman Youssef wrote:
> While parsing FDT, fdt_prop sometimes extends beyond FDT resulting in
> heap-overflow.
> 
> dt_ptr_ok() checks a pointer is within bounds of the FDT, so we can use it
> here to fix the issue.
> 
> Suggested-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> Signed-off-by: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>
> ---
>  drivers/of/fdt.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 75af1844f3..a756483578 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -257,6 +257,11 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, int size,
>  
>  		case FDT_PROP:
>  			fdt_prop = infdt + dt_struct;
> +			if (dt_ptr_ok(fdt, fdt_prop)) {

Shouldn't you invert the condition?

Cheers,
Ahmad

> +				ret = -ESPIPE;
> +				goto err;
> +			}
> +
>  			len = fdt32_to_cpu(fdt_prop->len);
>  			nodep = fdt_prop->data;
>  


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2024-11-19 19:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-19 18:35 Abdelrahman Youssef
2024-11-19 19:23 ` Ahmad Fatoum [this message]
2024-11-19 19:57   ` AbdelRahman Yossef

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=9452ada7-6515-458e-80e0-a5da01fec3a0@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=abdelrahmanyossef12@gmail.com \
    --cc=barebox@lists.infradead.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