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: <20251027162521.c56c7f89f6ad4e3d639c408c@linux-foundation.org>
Date: Mon, 27 Oct 2025 16:25:21 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Ankit Khushwaha <ankitkhushwaha.linux@...il.com>
Cc: linux-kselftest@...r.kernel.org, Shuah Khan <shuah@...nel.org>,
 Bala-Vignesh-Reddy <reddybalavignesh9979@...il.com>, Wei Yang
 <richard.weiyang@...il.com>, linux-kernel@...r.kernel.org,
 linux-kernel-mentees@...ts.linuxfoundation.org, Steven Rostedt
 <rostedt@...dmis.org>
Subject: Re: [PATCH] selftests/user_events: Avoid taking address of packed
 member in perf_test

On Mon, 27 Oct 2025 17:04:39 +0530 Ankit Khushwaha <ankitkhushwaha.linux@...il.com> wrote:

> Accessing 'reg.write_index' directly triggers a -Waddress-of-packed-member
> warning due to potential unaligned pointer access:
> 
> perf_test.c:239:38: warning: taking address of packed member 'write_index'
> of class or structure 'user_reg' may result in an unaligned pointer value 
> [-Waddress-of-packed-member]
>   239 |         ASSERT_NE(-1, write(self->data_fd, &reg.write_index,
>       |                                             ^~~~~~~~~~~~~~~ 
> 
> Use memcpy() instead to safely copy the value and avoid unaligned pointer
> access across architectures.
> 
> ...
>
> --- a/tools/testing/selftests/user_events/perf_test.c
> +++ b/tools/testing/selftests/user_events/perf_test.c
> @@ -201,6 +201,7 @@ TEST_F(user, perf_empty_events) {
>  	struct perf_event_mmap_page *perf_page;
>  	int page_size = sysconf(_SC_PAGESIZE);
>  	int id, fd;
> +	__u32 write_index;
>  	__u32 *val;
>  
>  	reg.size = sizeof(reg);
> @@ -236,7 +237,8 @@ TEST_F(user, perf_empty_events) {
>  	ASSERT_EQ(1 << reg.enable_bit, self->check);
>  
>  	/* Ensure write shows up at correct offset */
> -	ASSERT_NE(-1, write(self->data_fd, &reg.write_index,
> +	memcpy(&write_index, &reg.write_index, sizeof(reg.write_index));
> +	ASSERT_NE(-1, write(self->data_fd, &write_index,
>  	                    sizeof(reg.write_index)));

Simply casting &write_index to void* would fix this?

>  	val = (void *)(((char *)perf_page) + perf_page->data_offset);
>  	ASSERT_EQ(PERF_RECORD_SAMPLE, *val);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ