Skip to content

Commit a302fa0

Browse files
committed
Fix no_randomize_memory call test: check personality flag, not addresses
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 2725331 commit a302fa0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tests/test_integration.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,16 +1475,22 @@ def test_no_randomize_memory_deterministic_addresses(self):
14751475
assert r1.stdout.strip() == r2.stdout.strip()
14761476

14771477
def test_no_randomize_memory_call(self):
1478-
"""no_randomize_memory works with Sandbox.call."""
1479-
def get_addr():
1480-
import ctypes
1481-
return ctypes.addressof(ctypes.c_int())
1478+
"""no_randomize_memory sets personality in Sandbox.call.
1479+
1480+
personality(ADDR_NO_RANDOMIZE) takes effect at exec, not fork.
1481+
Sandbox.call has no exec, so we verify the flag is set rather
1482+
than comparing addresses.
1483+
"""
1484+
def check_personality():
1485+
import ctypes, ctypes.util
1486+
libc = ctypes.CDLL(ctypes.util.find_library("c"))
1487+
ADDR_NO_RANDOMIZE = 0x0040000
1488+
return bool(libc.personality(0xffffffff) & ADDR_NO_RANDOMIZE)
14821489

14831490
policy = Policy(no_randomize_memory=True)
1484-
r1 = Sandbox(policy).call(get_addr)
1485-
r2 = Sandbox(policy).call(get_addr)
1486-
assert r1.success and r2.success
1487-
assert r1.value == r2.value
1491+
result = Sandbox(policy).call(check_personality)
1492+
assert result.success, f"Failed: {result.error}"
1493+
assert result.value is True
14881494

14891495
def test_default_has_randomized_addresses(self):
14901496
"""Without no_randomize_memory, ASLR is active (addresses vary)."""

0 commit comments

Comments
 (0)