From: Matt Fleming <matt.fleming@intel.com>
To: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: "H. Peter Anvin" <hpa@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: build failure in Linus' tree with gcc 4.4.3
Date: Tue, 21 Feb 2012 10:01:57 +0000 [thread overview]
Message-ID: <1329818517.3639.29.camel@mfleming-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <1329731019.3639.20.camel@mfleming-mobl1.ger.corp.intel.com>
On Mon, 2012-02-20 at 09:43 +0000, Matt Fleming wrote:
> On Mon, 2012-02-20 at 14:22 +1100, Stephen Rothwell wrote:
> > Which is all endian specific code that will run on the host when building
> > the kernel ...
>
> Gah, right. I didn't think about cross-building this code.
>
> Thanks Stephen, I'll fix this up.
Looks like the segfault is caused by an unaligned access? How does this
patch look?
>From 54b2707a6a911330d8db2f4ec2fb1baa5e38acf9 Mon Sep 17 00:00:00 2001
From: Matt Fleming <matt.fleming@intel.com>
Date: Mon, 20 Feb 2012 17:32:42 +0000
Subject: [PATCH] x86, efi: Fix segfault caused by unaligned access
We need to use memcpy() instead of directly dereferencing a pointer
because memcpy() correctly handles the case where the
source/destination are unaligned, which can lead to a segfault when
cross-building an x86 kernel on risc architectures.
Stephen Rothwell noticed this bug when he hit a segfault while
cross-building an x86_64 allmodconfig kernel on PowerPC.
Cc: H. Peter Anvin <hpa@zytor.com>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
arch/x86/boot/tools/build.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 4e9bd6b..b4d85b5 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -200,36 +200,38 @@ int main(int argc, char ** argv)
#ifdef CONFIG_EFI_STUB
file_sz = sz + i + ((sys_size * 16) - sz);
- pe_header = *(unsigned int *)&buf[0x3c];
+ memcpy(&pe_header, &buf[0x3c], sizeof(pe_header));
/* Size of code */
- *(unsigned int *)&buf[pe_header + 0x1c] = file_sz;
+ memcpy(&buf[pe_header + 0x1c], &file_sz, sizeof(file_sz));
/* Size of image */
- *(unsigned int *)&buf[pe_header + 0x50] = file_sz;
+ memcpy(&buf[pe_header + 0x50], &file_sz, sizeof(file_sz));
#ifdef CONFIG_X86_32
/* Address of entry point */
- *(unsigned int *)&buf[pe_header + 0x28] = i;
+ memcpy(&buf[pe_header + 0x28], &i, sizeof(i));
/* .text size */
- *(unsigned int *)&buf[pe_header + 0xb0] = file_sz;
+ memcpy(&buf[pe_header + 0xb0], &file_sz, sizeof(file_sz));
/* .text size of initialised data */
- *(unsigned int *)&buf[pe_header + 0xb8] = file_sz;
+ memcpy(&buf[pe_header + 0xb8], &file_sz, sizeof(file_sz));
#else
+ /* .text size */
+ memcpy(&buf[pe_header + 0xc0], &file_sz, sizeof(file_sz));
+
+ /* .text size of initialised data */
+ memcpy(&buf[pe_header + 0xc8], &file_sz, sizeof(file_sz));
+
/*
* Address of entry point. startup_32 is at the beginning and
* the 64-bit entry point (startup_64) is always 512 bytes
* after.
*/
- *(unsigned int *)&buf[pe_header + 0x28] = i + 512;
+ file_sz = i + 512;
+ memcpy(&buf[pe_header + 0x28], &file_sz, sizeof(file_sz));
- /* .text size */
- *(unsigned int *)&buf[pe_header + 0xc0] = file_sz;
-
- /* .text size of initialised data */
- *(unsigned int *)&buf[pe_header + 0xc8] = file_sz;
#endif /* CONFIG_X86_32 */
#endif /* CONFIG_EFI_STUB */
--
1.7.4.4
next prev parent reply other threads:[~2012-02-21 10:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-20 2:39 build failure in Linus' tree with gcc 4.4.3 Stephen Rothwell
2012-02-20 3:22 ` Stephen Rothwell
2012-02-20 9:43 ` Matt Fleming
2012-02-21 10:01 ` Matt Fleming [this message]
2012-02-21 10:38 ` Stephen Rothwell
2012-02-21 11:32 ` Matt Fleming
2012-02-21 11:51 ` Stephen Rothwell
2012-02-21 11:58 ` Matt Fleming
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=1329818517.3639.29.camel@mfleming-mobl1.ger.corp.intel.com \
--to=matt.fleming@intel.com \
--cc=hpa@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
/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;
as well as URLs for NNTP newsgroup(s).