lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221118051156.961494-1-itaru.kitayama@fujitsu.com>
Date:   Fri, 18 Nov 2022 14:11:56 +0900
From:   Itaru Kitayama <itaru.kitayama@...itsu.com>
To:     yamada.masahiko@...itsu.com
Cc:     acme@...nel.org, alexander.shishkin@...ux.intel.com,
        jolsa@...nel.org, linux-kernel@...r.kernel.org,
        linux-perf-users@...r.kernel.org, mark.rutland@....com,
        mingo@...hat.com, namhyung@...nel.org, peterz@...radead.org
Subject: [PATCH 1/1] perf: fix reset interface potential failure

On Fri, Nov 18, 2022 at 11:00:16AM +0900, Masahiko wrote:
> There is a potential bug where PERF_EVENT_IOC_RESET
> does not work when accessing PMU registers directly
> from userspace in the perf_event interface.
> we have created a patch on the kernel
> that fixes a potential perf_event reset failure.
> 
> The motivation is to initialize pc->offset.
> The perf_mmap__read_self function in tools/lib/perf/mmap.c is set by:.
> cnt = READ_ONCE(pc->offset);
> The pc->offset value is set in the following process
> in the perf_event_update_userpage function:.
> userpg->offset -= local64_read(&event->hw.prev_count);
> hw->prev_count is set in the armpmu_event_set_period function
> in drivers/perf/arm_pmu.c and in the x86_perf_event_set_period function
> in arch/x86/events/core.c as follows:.
> local64_set(&hwc->prev_count, (u64)-left);
> 
> Therefore, this patch was created to initialize hwc->prev_count
> during reset processing.
> 
> Signed-off-by: Masahiko, Yamada <yamada.masahiko@...itsu.com>
> ---
>  kernel/events/core.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4ec3717003d5..296549755a9c 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -5468,8 +5468,13 @@ static __poll_t perf_poll(struct file *file, poll_table *wait)
>  
>  static void _perf_event_reset(struct perf_event *event)
>  {
> +	struct hw_perf_event *hwc = &event->hw;
> +	s64 left;
> +
>  	(void)perf_event_read(event, false);
>  	local64_set(&event->count, 0);
> +	left = local64_read(&hwc->period_left);
> +	local64_set(&hwc->prev_count, (u64)-left);
>  	perf_event_update_userpage(event);
>  }
>  
> -- 
> 2.27.0

Reviewed-by: Itaru Kitayama <itaru.kitayama@...itsu.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ