arXiv:2106.01766v1 [cs.SE] 3 Jun 2021 es faycprgtdcmoeto hswr nohrwork other in work this of component copyrighted Perm any or permitted. is of advertising material reuse for this material of this use reprinting/republishing Personal IEEE. 6 2018 ARINC © of Analysis 10.1109/ISPRAS.2018.00009. “Dynamic Khoroshilov, DOI: A. and Cheptsov V. o eea-ups otaedvlpetmyb endby defined be objective may minimal development The general-purpose etc. for verification, and modelling ins code regular a fuzz-testing, instrumentation, static dynamic testing, supportin ysis, conformance to comprised model objectives threat be programmin formal documentation, may defensive and coverage, taken semiformal test measures redundancy, standards, of coding set of: the used, developed. uments being currently are possible, as early mi making as the made of detecting importantly, most risks and, the elimination, cost their the reducing imper- decreasing development, biological methods software circumvent during of mistakes To number future. a the fection, in malfunctionin program point in i some result mistakes at may of which probability code, high done written a is the remain programming will as there long humans, As by science. computer in studied tools. the of effects the maximise to enhancem runtimes and the optimisations to uninvolved sy suggest operating an we and example, , addition caveat a the sanitizer, an a against sides: As details relevant UndefinedB the GosNIIAS. and provide with and MemorySanitizer, haviorSanitizer AddressSanitizer, collaboration develo port prospective in being we a RAS currently JetOS, ISP system to at operating support tool stack real-time instrumentation LLVM onboard complete general-purpose a of instrumentatio accou bring into use dynamic taken effective speci be to to the the regards considerations discuss practical with provide we and hea systems paper to airborne introduced this of be In to environments. sani- general- thought restricted not to and was applied memory analyser originally regularly LLVM software, to while flow. infrastructure, constructions control defect tizer invalid code software or non-conforming find corruptions automatically strictly strong to analysi to from have static used meant but and practices are instrumentation consequences, common taken Dynamic undesired measures costs. of the varying The risks to aircraft. the sys applicable operating reduce modern real-time requirements in hard of found of cycle number development a software impose systems ytm,AIC63 M,LLVM IMA, 653, ARINC systems, eedn ntesfwr ieyl n euaoydoc- regulatory and lifecycle software the on Depending was it before since existed correctness code of problem The Terms Index Abstract Eitn tnad o ibreebde software airborne-embedded for standards —Existing vnio nttt o ytmProgramming System for Institute Ivannikov yai nlsso RN 5 RTOS 653 ARINC of Analysis Dynamic dnmcisrmnain eltm operating real-time instrumentation, —dynamic fteRsinAaeyo Sciences; of Academy Russian the of ihrSho fEconomics of School Higher .I I. [email protected] NTRODUCTION iayCheptsov Vitaly ocw Russia Moscow, rmtoa upss raignwcletv ok,frr for works, collective new creating purposes, promotional ihLLVM with sinfo EEms eotie o l te ss naycu any in uses, other all for obtained be must IEEE from ission s. 3RO ihLV, 08IankvIpa pnCneec (I Conference Open Ispras Ivannikov 2018 LLVM,” with RTOS 53 pection, tm In stem. purpose nall on s stakes .We s. tfor nt are s tems for s nal- ents ped vily fics g, ly e- s, n n g g s fcec fts eut ntne ihteohrtools. other the with t tandem increase in showcase to results actions We test suggest system. of and efficiency found operating be real-time to issues hard possible a runt in sanitizer implementing could support of issues specifics the and and objectives on, the focused which and applications itself, 653 system ARINC operating too testing general- which for describe applicable We to be environments. may intende restricted applied in not system used commonly were be operating but to are projects airborne development tools certified software purpose a These in [4]. up JetOS detecti them error bring and and erro instrumentation software general-purpose infrastructure dynamic of sanitizer LLVM geting set the on a based fo take tools instrumentation detection We dynamic detection. to error regards early in systems operating other. each necess to not aga conform which certifying objectives containing when wheneve standards important multiple applied especially efficiently is documents and This regulatory possible. for sought particular continuously in measur are verification additional included the costs, detection not the versus defect service, lower sometimes stage To timely into early [3]. of the put stage resulting production at price being different The the to quite that [2]. prior is shows certified industrial DO-178C history be in is and to defined it has objectives, aviation product as For precautions strict to standards. of amount referred large a commonly under damage, performed property be or nature only severe inju in loss, resulting human disasters costs or which of failure systems, of Creation [1]. developme 56939—2016 secure R for GOST like standards lifecycle, international and national ee.I hspprw ee odnmcisrmnainin instrumentation dynamic compiler to the refer or we level paper source this the In on level. m alteration instrumentation code of kinds require Different runtime. coverage, at violation, debugging contract performance, informa program gather about to allowing parameters certain by behaviour nti ae esuyteseic fmdr airborne modern of specifics the study we paper this In domain. different entirely an is software critical Safety yai ntuetto sawyt esr program measure to way a is instrumentation Dynamic vnio nttt o ytmProgramming System for Institute Ivannikov fteRsinAaeyo Sciences of Academy Russian the of [email protected] lxyKhoroshilov Alexey ocw Russia Moscow, I S II. AEO THE OF TATE sl rrdsrbto osreso it,or lists, or servers to redistribution or esale rn rftr ei,including media, future or rrent A RT PA) 08 p 9-15, pp. 2018, SPRAS), tar- , arily may tion ime and inst ries on, es, he be ay or nt ls d r r r , , the sense of compiler passes applying modifications targeting integer overflow, incorrect execution of floating-point programming error detection. calculations, incorrect boolean type assignment, etc; While the benefits of dynamic instrumentation may be vast, • ThreadSanitizer – data race condition detection tool. Used there are not so many publicly available tools that could be for finding errors in multithreaded programs; integrated at a reasonable cost. , such as • Control Flow Integrity – tool implementing a number of WinDbg, Intel Inspector, UNICOM PurifyPlus, Insure++, and control flow integrity checks including the detection of several others, usually target specific platforms or userspace incorrect class and function casts and invalid virtual table instrumentation, and even if free for use come with no source usage; availability. As a result, it is either impossible or very costly to • LeakSanitizer – detection tool; adopt it to embedded projects, putting aside the safety-critical • EfficiencySanitizer – tool for detecting suboptimal lan- systems segment. The few existing opensource tools have the guage constructions and ; exact same problems except in-house resources are to be spent • SafeStack – tool intended to protect software from stack for the bring up. buffer overflow with no measurable performance costs; is one of the oldest and most powerful tool suites • libFuzzer – fuzz testing tool. currently developed. It supports a large number of CPUs and These tools are being continuously ported to GCC as well, was proven to be quite effective on general-purpose operating however, the GCC support list is incomplete and suffers from systems, like targets, macOS, or Android. However, backport delays. On the good side, LLVM and try to using Valgrind on non-Linux and even non-POSIX targets may support a reasonable amount of GCC-supported platforms and be quite challenging. One of the ways to use Valgrind could be extensions, which allows a drop-in replacement in the majority porting the code to a simulated Linux-based environment, but of the BSPs. this results in additional costs of supporting multiple systems as well as the inability to detect bugs in the original code, III. JETOS which makes the task effectively unrewarding. In addition, Valgrind seriously affects the performance of the instrumented JetOS is a cross-platform hard real-time operating system code [5]. DynamoRIO based Dr. Memory and the supple- designed to control airborne equipment in modern civil avia- mental tools are quite promising, but once again the current tion. One of the fundamental requirements in its implementa- development course is focused on expanding the functionality tion is accordance with ARINC 653 [8] parts 1 and 2. ARINC and resolving the issues in general-purpose operating systems. 653 (Avionics Application Standard Software Interface) de- PowerPC or MIPS-based CPUs are not yet even considered. scribes the implementation of APEX (APplication/EXecutive), an API that regulates space and time partitioning in safety- From this perspective the LLVM project [6] favourably critical real-time operating systems for avionics. This stan- differs from the others by consisting of reusable modules han- dard allows the hosting of multiple applications of different dling compiling, building, and instrumenting stages altogether. software levels on the same hardware in the context of an Just like GNU Compiler Collection (GCC), LLVM subprojects Integrated Modular Avionics (IMA) [9] architecture. In turn, contain all the necessary components to create a fully-fledged IMA is an airborne system architecture used in modern air- toolchain for a target Board Support Package (BSP). It has an crafts (Boeing 787, Airbus A350, etc.) replacing the outdated optimizer with code generation support with broad target ar- Federated Architecture (FA). It features a common network of chitecture and CPU compatibility, a /C++/Objective-C code software components portable among standard hardware mod- compiler, a set of libraries for lower-level code generation ules, which allows to significantly reduce hardware resource support, C++ standard library, as well as its own linker and consumption. . As per ARINC 653, airborne OS subsystems are divided The LLVM project additionally contains a large set of into isolated dedicated sections called partitions, which run dynamic instrumentation tools. Most of them were originally cyclically following a predefined schedule. Each partition developed by Google Sanitizers [7] project, and while they houses one or more application process, varying in durability, require runtime support from the target platform, this runtime period, priority, and current state. Inter partition communica- can be written in C or C++, and all the checks necessary are tion is executed through ARINC 653 ports in the form of a automatically inserted by the compiler, so they do not require FIFO queue (queueing messages) or only reading the latest additional assembly usage. Among the currently supported arrived message (sampling messages). If partitions are placed tools are the following: at different processor modules the communication happens • AddressSanitizer – fast memory usage error detection over buses or switched networks like Avionics Full-Duplex tool. Used for buffer overflow errors, memory reuse after Switched Ethernet (AFDX) [10]. free, and so on; DO-178C standard, which regulates software development • MemorySanitizer – uninitialised memory usage error in civil aviation domain, defines a number of requirements. detection tool; It covers all the processes including planning, development, • UndefinedBehaviorSanitizer – undefined behaviour detec- verification, configuration management, quality assurance, and tion tool. Used for locating the use of unaligned pointers, certification. The set of requirements depends on the software severity level that ranges from level A (failure results in catas- meant to provide the necessary APIs and communicate with trophic consequences and loss of an aircraft) to level D (failure the kernel, and application software provided by various results in minor discomfort for passengers and crew) [11]. partners participating in the project. The following APIs were According to the DO-178C, development of any critical soft- implemented or were in progress of being supported for ware starts from system level requirements. Afterwards high- application software: level software requirements are described and software ar- • ARINC 653; chitecture defines decomposition to software subcomponents, • C Standard Library (limited subset); which get low-level requirements. Later onwards the source • OpenGL SC 2.0; code is developed, requirements-based unit and integration • Embedded C++; tests are written and executed, structural code coverage is • Ada Standard Library (limited subset). measured and analysed. Moreover, at each development step Configuration Control requires that any modification in the IV. DYNAMIC INSTRUMENTATION VALUE first class development artifacts (like requirements and code) Among the implemented measures of the secure develop- has to be justified and logged, which results in a repetition ment lifecycle JetOS already has APEX conformance tests, of all the verification activities. That makes the development structural code coverage collection, unit tests for internal process quite costly, especially if many repeated modifications functions, static analysis, and a number of side tests for are required. the general-purpose library interfaces like C standard library. Due to the aforementioned specialties, it is advisable to Adding the support of dynamic instrumentation was a logical approach the development of operating systems of this class in step forward, but the choice of LLVM was not unbiased. two stages. At the first stage, a working prototype is created JetOS code is written in a portable manner without relying on and used to form and implement the required functionality. compiler specifics, needs to target a wide range of architectures The process permits testing multiple solutions to particular and processors, was buildable with GCC, and relied on LLVM problems and helps to decide on the component development static analysis tools, and most importantly was at considerably within the certification package. At the second stage, high- early development stage. level requirements, architecture and design documentation, There are two main kinds of value provided by error low-level requirements, and of the production detection techniques based on dynamic instrumentation: version are developed in complete compliance with the cer- tification process on top of the prototyping experience. This • Reducing the debugging efforts by exposition of the place method allows to reduce the number of code modifications, where the error happens in comparison to the place where increases the development efficiency, and lowers the costs. a consequent fault became visible. At the time dynamic instrumentation was considered, JetOS • Detection of latent errors that do not manifest themselves was in prototype stage built on top of POK [12] operating in the tested conditions and configurations, but can be system. The size of the codebase was around 40000 LOC revealed in slightly altered environment or different pre- written in a subset of freestanding C99 with around 15000 conditions. LOC comprising the kernel code. The prototype was meant to For the first case the value comes from the ability of the be portable, and supported multiple architectures including: tools to propagate the information of control and data flows to • PowerPC 32-bit (e500mc, e500v2); later stages of program execution. For instance, uninitialised • ARMv7 (Cortex-A7, Cortex-A9); pointer cannot be strictly considered as an error until it actually • MIPS (MIPS32r1); is dereferenced, but even then the results of this operation are • X86 (i486-compatible). not guaranteed to be instantly visible for the . A tool that is able to track and find the origin of a sequence The buildsystem was already adopted to use a GCC-based of unobvious memory corruptions or some other events may toolchain, and suggested the possible use of certified back- seriously increase the debugging speed. ends in the future. All kinds of user-configurable compiler To illustrate the benefits of the second kind, let us give optimisations were prohibited, as well as compiler extensions a generic example based on the code cited in Listing 1. for maximum compatibility with non-GCC , like On most platforms this code will not cause an abnormal formally verified COMPCERT [13]. There are two supported termination or signal any problems, despite the presence of configurations of the codebase: an undefined behaviour due to buffer overflow. If the buffer • Onboard — the code intended to be executed on board size was odd, some implementations would not even require of an aircraft, subject to formal inspection and later buffer_prev or buffer_next, because the compiler certification, part of the certification package; could allocate the needed space implicitly while complying • Ground — the code not executed on board of an aircraft, with the alignment requirements. Dynamic instrumentation is used for the development and debugging of Onboard capable of detecting these and other ‘quiet’ issues, which code, prototyping, training the staff, instrumentation, under certain conditions may lead to severe consequences. telemetry, and other needs. That said, dynamic instrumentation does not provide a com- The userspace environment is comprised of system code, plete guarantee of code correctness, and in most cases it only void test(void) { were detected during testing even with AddressSanitizer char buffer_prev[16]; enabled. While there is no absolute assurance of error char buffer[16]; detection during testing in avionics as well, but more char buffer_next[16]; thorough test coverage reduces the value of the SafeS- size_t sz = sizeof(buffer); tack especially taking into account additional CPU and printf("Local buffers %p %p %p\n", verification overhead coming with it. buffer_prev, buffer, buffer_next); • Control Flow Integrity is not beneficial, since it provides *((volatile char *)buffer - 1) = 1; C++ oriented checks, and C++ language is not common *((volatile char *)buffer + sz) = 1; in onboard RTOS applications. } Other tools do not contradict the environment prerequisites, Listing 1. Generic buffer overflow example but have varying benefits. In JetOS our primary target was to provide the necessary tools to help the developers of appli- cation software. Taking the available resources we decided to helps to detect problems with memory usage, synchronisation focus on AddressSanitizer, MemorySanitizer, and Undefined- primitives, performing calculations etc., which could otherwise BehaviorSanitizer as our primary goals, and libFuzzer and lead to a number of software errors if violated. Dynamic ThreadSanitizer as our secondary goals. Once implementing instrumentation in combination with other means has helped to them in userspace, we ported them to the kernel for the uncover a substantial amount of previously undetected errors additional use. The reasons behind the decision were that the in existing open source projects [14] [15] and has helped first three tools complement each other, and are often used to prevent the occurrence of new ones, thus proving itself together accompanied by the fuzzing, which could be initially efficient. substituted by a large set of tests with decent coverage. There are certain types of errors irrelevant to JetOS code. In general case adopting LLVM dynamic instrumentation For example, memory cannot be reused after deallocation as support consists of two parts: there is no way to deallocate memory in JetOS except for areas • Compiler side support with instrumented code generation; solely managed by applications. However, the other types of • Target platform side support providing the necessary errors may still happen. library API and other interfaces necessary for the tool Dynamic instrumentation could be useful to detect errors in functioning. JetOS during the both phases of its development. In LLVM each sanitizer has its own scope of supported 1) The first stage of prototyping and porting components; architectures and target platforms. Even though, provided a 2) The later stage of production code development. functional runtime library implementation, there may be no The first stage has a lot in common with general purpose technical limitations to run MemorySanitizer on PowerPC software. But as far as productivity of error detection based bare metal, Clang frontend may not allow emitting code with on dynamic instrumentation highly depends on thoroughness sanitizer passes. For this reason, it should be decided whether of applied tests, the more tests became available during the a separate target configurable to the needs of a project is to second stage the more possible situations are checked by be created, or a general-purpose target (e.g. Linux) could be instrumented code. used. For JetOS it was possible to rely on stock LLVM and Clang by maintaining GNU ABI compatibility and use Linux V. BRINGING DYNAMIC INSTRUMENTATION SUPPORT target with upstreamed patches unlocking sanitizer support on There are several dynamic instrumentation tools of the all architectures assuming the runtime library is provided. LLVM project and each of them has distinct purpose and There are several approaches to implement target platform specific requirements. Some of the tools are not so useful for support as well. There is LLVM compiler-rt project, which JetOS: offers a reference implementation for each tool written in • LeakSanitizer is architecturally inapplicable for ARINC C++. It supports a large number of general-purpose operating 653 code, as the whole memory configuration is static, systems, notably Linux, macOS, BSD variants, Fuchsia, and and each component owns a specific chunk of mem- Windows. While these implementations do not require C++ ory during the partition lifetime. It is possible to write standard library availability, they still need some C standard dynamic memory management code for execution on library functions and headers, language features like thread- the ground, but in this case there is no reason to use local variables, and a platform specific part providing stack LeakSanitizer to detect memory leaks, as the allocator unwinding, memory manipulation, synchronisation primitives, can have the necessary checks inside. and several others. As an advantage, the reference implementa- • SafeStack targets stack corruption detection in production tion is always up-to-date, and requires few changes to maintain code. It implements a small subset of checks available in once it works. An alternative approach is to take a third-party AddressSanitizer but in a very efficient way. SafeStack runtime or implement it from scratch. is useful for general purpose software where typical Since our main target was instrumenting userspace code, test coverage does not ensure that all possible problems and optional C++ support was already considered for some of the tools, we opted to reuse the reference implementa- which is negligible in general-purpose operating systems but tion where possible. For the tools used in both user and in the case of RTOS may cause the code to go off-schedule kernel space we opted with in-house implementations. The and render software testing impossible. Potential solutions instrumentation runtime dependencies were minimised by in- include local timeout alterations or a global timer delay in tegrating the existing services of JetOS debugging facilities. the entire operating system. In JetOS we had to apply both. Unlike generic software, error discovery rate in life critical In most cases it was sufficient to divide the timer output software is very low. Dynamic instrumentation serves as a by some constant factor, pretending that it goes e.g. twice proof of no conditions for certain error classes under certain slower, but in some places the timeouts still had to be altered circumstances. For this reason, providing extensive debugging locally. The reason for global timer slowdown not working facilities for report generation may not be beneficial. Adopting well enough is because the estimated slowdown caused by the runtime to be connected to the debugger scripts may be instrumentation and mentioned in the docs is usually average sufficient, since it already provides stack unwinding, variable and approximated, while in reality it strongly varies on the printing, and source mapping to help locate the error. code path. All in all, when dynamically instrumenting RTOS Besides automatically generated checks, different tools pro- the reliability of the timing tests has to be given up leaving vide an API, which may be used to implement sanity checks just the failure reproducibility as an important factor. otherwise impossible to do directly in the codebase. Since it Another traditional problem for operating systems of this is not an option to fill safety-critical software sources with class is memory usage, which is allocated statically before numerous conditionally enabled functional macros invoking the start of each partition and cannot be increased after sanitizer checks, we had to worked out several ways of adding that. To resolve this, JetOS uses a mechanism of preliminary the instrumentation intrinsics: memory area designation for each process, based on which • Templated code generation — for the generated sources the needed shadow memory size is calculated and provided to we have the necessary intrinsics right within the template, AddressSanitizer. Shadow memory granularity is one of the enabled when building with sanitizer support. practical sides of AddressSanitizer. It allows to reduce the • Function wrapping — select functions are provided with shadow memory size by mapping multiple origin bytes to one external wrapping, and their calls are redirected to a shadow byte with little to no report quality loss. The default generated proxy, which itself calls the original function. granularity for AddressSanitizer is 8:1, which means 8 origin This is problematic if it requires to maintain two separate bytes are mapped to 8 shadow bits. Since the whole software interfaces and be aware of interface internals, but works package was under our control, we decided to reconsider fairly well for standardised functions. AddressSanitizer memory checking from just heap, registered • Per-function preprocessing — based on a set of rules data variables, and stack to overall memory as a whole, selected source files may be patched with the necessary blacklisting everything but what we are aware of like MMIO intrinsics at designated places prior to compiling with areas, configuration memory blocks, shared memory, etc. In sanitizer support. At this step we plan to automate the our case sparse shadow memory or algorithm changes were process of generating rules based on function specifica- not required, as we had enough hardware resources, but the tions we have written. caveats of working on minimalistic environment are mentioned in other works such as Address Sanitizer on Myraid [17]. A. Implementing AddressSanitizer The general idea behind AddressSanitizer [16] is to map B. Implementing MemorySanitizer conventional memory to a special area called shadow memory, MemorySanitizer [18] is similar to AddressSanitizer but it which contains memory usage status rather than specific targets uninitialised memory usage of heap and stack variables. values. This tool detects errors like out of bounds access, Unlike AddressSanitizer, MemorySanitizer only supports 1:1 unallocated memory access, out of the scope memory usage, memory granularity, which means its shadow size must be stack corruption, as well as other related memory problems. equal to the used memory size. DO-178C Requirements-Based Anytime conventional memory is addressed, the compiler gen- Testing Methods (6.4.3 [2]) specifies a number of objectives erates a check of the corresponding area of shadow memory, which are also applicable to MemorySanitizer related to vari- and in the event of attempted access to invalid memory, able initialisation correctness and valid parameter passing. signaled by poisoned shadow memory zones, a fatal exception MemorySanitizer may not be directly compatible with a is raised. Besides the practical benefit of the tool, coverage certified onboard OS. In safety-critical software it is not un- of several DO-178C Requirements-Based Testing Methods common to circumvent variable initialisation issues by always (6.4.3 [2]) objectives is also provided. The testing uncovers initialising every declared variable with a special reserved ini- stack corruption, software partition violations, data corruption, tialisation value, when the actual value cannot be determined and invalid parameter passing. beforehand. It is not allowed to intentionally compare the The main problem with using dynamic instrumentation variable value against this reserved value, assume it to be and AddressSanitizer in particular for analysis of real-time a valid state of a variable, or pass it to external functions, software is timing overhead expenses. The aforementioned but it can be used as a last resort of control to make the tools typically cause a double slowdown of code execution, behaviour deterministic and protect against initialisation errors //!USER_NAME: jet_thread_status believe that sanitizer-aided assertions will serve as a helpful //!PRE: msan_check ( instrument to application software developers on both software &thread_id, sizeof (thread_id)); and requirement levels. //!POST: msan_unpoison ( name, sizeof (max_name_t)); C. Implementing UndefinedBehaviorSanitizer //!POST: msan_unpoison ( UndefinedBehaviorSanitizer [19] is an undefined behaviour entry, sizeof (*entry)); detection tool, which helps to reveal errors such as misaligned //!POST: msan_unpoison ( or null pointer access, integer overflows, array bound viola- status, sizeof (*status)); tions when statically determinable, floating point issues such syscall_declare ( as division by zero and cast overflows, _Bool or enum range jet_syscall_thread_status_t, violations, integer truncation, etc. jet_thread_get_status, While the simplest to support, UndefinedBehaviorSanitizer jet_thread_id_t, thread_id, is one of the most powerful checkers of the toolset. It max_name_t, name, does not require special features like shadow memory, and void**, entry, currently three separate publicly available implementations jet_thread_status_t*, status) exist: reference, Linux Kernel, NetBSD. In JetOS we relied Listing 2. Annotated syscall example on the reference implementation in userspace, and on NetBSD implementation in the kernel. It is discussable how dangerous the errors found can actually be, but for instance, in the prototype we discovered a long-standing bug in the assembly and control flow attacks. Since the variable still has to be code of one of the BSPs, which did not evince itself in any initialised by a correct value regardless of the reserved value way in the past but caused undefined behaviour in C code. presence, we opted to preprocess the sources with an external Nullability checks guided by the _Nonnull keyword can also tool to remove the reserved initialisation value assignments. serve as an enforcement of function requirements similarly to Another way avoiding source modifications could have been AddressSanitizer and MemorySanitizer range checks. to modify the tool itself to account for the default value, but this would have caused various compatibility issues with VI. CONCLUSION uncertified software prototypes, which may known about the Based on our experience with JetOS prototype, we affirm reserved initialisation value, and will lead to the loss of bit- that even though the instrumentation error detection rate may precise error detection. be low, the errors detected could be remarkably hard to Memory returned from an unknown source, such as kernel discover with the other measures. memory through a syscall should be annotated to unpoison By the end of this work, we were able to prove the (mark as valid) output parameters. The example provided in usefulness of general-purpose dynamic instrumentation tools Listing 2 shows an annotated syscall template for later C during the development of ARINC 653 compatible safety- conversion with the checks of input parameter initialisation critical real-time operating system prototype. The benefits of and unpoisoning of the output parameters in case of operation LLVM sanitizers in prototyped and ported components are success. similar to those of non-specific software including early stage The same is being done in JetOS, not just to syscalls, but error detection as well as time and cost reduction. Furthermore, other functions based on the formally defined requirements with almost no additional work, these tools can also be and serving for contract enforcement as mentioned previ- used for objective enforcement and contract checking of the ously. One of the issues we had to workaround when using certified code. Dynamic instrumentation could be viewed as MemorySanitizer was providing annotations to structure types automatic oracles that detect certain classes of errors during with padding. Structure padding may not be initialised and test execution and a testing method providing the guarantees can cause false positives. Since the compiler is aware of the of certain class error absence on the path, which in conjunction underlying type, we believe it should be possible to provide with high coverage, serves as a solid proof that all the other an API that will not require writing assertions field by field. measures taken function correctly. During the process of adding the checks we were able In the continuation of our work we foresee several directions to identify select issues in the examples and test suite. For to consider. With AddressSanitizer, MemorySanitizer, and Un- instance, one of the checks exposed a change in the 4th revision definedBehaviorSanitizer already proven to be effective over of the 1st part of ARINC 653 specification that was not the existing featureset, the works to expand their functionality reflected in the prototype. Earlier revisions of the standard involving upstream code modifications and downstream anno- permitted GET_MY_ID to return INVALID_MODE for the tations can now be considered. We also plan to find the use of main process, since it had no ID assigned, while the latest more tools. For instance, fuzzing or symbolic-execution based revision defined MAIN_PROCESS_ID for this purpose. While fuzzing could quickly expand the coverage area when the test the complaint is not fair, as the test suite and prototype suite is not yet complete, which is generally useful for the standard revisions were not fully coordinated, it makes us prototyped components or testing kernelspace isolation. Unlike sanitizers, which cause undesired but measurable slowdown, [4] Mallachiev K.M., Pakulin N.V., Khoroshilov A.V. Design and architec- fuzzing is an entirely different domain and may be a lot more ture of real-time operating system. Trudy ISP RAN/Proc. ISP RAS, vol. 28, issue 2, 2016, pp. 181-192. DOI: 10.15514/ISPRAS-2016-28(2)-12. complex to support in a real-time operating system. However, [5] Julian Seward, Nicholas Nethercote. we suppose that even with a well-written test suite fuzzing Using Valgrind to detect undefined value errors with bit-precision. backed with sanitizer instrumentation may uncover new code Proceeding ATEC ’05 Proceedings of the annual conference on USENIX Annual Technical Conference. Anaheim, CA — April 10 - paths or different behaviour of the old paths, and further 15, 2005. pp. 17-30 research of the topic is worth the effort. The primary fuzzing [6] Chris Lattner. LLVM: An Infrastructure for Multi-Stage Optimization. targets could be AFDX network, device communication, and Dept., University of Illinois at Urbana-Champaign, Dec. 2002. system calls. Regarding the AFDX network used for inter- [7] Google Sanitizers Project. https://github.com/google/sanitizers/wiki partition communication, at present the target partition has [8] ARINC Industry Activities. ARINC 653P1. Airlines Electronic Engi- to determine the validity of transmitted data based on the neering Committee (AEEC), 2015-08-21. 285 p. [9] ARINC Industry Activities. ARINC 651. Design Guidance for Integrated message contents, however, the source partition already has Modular Avionics. Airlines Electronic Engineering Committee (AEEC), parts of this information from the sanitizer runtime. It verifies 1991 the properties like initialisation of the transmitted data and [10] ARINC Industry Activities. ARINC 664 P7. Avionics Full-Duplex Switched Ethernet Network, 2009-09-23, 150 p. enforces them prior to sending. Whether or not the possibility [11] Jos´e Andr´es Jim´enez, Jos´eAmelio Medina Merodio, Luis Fern´andez to transmit supplemental information about the contents of the Sanz. Checklists for compliance to DO-178C and DO-278A Standards. message would be beneficial is also questionable. Computer Standards and Interfaces. Volume 52 Edition C, 2017-05. pp. 41-50. Overhead induced by dynamic instrumentation leads to [12] POK, a real-time kernel for secure embedded systems. issues with real-time scheduling. We overcome it by intro- https://pok-kernel.github.io/about/ ducing timer slowdown option, but the problem of estimation [13] Xavier Leroy. A formally verified compiler back-end. 2009. inria- 00360768v1. https://hal.inria.fr/inria-00360768v1/document of timing overhead and making it deterministic is an open [14] Konstantin Serebryany, Derek Bruening, Alexander Potapenko, question for further research. Dmitry Vyukov. AddressSanitizer: A Fast Address Sanity Checker. USENIX ATC’12 Proceedings of the 2012 USENIX ACKNOWLEDGEMENTS conference on Annual Technical Conference. pp. 28-28 https://www.usenix.org/system/files/conference/atc12/atc12-final39.pdf This study is supported by RFBR grant #16-01-00356. [15] Andrey Konovalov, Dmitry Vyukov. KernelAddressSanitizer (KASan) a fast memory error detectorfor the Linux kernel. REFERENCES LinuxCon North America 2015. 2015-07-18. [16] The LLVM Project. AddressSanitizer Documentation. [1] GOST R 56939-2016. Information protection. Development of secure https://clang.llvm.org/docs/AddressSanitizer.html software. General requirements. Introduced 2016-06-01. Standartinform. [17] Walter Lee. Address Sanitizer on Myriad. 20 p. [18] The LLVM Project. MemorySanitizer Documentation. [2] RTCA/DO-178C. Software Considerations in Airborne Systems and https://clang.llvm.org/docs/MemorySanitizer.html Equipment Certifications. RTCA/EUROCAE. 2012 [19] The LLVM Project. UndefinedBehaviorSanitizer Documentation. [3] Jones, C. Estimating Software Costs: Bringing Realism to Estimating. http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html McGraw-Hill. 2007.