All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] samples/seccomp: eliminate two compile warnings in user-trap.c
@ 2020-09-01  8:39 Zhen Lei
  2020-09-01  8:39 ` [PATCH v2 1/1] " Zhen Lei
  0 siblings, 1 reply; 5+ messages in thread
From: Zhen Lei @ 2020-09-01  8:39 UTC (permalink / raw)
  To: Kees Cook, Masahiro Yamada, Greg Kroah-Hartman, Ingo Molnar,
	linux-kernel
  Cc: Zhen Lei

v1 --> v2:
1. a character 'g' is missed in "userccflags += -fno-strict-aliasing".
2. delete the word "boring" in the subject.

Zhen Lei (1):
  samples/seccomp: eliminate two compile warnings in user-trap.c

 samples/seccomp/user-trap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
1.8.3



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] samples/seccomp: eliminate two compile warnings in user-trap.c
  2020-09-01  8:39 [PATCH v2 0/1] samples/seccomp: eliminate two compile warnings in user-trap.c Zhen Lei
@ 2020-09-01  8:39 ` Zhen Lei
  2020-09-02  1:33   ` Leizhen (ThunderTown)
  0 siblings, 1 reply; 5+ messages in thread
From: Zhen Lei @ 2020-09-01  8:39 UTC (permalink / raw)
  To: Kees Cook, Masahiro Yamada, Greg Kroah-Hartman, Ingo Molnar,
	linux-kernel
  Cc: Zhen Lei

samples/seccomp/user-trap.c is compiled with $(userccflags), and the
latter does not contain -fno-strict-aliasing, so the warnings reported as
below. Due to add "userccflags += -fno-strict-aliasing" will impact other
files, so use __attribute__((__may_alias__)) to suppress it exactly.

My gcc version is 5.5.0 20171010.

----------
samples/seccomp/user-trap.c: In function ‘send_fd’:
samples/seccomp/user-trap.c:50:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  *((int *)CMSG_DATA(cmsg)) = fd;
  ^
samples/seccomp/user-trap.c: In function ‘recv_fd’:
samples/seccomp/user-trap.c:83:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  return *((int *)CMSG_DATA(cmsg));
  ^

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 samples/seccomp/user-trap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/samples/seccomp/user-trap.c b/samples/seccomp/user-trap.c
index 20291ec6489f31e..e36696b7f41517f 100644
--- a/samples/seccomp/user-trap.c
+++ b/samples/seccomp/user-trap.c
@@ -23,6 +23,8 @@
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
 
+typedef int __attribute__((__may_alias__)) __int_alias_t;
+
 static int seccomp(unsigned int op, unsigned int flags, void *args)
 {
 	errno = 0;
@@ -47,7 +49,7 @@ static int send_fd(int sock, int fd)
 	cmsg->cmsg_level = SOL_SOCKET;
 	cmsg->cmsg_type = SCM_RIGHTS;
 	cmsg->cmsg_len = CMSG_LEN(sizeof(int));
-	*((int *)CMSG_DATA(cmsg)) = fd;
+	*(__int_alias_t *)CMSG_DATA(cmsg) = fd;
 	msg.msg_controllen = cmsg->cmsg_len;
 
 	if (sendmsg(sock, &msg, 0) < 0) {
@@ -80,7 +82,7 @@ static int recv_fd(int sock)
 
 	cmsg = CMSG_FIRSTHDR(&msg);
 
-	return *((int *)CMSG_DATA(cmsg));
+	return *(__int_alias_t *)CMSG_DATA(cmsg);
 }
 
 static int user_trap_syscall(int nr, unsigned int flags)
-- 
1.8.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] samples/seccomp: eliminate two compile warnings in user-trap.c
  2020-09-01  8:39 ` [PATCH v2 1/1] " Zhen Lei
@ 2020-09-02  1:33   ` Leizhen (ThunderTown)
  2020-09-08 23:42     ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Leizhen (ThunderTown) @ 2020-09-02  1:33 UTC (permalink / raw)
  To: Kees Cook, Masahiro Yamada, Greg Kroah-Hartman, Ingo Molnar,
	linux-kernel

Doesn't anyone care about this? Or is it that everyone hasn't encountered this problem?
Why do these two warnings occur every time I compiled?

On 2020/9/1 16:39, Zhen Lei wrote:
> samples/seccomp/user-trap.c is compiled with $(userccflags), and the
> latter does not contain -fno-strict-aliasing, so the warnings reported as
> below. Due to add "userccflags += -fno-strict-aliasing" will impact other
> files, so use __attribute__((__may_alias__)) to suppress it exactly.
> 
> My gcc version is 5.5.0 20171010.
> 
> ----------
> samples/seccomp/user-trap.c: In function ‘send_fd’:
> samples/seccomp/user-trap.c:50:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>   *((int *)CMSG_DATA(cmsg)) = fd;
>   ^
> samples/seccomp/user-trap.c: In function ‘recv_fd’:
> samples/seccomp/user-trap.c:83:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>   return *((int *)CMSG_DATA(cmsg));
>   ^
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  samples/seccomp/user-trap.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/samples/seccomp/user-trap.c b/samples/seccomp/user-trap.c
> index 20291ec6489f31e..e36696b7f41517f 100644
> --- a/samples/seccomp/user-trap.c
> +++ b/samples/seccomp/user-trap.c
> @@ -23,6 +23,8 @@
>  
>  #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
>  
> +typedef int __attribute__((__may_alias__)) __int_alias_t;
> +
>  static int seccomp(unsigned int op, unsigned int flags, void *args)
>  {
>  	errno = 0;
> @@ -47,7 +49,7 @@ static int send_fd(int sock, int fd)
>  	cmsg->cmsg_level = SOL_SOCKET;
>  	cmsg->cmsg_type = SCM_RIGHTS;
>  	cmsg->cmsg_len = CMSG_LEN(sizeof(int));
> -	*((int *)CMSG_DATA(cmsg)) = fd;
> +	*(__int_alias_t *)CMSG_DATA(cmsg) = fd;
>  	msg.msg_controllen = cmsg->cmsg_len;
>  
>  	if (sendmsg(sock, &msg, 0) < 0) {
> @@ -80,7 +82,7 @@ static int recv_fd(int sock)
>  
>  	cmsg = CMSG_FIRSTHDR(&msg);
>  
> -	return *((int *)CMSG_DATA(cmsg));
> +	return *(__int_alias_t *)CMSG_DATA(cmsg);
>  }
>  
>  static int user_trap_syscall(int nr, unsigned int flags)
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] samples/seccomp: eliminate two compile warnings in user-trap.c
  2020-09-02  1:33   ` Leizhen (ThunderTown)
@ 2020-09-08 23:42     ` Kees Cook
  2020-09-09  2:20       ` Leizhen (ThunderTown)
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2020-09-08 23:42 UTC (permalink / raw)
  To: Leizhen (ThunderTown)
  Cc: Masahiro Yamada, Greg Kroah-Hartman, Ingo Molnar, linux-kernel

On Wed, Sep 02, 2020 at 09:33:06AM +0800, Leizhen (ThunderTown) wrote:
> On 2020/9/1 16:39, Zhen Lei wrote:
> > samples/seccomp/user-trap.c is compiled with $(userccflags), and the
> > latter does not contain -fno-strict-aliasing, so the warnings reported as
> > below. Due to add "userccflags += -fno-strict-aliasing" will impact other
> > files, so use __attribute__((__may_alias__)) to suppress it exactly.
> > 
> > My gcc version is 5.5.0 20171010.
> > 
> > ----------
> > samples/seccomp/user-trap.c: In function ‘send_fd’:
> > samples/seccomp/user-trap.c:50:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> >   *((int *)CMSG_DATA(cmsg)) = fd;
> >   ^
> > samples/seccomp/user-trap.c: In function ‘recv_fd’:
> > samples/seccomp/user-trap.c:83:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> >   return *((int *)CMSG_DATA(cmsg));
> >   ^
>
> Doesn't anyone care about this? Or is it that everyone hasn't encountered this problem?
> Why do these two warnings occur every time I compiled?

Hi!

I think the samples have been a bit ignored lately because they have a
lot of weird build issues with regard to native vs compat and needing
the kernel headers to be built first, etc.

That said, yes, I'd like to fix warnings. However, I can't reproduce
this. How are you building? I tried x86_64 and cross-compiled to i386.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] samples/seccomp: eliminate two compile warnings in user-trap.c
  2020-09-08 23:42     ` Kees Cook
@ 2020-09-09  2:20       ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 5+ messages in thread
From: Leizhen (ThunderTown) @ 2020-09-09  2:20 UTC (permalink / raw)
  To: Kees Cook; +Cc: Masahiro Yamada, Greg Kroah-Hartman, Ingo Molnar, linux-kernel



On 2020/9/9 7:42, Kees Cook wrote:
> On Wed, Sep 02, 2020 at 09:33:06AM +0800, Leizhen (ThunderTown) wrote:
>> On 2020/9/1 16:39, Zhen Lei wrote:
>>> samples/seccomp/user-trap.c is compiled with $(userccflags), and the
>>> latter does not contain -fno-strict-aliasing, so the warnings reported as
>>> below. Due to add "userccflags += -fno-strict-aliasing" will impact other
>>> files, so use __attribute__((__may_alias__)) to suppress it exactly.
>>>
>>> My gcc version is 5.5.0 20171010.
>>>
>>> ----------
>>> samples/seccomp/user-trap.c: In function ‘send_fd’:
>>> samples/seccomp/user-trap.c:50:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>>>   *((int *)CMSG_DATA(cmsg)) = fd;
>>>   ^
>>> samples/seccomp/user-trap.c: In function ‘recv_fd’:
>>> samples/seccomp/user-trap.c:83:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>>>   return *((int *)CMSG_DATA(cmsg));
>>>   ^
>>
>> Doesn't anyone care about this? Or is it that everyone hasn't encountered this problem?
>> Why do these two warnings occur every time I compiled?
> 
> Hi!
> 
> I think the samples have been a bit ignored lately because they have a
> lot of weird build issues with regard to native vs compat and needing
> the kernel headers to be built first, etc.
> 
> That said, yes, I'd like to fix warnings. However, I can't reproduce
> this. How are you building? I tried x86_64 and cross-compiled to i386.

I can reproduce it both on X86 and ARM64.

On X86:
make distclean allmodconfig
make -j64 2>err.txt
vi err.txt

$ arch
x86_64
$ ls -l samples/seccomp/user-trap
user-trap    user-trap.c
$ gcc -v
gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu5~16.04)

On ARM64:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- distclean allmodconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j64 2>err.tx
vi err.txt

$ ls -l samples/seccomp/user-trap
user-trap    user-trap.c
$ aarch64-linux-gnu-gcc -v
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-09  2:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01  8:39 [PATCH v2 0/1] samples/seccomp: eliminate two compile warnings in user-trap.c Zhen Lei
2020-09-01  8:39 ` [PATCH v2 1/1] " Zhen Lei
2020-09-02  1:33   ` Leizhen (ThunderTown)
2020-09-08 23:42     ` Kees Cook
2020-09-09  2:20       ` Leizhen (ThunderTown)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.