From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF361CDFAC; Sun, 7 Sep 2025 20:10:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757275838; cv=none; b=Gqh0dr1wKxOEPWRBrNjlJ3PfJBdYJMva8YEKflf8ajoe3SZKI5ZaOZWtqoQPc0ZrvVszCpNS28iYTHzkIqj0U57onLt020NWqyAoYudqz6BpmgRS1Ngf3mHbyInk9HL3ZJmF+qFBBKVTUDZwK58gP4yYOb+AochZ7Y3u0Gbh04I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757275838; c=relaxed/simple; bh=/Xg+KOCSD0by8C9zqiak6rOpKs8WoVuacsHM0xZl7Zs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RPHVySOJc5IrbtuU1XjYjDz4Bb0P88k7AGCfGkr70j9Pe/aD7rBy+Pm3hvrxnKxpZA+Riv9/K2a7dQgddDLVPUyGzSay4Z5x/p+7cSzl9gEauovS2j+2EGVhUPvLc/68QvEODtwsiYnWqNgQp/2z4f0ZZJwMGs9UeVAwrNa8Vmw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=H+LQrqEu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="H+LQrqEu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1AB7C4CEF8; Sun, 7 Sep 2025 20:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757275838; bh=/Xg+KOCSD0by8C9zqiak6rOpKs8WoVuacsHM0xZl7Zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H+LQrqEu/bNIc5DujrP3ii9rstCwRqFJqRKiGZOixSHhQr6B0NCTh8NAmmsL7RGbN qOfjCmtgR1+sU7yxtWz4NXK5woF8w+plKgJlKSqF8aCgllvT9a91k5QKYkmbbUIvGL pEK9XVuMGa6Vc5F+WbeHn2m3zVxZW7LuWYTJUy4Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Li Qiong , Harry Yoo , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Sasha Levin Subject: [PATCH 5.4 26/45] mm/slub: avoid accessing metadata when pointer is invalid in object_err() Date: Sun, 7 Sep 2025 21:58:12 +0200 Message-ID: <20250907195601.723158870@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250907195600.953058118@linuxfoundation.org> References: <20250907195600.953058118@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Li Qiong [ Upstream commit b4efccec8d06ceb10a7d34d7b1c449c569d53770 ] object_err() reports details of an object for further debugging, such as the freelist pointer, redzone, etc. However, if the pointer is invalid, attempting to access object metadata can lead to a crash since it does not point to a valid object. One known path to the crash is when alloc_consistency_checks() determines the pointer to the allocated object is invalid because of a freelist corruption, and calls object_err() to report it. The debug code should report and handle the corruption gracefully and not crash in the process. In case the pointer is NULL or check_valid_pointer() returns false for the pointer, only print the pointer value and skip accessing metadata. Fixes: 81819f0fc828 ("SLUB core") Cc: Signed-off-by: Li Qiong Reviewed-by: Harry Yoo Reviewed-by: Matthew Wilcox (Oracle) Signed-off-by: Vlastimil Babka [ struct page + print_page_info() ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- mm/slub.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/mm/slub.c +++ b/mm/slub.c @@ -719,7 +719,12 @@ void object_err(struct kmem_cache *s, st u8 *object, char *reason) { slab_bug(s, "%s", reason); - print_trailer(s, page, object); + if (!object || !check_valid_pointer(s, page, object)) { + print_page_info(page); + pr_err("Invalid pointer 0x%p\n", object); + } else { + print_trailer(s, page, object); + } } static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page,