[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z8Sc4DEIVs-lDV1J@Arch>
Date: Sun, 2 Mar 2025 20:01:04 +0200
From: Lilith Persefoni Gkini <lilithpgkini@...il.com>
To: Christoph Lameter <cl@...ux.com>, Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Vlastimil Babka <vbabka@...e.cz>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Hyeonggon Yoo <42.hyeyoo@...il.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, harry.yoo@...cle.com
Subject: [PATCH] slub: Fix Off-By-One in the While condition in on_freelist()
The on_freelist() uses a while loop to walk through the linked list
freelist of a particular slab until it finds the `search` pattern and
breaks if there is a freepointer in the list that is NULL, or invalid
(fails the check_valid_pointer() check), or the number of objects (nr)
in the freelist is more than `slab->objects + 1`
No valid freelist should have more than slab->objects non NULL pointers,
therefore the while conditional should check until slab->objects amount
of times, not more.
If the `search` pattern is not found in the freelist then the function
should return `fp == search` where fp is the last freepointer from the
while loop.
If the caller of the function was searching for NULL and the freelist is
valid it should return True (1), otherwise False (0).
Signed-off-by: Lilith Persefoni Gkini <lilithgkini@...ton.me>
---
mm/slub.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 1f50129dcfb3..0d3dd429b095 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1435,7 +1435,7 @@ static int on_freelist(struct kmem_cache *s, struct slab *slab, void *search)
int max_objects;
fp = slab->freelist;
- while (fp && nr <= slab->objects) {
+ while (fp && nr < slab->objects) {
if (fp == search)
return 1;
if (!check_valid_pointer(s, slab, fp)) {
@@ -1473,7 +1473,7 @@ static int on_freelist(struct kmem_cache *s, struct slab *slab, void *search)
slab->inuse = slab->objects - nr;
slab_fix(s, "Object count adjusted");
}
- return search == NULL;
+ return fp == search;
}
static void trace(struct kmem_cache *s, struct slab *slab, void *object,
--
2.48.1
Powered by blists - more mailing lists