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=1794061119; b=dLtHWiyGWKByd11Jwr7D1o/z7rczbdmtKTnavELNkwSCijuxDQ9t+VFBAwIl4FO6r/Zj Nr8Cf4DYNfESDfMZ24o5NrJx6jfePOB5YRDK1lY3aFWML4PWGYoUr29PVWkHCe1KmLnb7 ZrtI/gzXR3fA50a0XYA2AfkZqJ0bcYu8SyFNpBGaOPM/ZCkaEJ6zHHaeHHYi773TWrm/y bDsJHfNExKG3RODejLowTV6S+SLm6jAr0mZyvBWwhDTvAugHVbWNipHcDvbRdk2gMg5Rf CKOSnzGzNXtMDe63gZFdnt1Ob9FpOT7ydhe3cTyTDanGuPyhxQvZuL1s41qV04bgxPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794061119; 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=VfYk3Rpd9KF2kZPQJgd/SbawJ1Qdr3yC3aTHRorcGyk=; b=tHW6A9RG9BAOjGGcoXPRO24or4NNzcNd6czusOZqHJfLQf9XJ7Wt4/7q+0C2KO/YsCU/ zZ+w1UrnY/iQkdAwHtQZ8hRgEkl3LyVn+GsDTLgLOd+isBi38tCk+Oo+/D+EVHsERCl/B cXaE4xMryVQbpvHhcrHAqObiMTHPxR0sytJ/ouoS2kMcQOp2CwPjnoQ2FF/DEuiZPGUs6 YzmZ+OLIzTE7ewAREFp2xNKQfKMsEFJ1vw4P83/X27AKrLb9FkxjeAfklB6yAXvALO1R6 NPcDKESPQfbeabFd4zHKTaBMZI9sVqE4lDyMg/jU6DEtga3u5nuekau2zH5gmlCvnjQ== 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=EbwVs3hH; 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 EEE2B606A332; Sat, 7 Nov 2026 14:18:38 +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=EbwVs3hH Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5C7E1F0089F; Sat, 7 Nov 2026 14:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794061118; bh=VfYk3Rpd9KF2kZPQJgd/SbawJ1Qdr3yC3aTHRorcGyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EbwVs3hHwHHjtwVAYGHmzWTSbgU8jexyndYQYWSFO/Kn5HcA/rY7ihmcnqLC1stry W4N8ksPRoN1xhnpypSZxB53h1u+t9IvXsGazoVEDfdFmuQUeVHMUPE52ycx2mLIkEF zLLGH3pnW29H8u5BcQgpXpvbjKb2ODpULh5CVntQ= 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 6.12 0433/1536] kcov: ignore an out-of-range comparison count in write_comp_data() Date: Sat, 7 Nov 2026 08:40:49 -0500 Message-ID: <20261107135009.725788639@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134957.653319350@linuxfoundation.org> References: <20261107134957.653319350@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 @@ -253,6 +253,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);