Skip to content

Improve freelist walking#12

Open
ksen-lin wants to merge 3 commits intonccgroup:mainfrom
ksen-lin:fix-freelist-walking
Open

Improve freelist walking#12
ksen-lin wants to merge 3 commits intonccgroup:mainfrom
ksen-lin:fix-freelist-walking

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
Collaborator

@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?

else:
t = "F"
address = "{:#x}".format(self.address)
if self.address < 0xffff800000000000:
Copy link
Collaborator

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