From 7b98f0d2c3929b3d961480d9316e9073e9bcc218 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Sat, 10 Dec 2016 23:32:11 -0800 Subject: [PATCH] Ensure child stack passed to clone is 16 byte aligned. --- CHANGELOG.md | 2 ++ src/sched.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd85e1c98..325e779c7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#397](https://github.com/nix-rust/nix/pull/397)) - Fixed an off-by-one bug in `UnixAddr::new_abstract` in `::nix::sys::socket`. ([#429](https://github.com/nix-rust/nix/pull/429)) +- Fixed clone passing a potentially unaligned stack. + ([#490](https://github.com/nix-rust/nix/pull/490)) ## [0.7.0] 2016-09-09 diff --git a/src/sched.rs b/src/sched.rs index 4af332034c..66b4ed4f13 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -114,8 +114,9 @@ pub fn clone(mut cb: CloneCb, let res = unsafe { let combined = flags.bits() | signal.unwrap_or(0); let ptr = stack.as_mut_ptr().offset(stack.len() as isize); + let ptr_aligned = ptr.offset((ptr as usize % 16) as isize * -1); ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32), - ptr as *mut c_void, + ptr_aligned as *mut c_void, combined, &mut cb) };