[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Kernel unaligned accesses (was: booting on a microway alpha box)



On Tue 23 Jul 2002, Jon Leonard wrote:
> 
> The contents of two relevant /proc files:
>  
> frost:~# cat /proc/cpuinfo
> cpu                     : Alpha
> cpu model               : EV56
[snip]
> cycle frequency [Hz]    : 600000000

Wow, how precise! I have 366656400...

> kernel unaligned acc    : 361582386 (pc=fffffc0000533914,va=fffffc000064cd81)

I noticed a lot of kernel unaligned accesses in my 2.4 kernel as well.
After some investigation, I tracked down two places which were
responsible. The most important one is in the netfilter code (iptables),
another is in the packet filter (isn't it always in the network code...)

I've sent a message to the netfilter people, it's on the todo list now.
Basically it's ensuring that the char array nulldevname in
ipt_do_table(), in file net/ipv4/netfilter/ip_tables.c, is word-aligned,
as that's used in int accesses, with some black magic bitwise boolean
operations.  I hacked that by putting nulldevname into a struct with a
long before and after it :-)  No patch, I hope someone else can come up
with a better fix...

The other is in net/core/filter.c where parts of a char array are cast
to u32 or u16 and accessly thusly. This one is used e.g. with tcpdump,
when you use a condition to limit what packets are shown.
Here's the patch:

--- net/core/filter.c.orig	Wed May 16 19:32:59 2001
+++ net/core/filter.c	Fri Jul 19 20:29:01 2002
@@ -202,7 +202,9 @@
 				k = fentry->k;
 load_w:
 				if(k >= 0 && (unsigned int)(k+sizeof(u32)) <= len) {
-					A = ntohl(*(u32*)&data[k]);
+					u32 tmp;
+					memcpy(&tmp, &data[k], sizeof(u32));
+					A = ntohl(tmp);
 					continue;
 				}
 				if (k<0) {
@@ -227,7 +229,9 @@
 				k = fentry->k;
 load_h:
 				if(k >= 0 && (unsigned int) (k + sizeof(u16)) <= len) {
-					A = ntohs(*(u16*)&data[k]);
+					u16 tmp;
+					memcpy(&tmp, &data[k], sizeof(u16));
+					A = ntohs(tmp);
 					continue;
 				}
 				if (k<0) {

I've sent that to the email address listed as the author at the top of the file, but
have not had response yet.  Perhaps someone else knows a better channel?


Zero kernel unaligned accesses in the meantime, after a gigabyte of
network through the box. Yay!  Although there are probably other
problems hidden away in places I don't touch...



Paul Slootman


-- 
To UNSUBSCRIBE, email to debian-alpha-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: