Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6804677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:29:44+00:00 2026-05-26T19:29:44+00:00

I have a small program that mmaps potentially dangerous executable code (with PROT_EXEC), calls

  • 0

I have a small program that mmaps potentially dangerous executable code (with PROT_EXEC), calls prctl(PR_SET_SECCOMP, 1) and then executes this mmap’d code. This is all well and good, and allows me to “save” the state of the evaluation by sync the mmap’d region to disk, and reload it later (most likely on another machine for load balancing). However, this technique doesn’t always work — because this code might have made changes to the program that are not in the mmap’d region, and this information will be lost.

So what I would like to do, is make absolutely everything (other than this mmap’d region) read-only before calling the code. This way I have a guarantee that the executable code can’t change the state of anything other than the mmap’d region which I can serialize/deserialize at will.

BTW this is Linux on x86_64

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:29:45+00:00Added an answer on May 26, 2026 at 7:29 pm

    Firstly, an observation: There’s nothing that says you have to mmap() to get machine instructions into memory or to save them back to a file. read() and write() can do this too, just note that you should make a writable and executable private mapping for this purpose.

    Obviously you can’t reliably disable writing to the area of the stack that will be calling into the executable code that you’ll load, if it’s to be executed within the same process since this will render the stack unusable. You might work around this by annotation your variables or using assembly.

    Your next option is to fork(). You could exec in the child into a special wrapper executable that allows for minimal damage and introspection by malicious executable code (provides simply load/dump), or you could do the same by having the child modify itself to the same effect. This still isn’t 100% safe.

    Proposal0

    • Create a stand alone binary that is linked against minimal libraries (-nodefaultlibs).
    • After a fork, ptrace(PTRACE_TRACEME) in the child (so that you can read memory contents reliably and do other interventions), and close all handles except that of a pipe (just in stdin for simplicity). exec() into the aforementioned wrapper binary.

    In the wrapper binary:

    • mmap a private region at a known location with write and execute permissions. Alternatively you can statically allocate this region if the size is fixed.
    • Read the contents of the pipe into the region.
    • Close the pipe. Now the process has no open handles.
    • prctl(PR_SET_SECCOMP, 1). Now the only valid system calls are _exit and sigreturn. Since the process can’t raise, sigreturn should have no useful effect.
    • Remove write permissions from the main stack (should be the only stack). Since you have no intention of returning, and will jump immediately afterward, you shouldn’t need to touch the stack again.
    • Jump to the starting location inside the region. Do this using assembly, or create a function pointer and invoke it (if you can get it to work without pushing to the stack). Now you should be executing a region of memory that is the only writable region available. The main stack was protected, and the heap should not be in use due to lack of library support.

    In the parent:

    • Using ptrace or wait, catch erroneous or successful completion.
    • Read the mapped region at the known location via /proc/<pid>/mem or equivalent to file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small server program that accepts connections on a TCP or local
I have a small command line program that uses the Team System API. When
I have a program that creates a small file in the Bin directory for
I have a Java program that runs many small simulations. It runs a genetic
I have a small program <350ish lines of code on 5 forms>. It works
i have a small program that uses 32bit object file, and i wish to
I have a small program that I can compile with GCC and ICC without
Let say I have written a small program that reads file_A and file_B as
I have a small C program to calculate hashes (for hash tables). The code
We have a small .Net program that we sell with individual licenses. The individual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.