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 871531A0BFD; Sun, 7 Sep 2025 20:34:31 +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=1757277271; cv=none; b=Ed8BB0Uq8XegVxHvgELBu0kLR6/QxpR0JtFoAtWvuIabF7dWmR12+EK4ho5OwrMmuMnIdzrb6ebl8ATSeyv/d3QPdOWsc1yaTwbkxXhgMDRjvQCFzTQFKTdmkhDY24zHRMpD9gB7B18hDhE6xHFYriD7fcRaRJm489Y9hmN1ZJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757277271; c=relaxed/simple; bh=DzdOHpCN1i+PlqXaiGPMkDDUYLnzP7ACjLApxuc8tHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=niWXtwdgjMmpRgxi6FApLakl3JWBPCjH0W/KZbCuZj0GvnRoNbzV2S3QBJKH0fsqpbGNPVd8YP2ePmHCl32X0Lotc+yQTCN3iBLdD6LqTa+nvB1Cm9VN/RUzBz97a4LzQs/Kwy4hC+YBgKmhKjr0PvpXGi0LbdFMeqaIbukqRAY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LzAliNYQ; 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="LzAliNYQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB28EC4CEF0; Sun, 7 Sep 2025 20:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757277271; bh=DzdOHpCN1i+PlqXaiGPMkDDUYLnzP7ACjLApxuc8tHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LzAliNYQNM7UZbLxm6uxLOZiV7OCY5cYXksn7yyWkb62QYmvNSuCp1SS2e6ElonTM 2koZ3SffkvLim/DUdQG76aTKevj/aOE997T6J93rsjn7WPMkU/7iwv8PURdCNUooyT XFuyJQFbscDTc7siWYHj86C1Kkg/2bc+YGeK3XHg= 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 6.12 140/175] mm/slub: avoid accessing metadata when pointer is invalid in object_err() Date: Sun, 7 Sep 2025 21:58:55 +0200 Message-ID: <20250907195618.164031691@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250907195614.892725141@linuxfoundation.org> References: <20250907195614.892725141@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 6.12-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 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 @@ -1113,7 +1113,12 @@ static void object_err(struct kmem_cache return; slab_bug(s, reason); - print_trailer(s, slab, object); + if (!object || !check_valid_pointer(s, slab, object)) { + print_slab_info(slab); + pr_err("Invalid pointer 0x%p\n", object); + } else { + print_trailer(s, slab, object); + } add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); WARN_ON(1);