Giter VIP home page Giter VIP logo

abort_at_exit's Introduction

LD_PRELOAD override to abort program at exit

A LD_PRELOAD override that causes normal process termination to instead result in abnormal process termination through a raised SIGABRT signal via abort(3) (even if SIGABRT is ignored, or is caught by a handler that returns).

The override works by splicing in a "fake main" function to be executed instead of the program main function. The fake_main function registers abort(3) as an atexit(3) handler to be called at normal process termination.

LD_PRELOAD cannot be used to override main directly as it can only override functions in dynamically linked shared libraries whose addresses are determined via the Procedure Linkage Table (PLT). However, main's location is not determined via the PLT, but is statically linked to the executable entry routine at __start which pushes main's address onto the stack, then invokes libc's startup routine, which obtains main's address from the stack.

Instead, the override uses LD_PRELOAD to override libc's startup routine, __libc_start_main, which is normally responsible for calling main and splice in fake_main there. We can't just run our setup code in the overriden __libc_start_main directly because the real __libc_start_main is responsible for setting up the C runtime environment, so we can't rely on standard library functions such as malloc(3) or atexit(3) being available yet.

Building:

make

Usage:

LD_PRELOAD=abort_at_exit.o program

Acknowledgments

Loosely based on libminijailpreload.c by the Chromium OS Authors.

License

Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

abort_at_exit's People

Contributors

thomasnyman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.