Skip to content

Commit

Permalink
test set-permission: Improve the test case
Browse files Browse the repository at this point in the history
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: 5eb3b24 ("x86-64: Preserve RCX and R11 when calling mprotect_asm (syscall)")
Cc: Grazfather <grazfather@gmail.com>
Signed-off-by: Ammar Faizi <ammarfaizi2@gmail.com>
  • Loading branch information
ammarfaizi2 authored and Grazfather committed Jul 7, 2021
1 parent a2b93a7 commit 593b5d3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/runtests.py
Expand Up @@ -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)
Expand Down

0 comments on commit 593b5d3

Please sign in to comment.