Re: Subject: [PATCH 02/16] Squashfs: directory lookup operations

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Geert Uytterhoeven
Date: Tuesday, October 28, 2008 - 10:42 am

On Fri, 17 Oct 2008, Phillip Lougher wrote:


As str has been returned by kmalloc(), and SQUASHFS_NAME_LEN is equal to 256,
`str + SQUASHFS_NAME_LEN + 1` is an odd address.

                                   ^^^^^^^^^^^
				     ^^^^^^^^^^^
					  ^^^^^^^^^^^^^^^^^^

Hence accessing multi-byte fields in struct squashfs_dir_index causes unaligned
accesses, which are emulated on some architectures (e.g. on MIPS).

Use get_unaligned_le32() for unaligned accesses.

Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
---
Actual patch is against current squashfs4.

 fs/squashfs/namei.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

--- a/fs/squashfs/namei.c
+++ b/fs/squashfs/namei.c
@@ -59,6 +59,8 @@
 #include <linux/dcache.h>
 #include <linux/zlib.h>
 
+#include <asm/unaligned.h>
+
 #include "squashfs_fs.h"
 #include "squashfs_fs_sb.h"
 #include "squashfs_fs_i.h"
@@ -101,7 +103,7 @@ static int get_dir_index_using_name(stru
 			break;
 
 
-		size = le32_to_cpu(index->size) + 1;
+		size = get_unaligned_le32(&index->size) + 1;
 
 		err = squashfs_read_metadata(sb, index->name, &index_start,
 					&index_offset, size);
@@ -113,8 +115,8 @@ static int get_dir_index_using_name(stru
 		if (strcmp(index->name, str) > 0)
 			break;
 
-		length = le32_to_cpu(index->index);
-		*next_block = le32_to_cpu(index->start_block) +
+		length = get_unaligned_le32(&index->index);
+		*next_block = get_unaligned_le32(&index->start_block) +
 					msblk->directory_table;
 	}
 

With kind regards,

Geert Uytterhoeven
Software Architect

Sony Techsoft Centre Europe
The Corporate Village
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Subject: [PATCH 02/16] Squashfs: directory lookup operations, Phillip Lougher, (Fri Oct 17, 8:42 am)
Re: Subject: [PATCH 02/16] Squashfs: directory lookup oper ..., Geert Uytterhoeven, (Tue Oct 28, 10:42 am)
Re: Subject: [PATCH 02/16] Squashfs: directory lookup oper ..., Geert Uytterhoeven, (Tue Oct 28, 1:19 pm)