All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Orzel, Michal" <michal.orzel@amd.com>
To: Jason Andryuk <jason.andryuk@amd.com>, xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>
Subject: Re: [PATCH] device-tree/kernel: Use memcpy in output_length()
Date: Wed, 23 Jul 2025 08:33:59 +0200	[thread overview]
Message-ID: <0aac46ee-fd2f-43b4-accd-6eae133c618e@amd.com> (raw)
In-Reply-To: <1d5c10bc-eb69-492c-9f1a-6a273feecdcd@amd.com>



On 22/07/2025 06:50, Jason Andryuk wrote:
> On 2025-07-22 03:46, Michal Orzel wrote:
>> Trying to boot a compressed kernel with UBSAN enabled, results in the
>> following warning:
>> (XEN) UBSAN: Undefined behaviour in common/device-tree/kernel.c:21:12
>> (XEN) load of misaligned address 00000a0040f89867 for type 'uint32_t'
>> (XEN) which requires 4 byte alignment
>> ...
>> (XEN)    [<00000a0000529964>] kernel_decompress+0x2bc/0x5bc
>> (XEN)    [<00000a000052a354>] kernel_probe+0x6f0/0x734
>> (XEN)    [<00000a0000528714>] dom0less-build.c#construct_domU+0x188/0x9d8
>>
>> If &image[image_len - 4] is not aligned to 4B boundary it causes
>> unaligned access which is undefined behavior on Arm. Use memcpy instead
>> to be safe.
>>
>> Fixes: c1be0b102e0e ("xen/arm: support gzip compressed kernels")
>> Signed-off-by: Michal Orzel <michal.orzel@amd.com>
>> ---
>>   xen/common/device-tree/kernel.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/xen/common/device-tree/kernel.c b/xen/common/device-tree/kernel.c
>> index ef393182b691..28096121a52d 100644
>> --- a/xen/common/device-tree/kernel.c
>> +++ b/xen/common/device-tree/kernel.c
>> @@ -18,7 +18,11 @@
>>   
>>   static uint32_t __init output_length(char *image, unsigned long image_len)
>>   {
>> -    return *(uint32_t *)&image[image_len - 4];
> 
> Maybe just:
>      return get_unaligned_le32(&image[image_len - 4]);
> 
> You'll also need:
> #include <xen/unaligned.h>
> 
> The gzip size is little endian, 
I thought about this solution but decided to use memcpy because one day we may
want to support other compression algorithms and forcing LE could cause issues.

I'm ok either way. Let other maintainers decide.

~Michal



  reply	other threads:[~2025-07-23  6:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22  7:46 [PATCH] device-tree/kernel: Use memcpy in output_length() Michal Orzel
2025-07-22  4:50 ` Jason Andryuk
2025-07-23  6:33   ` Orzel, Michal [this message]
2025-07-23  6:44     ` Bertrand Marquis

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=0aac46ee-fd2f-43b4-accd-6eae133c618e@amd.com \
    --to=michal.orzel@amd.com \
    --cc=bertrand.marquis@arm.com \
    --cc=jason.andryuk@amd.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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.