LD_PRELOAD checker for clock_gettime and consorts
Hello,
as you might know, I run into alot of troubles with realtime code calling clock_gettime.
This function is now a syscall on many architectures and depends on a linux kernel spinlock,
so a RT thread might deadlock itself when both trying to claim that lock and preventing the linux kernel to free it.
Usage is rather simple, the code compiles without any Cobalt/Xenomai headers. RT-threads need to enable PTHREAD_WARNSW:pthread_setmode_np(0, PTHREAD_WARNSW, NULL);
And the checker library needs to be preloaded:
LD_PRELOAD=libcobalt-gettime_checker.so ./yourapp -and -your -params.
Unlike the existing mode-checker, this does not need any changes to the binary, and will also catch calls from all directly and indirectly loaded DSOs.
Other skins should be supported aswell, aslong as libcobalt is loaded (or more specific, the code looks for a symbol "cobalt_assert_nrt").
Kind regards,
Norbert
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libcobalt-gettime_checker.c
URL: <http://xenomai.org/pipermail/xenomai/attachments/20190110/bc2720f2/attachment.c>
And heres a checker for malloc/free and consorts. This one is a bit trickier and I have barely tested it.
Quoted 63 lines
-----Original Message-----
From: Xenomai <[email protected]> On Behalf Of Lange Norbert via Xenomai
Sent: Donnerstag, 10. Jänner 2019 14:47
To: Xenomai ([email protected]) <[email protected]>
Subject:LD_PRELOADchecker forclock_gettimeand consortsE-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR ATTACHMENTS.
Hello,
as you might know, I run into alot of troubles with realtime code calling
clock_gettime.
This function is now a syscall on many architectures and depends on a linux kernel spinlock, so a RT thread might deadlock itself when both trying to claim that lock and preventing the linux kernel to free it.Usage is rather simple, the code compiles without any Cobalt/Xenomai headers.
RT-threads need to enablePTHREAD_WARNSW:pthread_setmode_np(0, PTHREAD_WARNSW, NULL);And the checker library needs to be preloaded:
LD_PRELOAD=libcobalt-gettime_checker.so ./yourapp -and -your -params.Unlike the existing mode-checker, this does not need any changes to the binary, and will also catch calls from all directly and indirectly loaded DSOs.
Other skins should be supported aswell, aslong as libcobalt is loaded (or more specific, the code looks for a symbol "
cobalt_assert_nrt").Kind regards,
Norbert
________________________________This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Quoted 8 lines
Thank You
________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name:libcobalt-gettime_checker.c
URL:
<http://xenomai.org/pipermail/xenomai/attachments/20190110/bc2720f2/attachment.c>
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libcobalt-malloc_checker.c
URL: <http://xenomai.org/pipermail/xenomai/attachments/20190110/4a80304a/attachment.c>
Quoted 2 lines · Lange Norbert via Xenomai
And heres a checker for malloc/free and consorts. This one is a bit trickier and I have barely tested it.
Looks useful, thanks for sharing!
In order to make it more easily accessible to users, we could provide it as "libcobalt-modecheck.so" or so in-tree and descibe its usage.
I think, rather than the gcc-dependent open-coded solution, pthread_once should address your needs to initialize pointers and state on first invocation.
What would also be good is to have a couple of tests for it that stress the basic and also non-trival cases the tool should catch.
Jan
Quoted 98 lines
Quoted 63 lines
-----Original Message-----
From: Xenomai <[email protected]> On Behalf Of Lange Norbert via Xenomai
Sent: Donnerstag, 10. Jänner 2019 14:47
To: Xenomai ([email protected]) <[email protected]>
Subject:LD_PRELOADchecker forclock_gettimeand consortsE-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR ATTACHMENTS.
Hello,
as you might know, I run into alot of troubles with realtime code calling
clock_gettime.
This function is now a syscall on many architectures and depends on a linux kernel spinlock, so a RT thread might deadlock itself when both trying to claim that lock and preventing the linux kernel to free it.Usage is rather simple, the code compiles without any Cobalt/Xenomai headers.
RT-threads need to enablePTHREAD_WARNSW:pthread_setmode_np(0, PTHREAD_WARNSW, NULL);And the checker library needs to be preloaded:
LD_PRELOAD=libcobalt-gettime_checker.so ./yourapp -and -your -params.Unlike the existing mode-checker, this does not need any changes to the binary, and will also catch calls from all directly and indirectly loaded DSOs.
Other skins should be supported aswell, aslong as libcobalt is loaded (or more specific, the code looks for a symbol "
cobalt_assert_nrt").Kind regards,
Norbert
________________________________This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Quoted 8 lines
Thank You
________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name:libcobalt-gettime_checker.c
URL:
<http://xenomai.org/pipermail/xenomai/attachments/20190110/bc2720f2/attachment.c>________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name:libcobalt-malloc_checker.c
URL: <http://xenomai.org/pipermail/xenomai/attachments/20190110/4a80304a/attachment.c>
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 19 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Freitag, 11. Jänner 2019 03:26
To: Lange Norbert <[email protected]>; Xenomai ([email protected]) <[email protected]>
Subject: Re: FW:LD_PRELOADchecker forclock_gettimeand consortsE-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR ATTACHMENTS.
Quoted 1 line · Lange Norbert via Xenomai
And heres a checker for malloc/free and consorts. This one is a bit trickier
and I have barely tested it.
Quoted 1 line
Quoted 7 lines
Looks useful, thanks for sharing!
In order to make it more easily accessible to users, we could provide it as "libcobalt-modecheck.so" or so in-tree and descibe its usage.
I think, rather than the gcc-dependent open-coded solution,
pthread_onceshould address your needs to initialize pointers and state on first invocation.
What if pthread_once calls the overridden functions? I haven’t fully understood the order the linker calls into DSO startups, but a library thing like pthread_once would make this harder and more fragile.
I have to work around libdl and libc DSO startup and its transitive calls, AFAIK pthread_once will go live a lot later so not solve anything.
If anything, then rtld-audit could probably be used, but that would be highly dependent on glibc.
Also, what gcc-dependent part is troublesome to you? The only *functional required* thing would be the barrier __asm__ __volatile__("" ::: "memory")
and that’s primary because you don’t have any standardized way of doing that before C11.
Quoted 2 lines
What would also be good is to have a couple of tests for it that stress the basic and also non-trival cases the tool should catch.
Indeed, ist only a matter of time allocation =)
Norbert
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________