]> git.ipfire.org Git - thirdparty/linux.git/commit
slub: Handle freelist cycle in on_freelist()
authorLilith Gkini <lilithpgkini@gmail.com>
Wed, 5 Mar 2025 15:48:39 +0000 (17:48 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Thu, 6 Mar 2025 08:39:53 +0000 (09:39 +0100)
commit747e2cf137f44058a093d3226bf83974d9d117e7
tree5480147cf70d70167377908a67d18b53293df109
parent939c5de3c70d145d7388db1b04d75cda79297c23
slub: Handle freelist cycle in on_freelist()

The on_freelist() doesn't have a way to handle the edgecase of having a
full freelist that doesn't end in NULL and instead has another valid
pointer in the slab as a result of a Use-After-Free or anything similar.

This case won't get caught by check_valid_pointer() and it will result in
nr incrementing to `slab->objects + 1`, corrupting the slab->inuse entry
later in the code by setting it to -1.

Add an if check to detect that case, report it and handle the freelist
and slab appropriately, as is the standard process in these situations.

Furthermore change the return type of the function from int to bool as
per coding style guidelines.

Also move the `break;` line inside the `if (object) {` to make it more
obvious that the code breaks the while loop in that branch.

Signed-off-by: Lilith Persefoni Gkini <lilithgkini@proton.me>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c