netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: "David S. Miller" <davem@davemloft.net>
Cc: Jan Engelhardt <jengelh@inai.de>,
	Ido Schimmel <idosch@idosch.org>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	David Laight <David.Laight@ACULAB.COM>,
	netdev@vger.kernel.org
Subject: [PATCH 2/4] net: make sockptr_is_null strict aliasing safe
Date: Tue, 28 Jul 2020 08:36:41 +0200	[thread overview]
Message-ID: <20200728063643.396100-3-hch@lst.de> (raw)
In-Reply-To: <20200728063643.396100-1-hch@lst.de>

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>
---
 include/linux/sockptr.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/sockptr.h b/include/linux/sockptr.h
index 7d5cdb2b30b5f0..b13ea1422f93a5 100644
--- a/include/linux/sockptr.h
+++ b/include/linux/sockptr.h
@@ -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)
-- 
2.27.0


  parent reply	other threads:[~2020-07-28  6:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  6:36 [PATCH 0/4 net-next] sockptr_t fixes Christoph Hellwig
2020-07-28  6:36 ` [PATCH 1/4] netfilter: arp_tables: restore a SPDX identifier Christoph Hellwig
2020-07-28  6:36 ` Christoph Hellwig [this message]
2020-07-28  6:36 ` [PATCH 3/4] net: remove sockptr_advance Christoph Hellwig
2020-07-28  6:36 ` [PATCH 4/4] net: improve the user pointer check in init_user_sockptr Christoph Hellwig
2020-07-28 15:47   ` Jakub Kicinski
2020-07-28 15:51     ` Christoph Hellwig
2020-07-28 18:53       ` Jakub Kicinski
2020-07-28 15:52     ` David Laight
2020-07-28 20:01   ` David Miller
2020-07-29  6:04     ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2020-07-28 16:38 [PATCH 0/4 net-next] sockptr_t fixes v2 Christoph Hellwig
2020-07-28 16:38 ` [PATCH 2/4] net: make sockptr_is_null strict aliasing safe Christoph Hellwig
2020-07-29  8:04   ` David Laight
2020-07-29  9:06     ` Jan Engelhardt

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=20200728063643.396100-3-hch@lst.de \
    --to=hch@lst.de \
    --cc=David.Laight@ACULAB.COM \
    --cc=Jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=idosch@idosch.org \
    --cc=jengelh@inai.de \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).