From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795057663; b=ygNGQXwb3Avcvs3HFVYXbgY/jfBr5XH9T7C/VsnFC2GEGsFKqUvx3K8Fphshe4Q1aZoY vXOgpQtMx+wWDWcu6SssQwpD561KBghl4ALQGquN7gs04yJIJOrzkiCdCW+uevgB94+pq DoI8IeUrNMqvVTCe5NG+I1tnKHE5LryH+58fJpxW92Tr0OSEPuJ2EWsUQ2z+vXegCiL2w d0bw/AXzheAWt0F65t1AS3y7CorAxj6qzx3wR9tYRqqzmAgNR5iSD+0Zl3/XZyp3bTc2J Ack6xESLGqtj/xaFMPqJC33n8oijVmxLp+UwvMdUPkTGw+zTBV52PDhC11WLDKIv3ww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795057663; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ByKlpNPFWGNJQWYzUS6A6Li2KxVzu9BFGKhqJl7EY4c=; b=vgMEkbaf3gJkfqPge6hwbroxniDzG1Iy1fxEbbaEVQv2ol4BKT43wwNq2uAFYu0avt+H ln32QYy++XV90qTlTHpGvvXsZVcsvUcucoD9c3ypUqVqBPtNMkoiAOL2FAIIXqz16ILtn RJJAKYiAHjpSCH9FlfS2BwQUmGkFnMtub+sqe+ZKZWXV3mxZAY27cq2XdDwyK+dusSvrl YtcwtJ4VewXo4hjSPTA9X11FuZaSNRY2fAXc6uJjqrP1b5plBNtw3iwyhPreiworonqk2 nugrac0tgRz0iAXM3swuNINF6T8j02hzvDsRkNyWn2g7T44CYjR6Y4FActTQH00oSLA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=MqJWCR9S; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9057606A332; Thu, 19 Nov 2026 03:07:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=MqJWCR9S Received: by smtp.kernel.org (Postfix) with ESMTPSA id C81D71F000C4; Thu, 19 Nov 2026 03:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795057663; bh=ByKlpNPFWGNJQWYzUS6A6Li2KxVzu9BFGKhqJl7EY4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MqJWCR9SuFRmSOAOnOMw9YBpSkb5o1En2nO2y1cwZSpbluZJISXrwWRLAUrDUfDfF aoX5p2FbfkQsqAUaqs4yQ3QPDDlcXTIwGBrNEbNRpl8RFFucI7i/xL2FGvgcwnay5A mbfH3/RiEsVUgz5Etf7zWFQnxj7agQS8v6YWscxI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fang Xieyan , Andrew Morton , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Marco Elver , Victor Chibotaru Subject: [PATCH 5.10 0209/1848] kcov: ignore an out-of-range comparison count in write_comp_data() Date: Wed, 18 Nov 2026 15:37:27 +0100 Message-ID: <20261118145920.783363877@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fang Xieyan commit f5263bee9eb84d2388fd7555a18d518e17226894 upstream. write_comp_data() reads the comparison record count from area[0] and uses it to index the coverage buffer: area = (u64 *)t->kcov_area; max_pos = t->kcov_size * sizeof(unsigned long); count = READ_ONCE(area[0]); /* Every record is KCOV_WORDS_PER_CMP 64-bit words. */ start_index = 1 + count * KCOV_WORDS_PER_CMP; end_pos = (start_index + KCOV_WORDS_PER_CMP) * sizeof(u64); if (likely(end_pos <= max_pos)) { The buffer is mmap'd writable into the collecting process, so count is under its control and end_pos <= max_pos is its only bound. A count that wraps the u64 multiply leaves end_pos below max_pos, so the check passes while the record store lands 24 bytes before the buffer, in the unmapped vmalloc guard page, and faults: BUG: unable to handle page fault for address: ffa0000000b60fe8 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page Oops: 0002 [#1] SMP KASAN NOPTI RIP: 0010:write_comp_data+0x7e/0xa0 ... Kernel panic - not syncing: Fatal exception Bound count first: only max_pos / (sizeof(u64) * KCOV_WORDS_PER_CMP) records fit, so a larger count is not a valid index and is dropped. kcov_move_area() bounds the same untrusted count this way, and no count the end_pos <= max_pos check accepts reaches that limit, so no valid record is lost. kcov is a root-only debugfs file (debugfs_create_file_unsafe("kcov", 0600, ...)) and write_comp_data() exists only under CONFIG_KCOV_ENABLE_COMPARISONS, so this is a local, debug-kernel robustness fix: the process corrupts its own buffer and the kernel oopses. It crosses no privilege boundary. Additional details at [1] Link: https://lore.kernel.org/20260917104306.22145-1-fangxy@xiaopeng.com [1] Fixes: ded97d2c2b2c ("kcov: support comparison operands collection") Signed-off-by: Fang Xieyan Signed-off-by: Andrew Morton Reviewed-by: Alexander Potapenko Assisted-by: Hawkeye:GLM-5.3-flash Assisted-by: Qoder:Qwen3.8-Max Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Marco Elver Cc: Victor Chibotaru Cc: Signed-off-by: Greg Kroah-Hartman --- kernel/kcov.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -220,6 +220,14 @@ static void notrace write_comp_data(u64 count = READ_ONCE(area[0]); + /* + * area[0] is writable by the collecting process, so count cannot be + * trusted. Bound it to the records that fit, as kcov_move_area() + * does, so the end_pos multiply below cannot wrap past its check. + */ + if (count >= max_pos / (sizeof(u64) * KCOV_WORDS_PER_CMP)) + return; + /* Every record is KCOV_WORDS_PER_CMP 64-bit words. */ start_index = 1 + count * KCOV_WORDS_PER_CMP; end_pos = (start_index + KCOV_WORDS_PER_CMP) * sizeof(u64);