infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
830_security.c File Reference

A test suite for security hardening and vulnerability prevention. More...

#include "common/double_tap.h"
#include "common/infix_internals.h"
#include <infix/infix.h>
#include <limits.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
Include dependency graph for 830_security.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

int dummy_target_func (int a)
 
void dummy_handler_func (void)
 
 subtest ("Guard pages prevent use-after-free")
 
 subtest ("Writing to a hardened reverse trampoline context causes a crash")
 
 subtest ("API hardening against integer overflows")
 
 subtest ("POSIX hardened allocator (shm_open)")
 

Variables

 TEST
 

Detailed Description

A test suite for security hardening and vulnerability prevention.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

This suite consolidates several tests to verify the security-related features and hardening of the infix library. It is designed to be run on all platforms, with specific tests activating based on the target OS and compiler.

The key areas verified are:

  1. Use-After-Free Prevention: Confirms that attempting to call a freed trampoline results in a safe, immediate crash (e.g., SIGSEGV or Access Violation) due to the guard page mechanism in infix_executable_free. This is tested for both forward and reverse trampolines.
  2. Read-Only Context Protection: Verifies that the context for a reverse trampoline is made read-only after creation. Attempting to write to this hardened memory should cause a crash, preventing exploits that might modify callback behavior at runtime.
  3. API Hardening (Integer Overflows): Ensures that the infix_type_create_* functions are resilient to integer overflow attacks. It passes maliciously crafted size, offset, or element counts that would cause size_t to wrap around, and confirms that the API rejects these inputs gracefully.
  4. POSIX Hardened Allocator: A simple check to confirm that the dual-mapping shm_open memory allocator, used on hardened Linux/BSD systems, functions correctly.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ dummy_handler_func()

void dummy_handler_func ( void  )

◆ dummy_target_func()

int dummy_target_func ( int  a)

◆ subtest() [1/4]

subtest ( "API hardening against integer overflows"  )

◆ subtest() [2/4]

subtest ( "Guard pages prevent use-after-free"  )

◆ subtest() [3/4]

subtest ( "POSIX hardened allocator (shm_open)"  )

◆ subtest() [4/4]

subtest ( "Writing to a hardened reverse trampoline context causes a crash"  )

Variable Documentation

◆ TEST

TEST