Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1490290 > unrolled thread

[PATCH] of: Prevent unaligned access in of_alias_scan()

Started byPaul Burton <paul.burton@imgtec.com>
First post2016-09-23 18:00 +0200
Last post2016-09-23 18:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] of: Prevent unaligned access in of_alias_scan() Paul Burton <paul.burton@imgtec.com> - 2016-09-23 18:00 +0200
    Re: [PATCH] of: Prevent unaligned access in of_alias_scan() Grant Likely <grant.likely@secretlab.ca> - 2016-09-23 18:20 +0200

#1490290 — [PATCH] of: Prevent unaligned access in of_alias_scan()

FromPaul Burton <paul.burton@imgtec.com>
Date2016-09-23 18:00 +0200
Subject[PATCH] of: Prevent unaligned access in of_alias_scan()
Message-ID<skB3j-5Jn-9@gated-at.bofh.it>
When allocating a struct alias_prop, of_alias_scan() only requested that
it be aligned on a 4 byte boundary. The struct contains pointers which
leads to us attempting 64 bit writes on 64 bit systems, and if the CPU
doesn't support unaligned memory accesses then this causes problems -
for example on some MIPS64r2 CPUs including the "mips64r2-generic" QEMU
emulated CPU it will trigger an address error exception.

Fix this by requesting alignment for the struct alias_prop allocation
matching that which the compiler expects, using the __alignof__ keyword.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: devicetree@vger.kernel.org
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: Ralf Baechle <ralf@linux-mips.org>
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3ce6953..448aa40 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2042,7 +2042,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 			continue;
 
 		/* Allocate an alias_prop with enough space for the stem */
-		ap = dt_alloc(sizeof(*ap) + len + 1, 4);
+		ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));
 		if (!ap)
 			continue;
 		memset(ap, 0, sizeof(*ap) + len + 1);
-- 
2.10.0

[toc] | [next] | [standalone]


#1490301

FromGrant Likely <grant.likely@secretlab.ca>
Date2016-09-23 18:20 +0200
Message-ID<skBmF-69k-1@gated-at.bofh.it>
In reply to#1490290
On Fri, Sep 23, 2016 at 4:38 PM, Paul Burton <paul.burton@imgtec.com> wrote:
> When allocating a struct alias_prop, of_alias_scan() only requested that
> it be aligned on a 4 byte boundary. The struct contains pointers which
> leads to us attempting 64 bit writes on 64 bit systems, and if the CPU
> doesn't support unaligned memory accesses then this causes problems -
> for example on some MIPS64r2 CPUs including the "mips64r2-generic" QEMU
> emulated CPU it will trigger an address error exception.
>
> Fix this by requesting alignment for the struct alias_prop allocation
> matching that which the compiler expects, using the __alignof__ keyword.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>

Looks right to me.

Reviewed-by: Grant Likely <grant.likely@secretlab.ca>

> Cc: devicetree@vger.kernel.org
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-mips@linux-mips.org
> Cc: Ralf Baechle <ralf@linux-mips.org>
> ---
>  drivers/of/base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 3ce6953..448aa40 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2042,7 +2042,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
>                         continue;
>
>                 /* Allocate an alias_prop with enough space for the stem */
> -               ap = dt_alloc(sizeof(*ap) + len + 1, 4);
> +               ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));
>                 if (!ap)
>                         continue;
>                 memset(ap, 0, sizeof(*ap) + len + 1);
> --
> 2.10.0
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web