Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "JunYoung Lee" <ljyoung04@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 1/2] perf/core: Don't report a kernel IP for exclude_kernel events
Date: Wed, 02 Dec 2026 12:16:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-245682@kernel.org> (raw)
In-Reply-To: <20261202115902.586760-2-ljyoung04@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf/core: perf_instruction_pointer() leaks kernel page size
  via guest IP
--

commit a820ba38e41084effb8fa61a40e0099cbe14de3a
Author: JunYoung Lee <ljyoung04@gmail.com>

perf/core: Don't report a kernel IP for exclude_kernel events

This commit returns 0 from perf_instruction_pointer() on exclude_kernel
events when the sampled IP is >= TASK_SIZE_MAX, preventing a user mode
trap frame with a kernel IP from exposing kernel code page sizes via
PERF_SAMPLE_CODE_PAGE_SIZE.

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4ab3919ac78e9..4c7f173d716a3 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -7858,6 +7858,8 @@ unsigned long perf_misc_flags(struct perf_event *event,
>  unsigned long perf_instruction_pointer(struct perf_event *event,
>  				       struct pt_regs *regs)
>  {
> +	unsigned long ip;
> +
>  	/*
>  	 * Hardware skid can lead to a scenario where a PMI is
>  	 * delivered after the CPU has already entered kernel mode.
> @@ -7870,8 +7872,18 @@ unsigned long perf_instruction_pointer(struct perf_event *event,
>  			0 : perf_guest_get_ip();
>  	}
>  
> -	return event->attr.exclude_kernel && !user_mode(regs) ?
> -		0 : perf_arch_instruction_pointer(regs);
> +	ip = perf_arch_instruction_pointer(regs);
> +
> +	/*
> +	 * A user mode frame can still carry a kernel IP, for example when a
> +	 * debug trap is taken right after a jump to a kernel address, before
> +	 * the instruction fetch faults.
> +	 */
> +	if (event->attr.exclude_kernel &&
> +	    (!user_mode(regs) || ip >= TASK_SIZE_MAX))
> +		return 0;
> +
> +	return ip;
>  }

[Severity: Medium]
Can the should_sample_guest() branch still return a kernel address >=
TASK_SIZE_MAX on an exclude_kernel event?

An unprivileged user can open a PERF_SAMPLE_CODE_PAGE_SIZE event with
exclude_kernel=1 and exclude_guest=0, and run a KVM vCPU in guest user
mode (PERF_GUEST_USER) with a guest IP >= TASK_SIZE_MAX.
perf_instruction_pointer() then returns perf_guest_get_ip() without the
ip >= TASK_SIZE_MAX check, and perf_prepare_sample() passes data->ip to
perf_get_page_size(), which walks current->mm on the host and reports the
host kernel mapping's page size.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202115902.586760-1-ljyoung04@gmail.com?part=1

  reply	other threads:[~2026-12-02 12:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 11:59 [PATCH v2 0/2] perf/core: Fix kernel page size leak and espfix hang JunYoung Lee
2026-12-02 11:59 ` [PATCH v2 1/2] perf/core: Don't report a kernel IP for exclude_kernel events JunYoung Lee
2026-12-02 12:16   ` sashiko-bot [this message]
2026-12-02 11:59 ` [PATCH v2 2/2] perf/core: Don't loop forever on a bad pmd in perf_get_pgtable_size() JunYoung Lee
2026-12-02 12:16 ` [PATCH v2 0/2] perf/core: Fix kernel page size leak and espfix hang sashiko-bot

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=sashiko-outbox-245682@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=ljyoung04@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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