Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #33

Merged
merged 85 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
605b78b
Add stub libcgc_win
krx Jan 6, 2017
28750fb
Convert math/setjmp/longjmp to MASM
krx Jan 6, 2017
46f5fa1
Update CMakeLists for windows build
krx Jan 6, 2017
6b45264
Refactor cgc_scalbln
krx Jan 6, 2017
c2b5d18
Rename math file
krx Jan 6, 2017
154685d
Fix math functions not being exported
krx Jan 6, 2017
5812c63
Update CMakeLists for building libpov
krx Jan 6, 2017
f143fd6
Update compile flags for cbs
krx Jan 6, 2017
60a7c70
Ignore warning flags when generating CMakeLists
krx Jan 6, 2017
06ef08e
Implement allocate/deallocate
krx Jan 6, 2017
ef3dee5
Implement flag page initialization
krx Jan 6, 2017
b9904c8
Use pipes instead of socketpairs for IPC
krx Jan 12, 2017
9211086
Fix incorrect IPC usage in BIRC
krx Jan 12, 2017
687d7b8
Misc cleanup
krx Jan 12, 2017
0bfcb00
Fix incorrect IPC usage in LulzChat
krx Jan 13, 2017
eeb639e
Fix incorrect IPC usage in commerce_webscale
krx Jan 13, 2017
b193b5a
Restructure server in preparation for AJL
krx Jan 31, 2017
e9b5059
Add AppJailLauncher
krx Jan 31, 2017
7330e2b
Setup launching AJL as the server
krx Feb 1, 2017
7533626
Fix stdout inheritance
krx Feb 1, 2017
304b3e7
Reorganize/cleanup server
krx Feb 1, 2017
559f436
Delete unneeded files
krx Feb 1, 2017
5df3511
Use sys.executable when running other files
krx Feb 1, 2017
701c098
Implement transmit/receive
krx Feb 1, 2017
b0098e9
Fix CMake output directory
krx Feb 3, 2017
d9b59aa
Add basic windows build script
krx Feb 3, 2017
083d4c9
Some tester changes for compatibility
krx Feb 3, 2017
a77de32
Fix VirtualFree param in deallocate
krx Feb 3, 2017
f45429f
Fix flag page allocation
krx Feb 3, 2017
4cb6fe7
Update .travis.yml
krx Feb 3, 2017
9cc0251
Copy over dlls post-build
krx Feb 7, 2017
bc96228
Reorganize tools
krx Mar 13, 2017
c0d1264
Add thread-based timeout
krx Mar 13, 2017
4715eb5
Use the new timeout everywhere
krx Mar 13, 2017
407df88
Rename cgc tools, misc compatibility fixes
krx Mar 28, 2017
39fdaec
Update testing tools to syncronize with pipes
krx Mar 28, 2017
6299764
Fix receive bug when reading a single newline
krx Mar 28, 2017
4b0e9d4
Fix server termination after timeout
krx Mar 28, 2017
62a9304
Catch exceptions when terminating on windows
krx Mar 28, 2017
d22128f
Fix pipe syncing on linux/OS X
krx Apr 3, 2017
1c864e6
Update patcher to rename includes
krx Apr 13, 2017
baf892b
Fix includes for building cfe povs
krx Apr 13, 2017
e16e8b7
Rename all symbols in include/
krx Apr 13, 2017
69a57d0
Fix building wrong cb number in multibin challenges
krx May 11, 2017
041eac4
Remove patching from build process
krx May 18, 2017
839d300
Use signed types in receive/transmit
krx May 18, 2017
ac3291f
Remove pyyaml requirement
krx May 18, 2017
59f05f4
Rename processed/original-challenges -> challenges
krx May 18, 2017
3002456
Remove nostdinc
krx May 18, 2017
67d2d4e
Update .gitignore
krx May 18, 2017
37f250c
Remove patcher info from README
krx May 18, 2017
2d052e5
Add all renamed challenges, delete old sources
krx May 18, 2017
9a36883
Merge pull request #27 from trailofbits/clang_rename
krx May 18, 2017
f9f2d5e
Include stdarg.h in libpov
krx May 18, 2017
e839540
Update gitignore
krx May 25, 2017
3073f36
Include stdarg.h instead of defining new types
krx May 25, 2017
94f244b
Save all built binaries in the build dir
krx May 26, 2017
3f63405
Update tester for new directory structure
krx May 26, 2017
9d93ace
Add ability to exclude challenges from building
krx May 26, 2017
b921ef0
Update README
krx May 26, 2017
64542c3
Merge pull request #28 from trailofbits/change_bin_location
krx May 26, 2017
9b86f81
Exclude challenges using VLA
krx May 26, 2017
bc5ea8d
Fix definitions of math symbols in libcgc
krx Jun 5, 2017
b17cb1e
Fix stdarg.h guards
krx Jun 5, 2017
24cac3b
Disable including headers globally
krx Jun 5, 2017
5c11337
Add support for building with clang-cl
krx Jun 5, 2017
b452d67
Exclude more challenges that use VLA
krx Jun 5, 2017
d6f3b6a
Workaround most of the builtin issues
krx Jun 5, 2017
a5b17b5
First attempt at setting up appveyor
krx Jun 5, 2017
340e729
Update appveyor
krx Jun 5, 2017
d17f713
Add fdwait implementation
krx Jun 22, 2017
de38869
Change signature of main to something more standard
moyix Jun 27, 2017
63a5a89
Add two more main()s that were missed
moyix Jun 27, 2017
2b2a71d
Test only built challenges when using --all
krx Jul 7, 2017
a61b4e6
Remove server and AppJailLauncher
krx Jul 7, 2017
f504bb8
Refactor cb-test/cb-replay to run without a server
krx Jul 7, 2017
03346c1
Fix renaming typos in Material_Temperature_Simulation
krx Jul 7, 2017
e5e6540
Add ability to dump register values on windows
krx Jul 10, 2017
2f717b4
Build with clang by default
krx Jul 12, 2017
cca9355
Refactor cb-replay-pov to run without a server
krx Jul 12, 2017
8dc7804
Misc cleanup
krx Jul 12, 2017
a85765c
Correctly launch challenges for multibin support
krx Jul 12, 2017
b91255f
Setup IPC pipes correctly on Windows
krx Jul 13, 2017
9deaea5
Update README
krx Jul 13, 2017
7f650bf
Update poll generator post-rebase
krx Jul 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Setup IPC pipes correctly on Windows
  • Loading branch information
krx committed Jul 13, 2017
commit b91255fb5d75dde82183d447318c854d01a3cc42
51 changes: 49 additions & 2 deletions include/libcgc_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <fcntl.h>

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
Expand Down Expand Up @@ -207,11 +208,57 @@ static void cgc_initialize_flag_page(void) {
cgc_aes_get_bytes(cgc_internal_prng, PAGE_SIZE, flag_addr);
}

/**
* Helper to parse values out of the env
* All values are expected to be positive + nonzero
* Returns 0 on any error
*/
unsigned int cgc_getenv_uint(char *varname) {
char *val = getenv(varname);
if (val) {
int res = atoi(val);
if (res > 0) return res;
}
return 0;
}

// Up to 2 digits, should really never go past ~20 anyway
#define MAX_IPC_PIPES 99
#define MAX_NAME_LEN 8 // "PIPE_##\0"

/**
* Initialize all the pipes necessary for IPC
*/
void cgc_init_ipc_pipes() {
char name_buf[MAX_NAME_LEN] = {0};
HANDLE pipe_hndl = NULL;
int pipe_fd = 0;

// Get the number of pipes we need to set up
int numpipes = cgc_getenv_uint("PIPE_COUNT");
if (numpipes > MAX_IPC_PIPES) numpipes = MAX_IPC_PIPES;

// Open all pipe HANDLEs in the correct fds
for (unsigned int i = 0; i < numpipes; ++i) {
// Get the next HANDLE from the env
snprintf(name_buf, MAX_NAME_LEN, "PIPE_%d", i);
pipe_hndl = (HANDLE) cgc_getenv_uint(name_buf);

if (pipe_hndl) {
// Assign the pipe to the correct fd
pipe_fd = _open_osfhandle(pipe_hndl, O_RDONLY | O_APPEND);
if (pipe_fd != 3 + i) { // First pipe is at fd 3
_dup2(pipe_fd, 3 + i);
}
}
}
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_ATTACH) {
// __attribute__((constructor))
if (fdwReason == DLL_PROCESS_ATTACH) { // __attribute__((constructor))
setvbuf(stdout, NULL, _IONBF, 0); // We *may* not need this, not sure yet
cgc_initialize_flag_page();
cgc_init_ipc_pipes();
}
return TRUE;
}
26 changes: 20 additions & 6 deletions tools/challenge_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def run(challenges, timeout, seed, logfunc):
Returns:
(list): all processes that were started
"""
cb_env = {'seed': seed} # Environment variables for all challenges

# This is the first fd after all of the challenges
last_fd = 2 * len(challenges) + 3

Expand Down Expand Up @@ -58,9 +60,21 @@ def run(challenges, timeout, seed, logfunc):
# Done with the temporary dup
os.close(rpipe_tmp)

# Start all challenges
cb_env = {'seed': seed}
# None of the above file descriptors will actually be inherited on Windows
# Prepare the environment so libcgc can regenerate this setup
# with the inherited HANDLEs
if IS_WINDOWS:
import msvcrt

# Store the number of pipes that need to be set up
numpipes = len(challenges) * 2 # Pipe pair for each
cb_env['PIPE_COUNT'] = str(numpipes)

# Store the HANDLE for each of the pipes
for i in xrange(len(challenges) * 2):
cb_env['PIPE_{}'.format(i)] = str(msvcrt.get_osfhandle(3 + i)) # First pipe is at 3

# Start all challenges
# Launch the main binary first
mainchal, otherchals = challenges[0], challenges[1:]
procs = [sp.Popen(mainchal, env=cb_env, stdin=sp.PIPE,
Expand Down Expand Up @@ -110,18 +124,18 @@ def chal_watcher(paths, procs, timeout, log):
for path, proc in zip(paths, procs):
pid, sig = proc.pid, abs(proc.returncode)
if sig not in [None, 0, signal.SIGTERM]:
log('[DEBUG] pid: {}, sig: {}\n'.format(pid, sig))
log('[DEBUG] pid: {}, sig: {}'.format(pid, sig))

# Attempt to get register values
regs = get_core_dump_regs(path, pid, log)
if regs is not None:
# If a core dump was generated, report this as a crash
# log('Process generated signal (pid: {}, signal: {}) - {}\n'.format(pid, sig, testpath))
log('Process generated signal (pid: {}, signal: {})\n'.format(pid, sig))
log('Process generated signal (pid: {}, signal: {})'.format(pid, sig))

# Report the register states
reg_str = ' '.join(['{}:{}'.format(reg, val) for reg, val in regs.iteritems()])
log('register states - {}\n'.format(reg_str))
log('register states - {}'.format(reg_str))

# Final cleanup
clean_cores(paths, procs)
Expand Down Expand Up @@ -175,7 +189,7 @@ def get_core_dump_regs(path, pid, log):
]

if any(err in dbg_out for err in errs):
log('Core dump not found, are they enabled on your system?\n')
log('Core dump not found, are they enabled on your system?')
return

# Parse out registers/values
Expand Down