mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Edward Adam Davis <eadavis@sina.com>
To: syzbot+237f670105a254a230d4@syzkaller.appspotmail.com
Cc: andreyknvl@gmail.com, glider@google.com, dvyukov@google.com,
	boqun@kernel.org, tchibo@google.com,
	linux-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com,
	paulmck@kernel.org, peterz@infradead.org,
	syzkaller-bugs@googlegroups.com
Subject: [PATCH] kcov: add a missing bound check in write_comp_data()
Date: Tue, 15 Sep 2026 11:33:45 +0800	[thread overview]
Message-ID: <20260915033345.904567-1-eadavis@sina.com> (raw)
In-Reply-To: <6aa87111.f81106d8.2ab401.0057.GAE@google.com>

A missing bounds check in write_comp_data() can lead to an out-of-bounds read
or write in the adjacent memory area, since the start_index is not validated
before accessing area[] in the function later, potentially hitting:

BUG: unable to handle page fault for address: ffffc90003792fe8
RIP: 0010:write_comp_data+0x7c/0xa0 kernel/kcov.c:263
Call Trace:
 __do_sys_rseq kernel/rseq.c:549 [inline]
 __se_sys_rseq kernel/rseq.c:547 [inline]
 __x64_sys_rseq+0xc2/0x2e0 kernel/rseq.c:547

Fixes: ded97d2c2b2c ("kcov: support comparison operands collection")
Reported-by: syzbot+237f670105a254a230d4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=237f670105a254a230d4
Tested-by: syzbot+237f670105a254a230d4@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@sina.com>
---
 kernel/kcov.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/kcov.c b/kernel/kcov.c
index 35420f0ac524..479a84921833 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -236,7 +236,7 @@ static void notrace write_comp_data(u64 type, u64 arg1, u64 arg2, u64 ip)
 {
 	struct task_struct *t;
 	u64 *area;
-	u64 count, start_index, end_pos, max_pos;
+	u64 count, start_index, end_pos, max_pos, tmp;
 
 	t = current;
 	if (!check_kcov_mode(KCOV_MODE_TRACE_CMP, t))
@@ -254,7 +254,9 @@ static void notrace write_comp_data(u64 type, u64 arg1, u64 arg2, u64 ip)
 	count = READ_ONCE(area[0]);
 
 	/* Every record is KCOV_WORDS_PER_CMP 64-bit words. */
-	start_index = 1 + count * KCOV_WORDS_PER_CMP;
+	if (check_mul_overflow(count, KCOV_WORDS_PER_CMP, &tmp))
+		return;
+	start_index = 1 + tmp;
 	end_pos = (start_index + KCOV_WORDS_PER_CMP) * sizeof(u64);
 	if (likely(end_pos <= max_pos)) {
 		/* See comment in __sanitizer_cov_trace_pc(). */
-- 
2.43.0


      parent reply	other threads:[~2026-09-15  3:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02  4:52 [syzbot] [kernel?] BUG: unable to handle kernel paging request in write_comp_data syzbot
2026-09-14 22:11 ` syzbot
2026-09-15  2:06   ` Edward Adam Davis
2026-09-15  3:24     ` syzbot
2026-09-15  3:33   ` Edward Adam Davis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260915033345.904567-1-eadavis@sina.com \
    --to=eadavis@sina.com \
    --cc=andreyknvl@gmail.com \
    --cc=boqun@kernel.org \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=syzbot+237f670105a254a230d4@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tchibo@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®