From 593b5d384c296f0b02a7466f1cb6f636df7fc55d Mon Sep 17 00:00:00 2001 From: Ammar Faizi Date: Wed, 7 Jul 2021 17:11:25 +0700 Subject: [PATCH] test set-permission: Improve the test case This commit introduces 2 changes: 1) Change "info registers" to "info registers all". This will track more registers and make sure they are not changed due to syscall. 2. Change `gdb_start_silent_cmd` to `gdb_run_cmd`. We don't need to use `gdb_start_silent_cmd` because our `before` commands have already started the process. And we can't see the register before we do `set-permission` command if the process has not been started yet. Therefore, it makes sense not to append `"entry-break"` by calling `gdb_start_silent_cmd`. Before this commit the result in commands will be like this: before = [ # These two do the entry-break job! "starti", "si", "printf \"match_before\\n\"", "info registers all", "printf \"match_before\\n\"", "gef config context.clear_screen False", "gef config context.layout '-code -stack'", # This is unecessary, because we have `starti` and `si`. # We can't reorder it because it is appended inside the # `gdb_start_silent_cmd`. "entry-break" ] cmd = "set-permission $sp" after = [ "printf \"match_after\\n\"", "info registers all", "printf \"match_after\\n\"" ] After this commit: before = [ "gef config context.clear_screen False", "gef config context.layout '-code -stack'", "entry-break", "printf \"match_before\\n\"", "info registers all", "printf \"match_before\\n\"" ] cmd = "set-permission $sp" after = [ "printf \"match_after\\n\"", "info registers all", "printf \"match_after\\n\"" ] Fixes: 5eb3b243bd9797f6f71176419d5981a4edfd1923 ("x86-64: Preserve RCX and R11 when calling mprotect_asm (syscall)") Cc: Grazfather Signed-off-by: Ammar Faizi --- tests/runtests.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/runtests.py b/tests/runtests.py index a46cded2a..a45ea5018 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -430,18 +430,19 @@ def test_cmd_set_permission(self): # Make sure set-permission command doesn't clobber any register before = [ - "starti", - "si", + "gef config context.clear_screen False", + "gef config context.layout '-code -stack'", + "entry-break", "printf \"match_before\\n\"", - "info registers", + "info registers all", "printf \"match_before\\n\"" ] after = [ "printf \"match_after\\n\"", - "info registers", + "info registers all", "printf \"match_after\\n\"" ] - res = gdb_start_silent_cmd("set-permission $sp", before=before, after=after, target=target) + res = gdb_run_cmd("set-permission $sp", before=before, after=after, target=target) regs_before = re.match(r"(?:.*match_before)(.+)(?:match_before.*)", res, flags=re.DOTALL)[1] regs_after = re.match(r"(?:.*match_after)(.+)(?:match_after.*)", res, flags=re.DOTALL)[1] self.assertEqual(regs_before, regs_after)