On Thu, Mar 17, 2022 at 8:26 AM WILLIAMS Stephen via Devel <[email protected]> wrote: > > Hi, > > I’m currently working on a project porting drivers from U-Boot to seL4 and > have run into an unexpected problem seemingly triggered by use of the > memalign within the U-Boot drivers. > > What I am seeing is that calls to memalign from within my CAmkES component > can return pointers to regions which overlap with those previously returned > by malloc. Obviously this leads to the two allocated regions trampling over > each other and resulting corruption of data. > > I’m at a complete loss to explain this behaviour and would be very grateful > to receive any suggestions or pointers. >
Both malloc and memalign in camkes are provided by our fork of libmuslc (https://github.com/sel4/musllibc/). Internally, memalign calls malloc and so it seems like your issue can be reduced to multiple calls to malloc are returning overlapping regions. This could be for a couple reasons: - Within the default camkes runtime, muslc functions such as malloc aren't thread safe and so must be called from critical sections guarded by a lock to avoid races. Many camkes components use a global lock when performing operations that mutate state: https://github.com/seL4/global-components/blob/master/components/TimeServer/src/time_server.c#L152, or they don't use dynamic memory allocation after initialization (as initialization is single threaded). This lack of thread safety is a bit nasty and the runtime should do more to protect developers from this, but currently I don't think it does. - You have memory corruption somewhere else that's causing malloc's bookkeeping structures to be corrupted. > Thanks for your help, > Stephen > This message contains information that may be privileged or confidential and > is the property of the Capgemini Group. It is intended only for the person to > whom it is addressed. If you are not the intended recipient, you are not > authorized to read, print, retain, copy, disseminate, distribute, or use this > message or any part thereof. If you receive this message in error, please > notify the sender immediately and delete all copies of this message. > _______________________________________________ > Devel mailing list -- [email protected] > To unsubscribe send an email to [email protected] _______________________________________________ Devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
