Skip to content

Improve freelist walking #12

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ksen-lin
Copy link

@ksen-lin ksen-lin commented Mar 2, 2025

Hi!
I came across the following situations that libslub couldn´t handle:

  1. a loop in a freelist led to libslub hanging with ^C being the only help
  2. an address in a freelist that couldn't be dereferenced (eg unmapped) resulted in an exception

For the first one i've added a limit that depends on a maximum capacity of a particular slub. For the second i've added a try-except, and also an explicit check to point non-kernel addresses.

With my fixes it looks like this:

  1. circular (2 elements) freelist
    dups
  2. invalid next
    next

Looking forward to comments/suggestions if you have any. Thanks!

ksen-lin added 3 commits March 1, 2025 12:19
libslub got stuck on freelists that contained cycles. Fix by walking no more than `max_objs_per_slab` steps.
Copy link
Contributor

@fidgetingbits fidgetingbits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Seems sane aside from the one thing about the hardcoded address. Let me know if you don't have time to fix it and I'll take a stab at it at some point.

Out of curiosity did you run into this bug while exploiting something that corrupted something in the freelist or was it somehow a legitimate state?

@@ -80,6 +80,9 @@ def to_string(self, name="", verbose=0, use_cache=False, indent=0, colorize_func
else:
t = "F"
address = "{:#x}".format(self.address)
if self.address < 0xffff800000000000:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't currently restrict use of this library to x64 anywhere, so I would say this should be abstracted and per-architecture, otherwise this would break it on anything but x64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants