diff mbox

[U-Boot,V2,3/7] lcd: prevent unaligned memory access when displaying splash screen

Message ID 1359618000-19069-4-git-send-email-nikita@compulab.co.il
State Rejected
Delegated to: Anatolij Gustschin
Headers show

Commit Message

Nikita Kiryanov Jan. 31, 2013, 7:39 a.m. UTC
When the bmp file is loaded to an address specified by the environment
variable "splashimage", its header members might be unaligned.
This happens because the bmp header starts with two byte size fields followd by
mostly 32 bit fields. When the address in splashimage is not equal to aligned
address plus/minus 2, the 32 bit members will be placed in unaligned addresses
and the result would be a data abort on targets that cannot handle unaligned
memory accesses.

Check that the address is safe to use, and fix it if it's not.

Cc: Anatolij Gustschin <agust@denx.de>
Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
Cc: Jeroen Hofstee <jeroen@myspectrum.nl>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
---
Changes in V2: None. Patch introduced in V2.

 common/lcd.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Nikita Kiryanov Feb. 10, 2013, 11:14 a.m. UTC | #1
Following the discussion in the "Create an API for safely accessing BMP
header fields" patch series, this patch should be dropped.

On 01/31/2013 09:39 AM, Nikita Kiryanov wrote:
> When the bmp file is loaded to an address specified by the environment
> variable "splashimage", its header members might be unaligned.
> This happens because the bmp header starts with two byte size fields followd by
> mostly 32 bit fields. When the address in splashimage is not equal to aligned
> address plus/minus 2, the 32 bit members will be placed in unaligned addresses
> and the result would be a data abort on targets that cannot handle unaligned
> memory accesses.
>
> Check that the address is safe to use, and fix it if it's not.
>
> Cc: Anatolij Gustschin <agust@denx.de>
> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
> Cc: Jeroen Hofstee <jeroen@myspectrum.nl>
> Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
> Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
> ---
> Changes in V2: None. Patch introduced in V2.
>
>   common/lcd.c |    8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/common/lcd.c b/common/lcd.c
> index 66d4f94..104125d 100644
> --- a/common/lcd.c
> +++ b/common/lcd.c
> @@ -1046,6 +1046,14 @@ static void *lcd_logo(void)
>   		do_splash = 0;
>
>   		addr = simple_strtoul (s, NULL, 16);
> +		/*
> +		 * In order for the fields of bmp header to be properly aligned
> +		 * in memory, splash image addr must be aligned to "aligned
> +		 * address plus 2". Fix addr if necessary.
> +		 */
> +		if (addr % 4 != 2)
> +			addr += (addr % 4) ?: 2;
> +
>   #ifdef CONFIG_SPLASH_SCREEN_ALIGN
>   		s = getenv("splashpos");
>   		if (s != NULL) {
>
diff mbox

Patch

diff --git a/common/lcd.c b/common/lcd.c
index 66d4f94..104125d 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -1046,6 +1046,14 @@  static void *lcd_logo(void)
 		do_splash = 0;
 
 		addr = simple_strtoul (s, NULL, 16);
+		/*
+		 * In order for the fields of bmp header to be properly aligned
+		 * in memory, splash image addr must be aligned to "aligned
+		 * address plus 2". Fix addr if necessary.
+		 */
+		if (addr % 4 != 2)
+			addr += (addr % 4) ?: 2;
+
 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
 		s = getenv("splashpos");
 		if (s != NULL) {