All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>,
	Frank Rowand
	<frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
Date: Wed, 7 Apr 2021 12:45:40 +1000	[thread overview]
Message-ID: <YG0c1IZXS5o0/rBR@yekko.fritz.box> (raw)
In-Reply-To: <20210406190712.2118098-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1644 bytes --]

On Tue, Apr 06, 2021 at 02:07:12PM -0500, Rob Herring wrote:
> Only checking the FDT alignment in fdt_ro_probe_() means that
> fdt_check_header() can pass, but then subsequent API calls fail on
> alignment checks. Let's add an alignment check to fdt_check_header() so
> alignment errors are found up front.
> 
> Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

Good catch.

Applied, thanks.

> ---
> For background, the new alignment check triggered a crash in the 
> linux kernel. Yes, we should fix the error handling, but 
> fdt_check_header() shouldn't tell us the FDT is valid only to fail 
> later on.
> 
> Maybe we should move the check instead, but fdt_ro_probe_() and
> fdt_check_header() already have a lot of the same checks.
> 
>  libfdt/fdt.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index 3e893073da05..9fe7cf4b747d 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -90,6 +90,10 @@ int fdt_check_header(const void *fdt)
>  {
>  	size_t hdrsize;
>  
> +	/* The device tree must be at an 8-byte aligned address */
> +	if ((uintptr_t)fdt & 7)
> +		return -FDT_ERR_ALIGNMENT;
> +
>  	if (fdt_magic(fdt) != FDT_MAGIC)
>  		return -FDT_ERR_BADMAGIC;
>  	if (!can_assume(LATEST)) {

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-04-07  2:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 19:07 [PATCH] libfdt: Add FDT alignment check to fdt_check_header() Rob Herring
     [not found] ` <20210406190712.2118098-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-04-07  2:45   ` David Gibson [this message]
2021-04-07 15:35   ` Simon Glass
     [not found]     ` <CAPnjgZ3fmzymABa4orPYxVQG4SaprSXZa+4AT9=yBYm8B6Md_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 17:25       ` Rob Herring
     [not found]         ` <CAL_JsqK+h8v2PY9W2jzoAihFwb+7T0oqkoSKrtOSf1mgYfU1mA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 18:35           ` Simon Glass
2021-04-07 18:09       ` Tom Rini
2021-04-07 18:36         ` Simon Glass
     [not found]           ` <CAPnjgZ2rGyCVQwQ3aP+=wF99R+2C_POV1Y=18jd8eAd+sOqSZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 18:39             ` Tom Rini

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=YG0c1IZXS5o0/rBR@yekko.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.