[Chilli] cast issue with packed structs under arm

Peter Warasin peter at endian.com
Fri Jun 17 17:22:50 UTC 2011


hi guys

i currently deal with an issue we notice with coova-chilli 1.2.6 under
armv5tel (marvell kirkwood). i have a possible solution, but would like
to ask for your opinion, maybe there's a better solution than mine.


===================
What happened to us
===================

We have a user with a static ip configured (FRAMED_IP_ADDRESS) to
192.168.11.66.
The user logged in without problems and everything worked, but it did
not have configured 192.168.11.66 but 192.168.11.6

Similar problem (i found out) is with logging out a user with
chilli_query logout ip 192.168.11.1
which is not working at all.

Another related problem is mac addresses shown in chilli_query list
which should be the same actually show up as different.

Within exactly the same environment but x86 works all as expected.


=====
Cause
=====

The issue is in cb_radius_auth_conf() in line 3647:

    hisip = (struct in_addr*) &(hisipattr->v.i);

This cast is invalid under arm. In arm everything must be aligned,
otherwise it is fixed up by the kernel (with cpu cost). The radius
struct is packed, so the compiler adds no padding to the assembler
representation.

It looks like that because of type-punning the compiler does not know
that the struct is packed, reads the first 3 bytes and overjumps then
the next 2 bytes, where the padding normally, when not packed, should
be. Result is, instead of 192.168.11.66 i get 192.168.11.6, when 6 is
the value which resides within memory area 2 bytes after 66


=================
Possible solution
=================

http://pastebin.com/VgxRxzJn

here you see an isolated code of this problem commented out the line
which causes the problem and added a workaround i found within tcpdump.

this actually is working

Now I am no expert on alignment of memory and arm at all,. so I asked
around a bit in #arm channels, for maybe a very easy solution.. well.
looks like there is no simple compiler flag or something which fixes
this. I think it is really necessary to change every cast.

However this means it is necessary to check every cast in coova-chilli.
This probably happens on many places, which maybe nobody did recognized yet.
And then after all it is necessary to replace these lines adding then
also a temporary variable which need to be mallocd and freed. (don't
like that)

I start now to write a patch which fixes the issues mentioned above,.
But i am unsure if this is a good solution, so probably i will not
search for every probably invalid cast right now before i got your opinions.

So please be verbose :)

thank you in advance

peter


-- 
:: e n d i a n
:: open source - open minds

:: peter warasin
:: http://www.endian.com   :: peter at endian.com


More information about the Chilli mailing list