net: make sockptr_is_null strict aliasing safe
authorChristoph Hellwig <hch@lst.de>
Tue, 28 Jul 2020 16:38:34 +0000 (18:38 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 28 Jul 2020 20:43:40 +0000 (13:43 -0700)
While the kernel in general is not strict aliasing safe we can trivially
do that in sockptr_is_null without affecting code generation, so always
check the actually assigned union member.

Reported-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/sockptr.h

index 7d5cdb2..b13ea14 100644 (file)
@@ -64,7 +64,9 @@ static inline int __must_check init_user_sockptr(sockptr_t *sp, void __user *p)
 
 static inline bool sockptr_is_null(sockptr_t sockptr)
 {
-       return !sockptr.user && !sockptr.kernel;
+       if (sockptr_is_kernel(sockptr))
+               return !sockptr.kernel;
+       return !sockptr.user;
 }
 
 static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size)