Thread (6 messages) 6 messages, 4 authors, 10h ago

Re: [PATCH net-next net] netdev: Hide the netdev_priv() origin from GCC in netdev_from_priv()

flat view

From: Qingfang Deng <hidden>
Date: 2026-10-16 15:19:15
Also in: linux-hardening, lkml, netdev, stable

Hi,

On 10/16/2026 1:00 AM, Kees Cook wrote:
quoted hunk ↗ jump to hunk
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2838,6 +2838,13 @@ static inline void *netdev_priv(const struct net_device *dev)
   */
  static inline struct net_device *netdev_from_priv(const void *priv)
  {
+	/*
+	 * When GCC can see that @priv came from netdev_priv(), it can
+	 * compute an object size of 0 for the net_device and its members,
+	 * which makes FORTIFY_SOURCE fail valid accesses through the result:
+	 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127875
+	 */
+	OPTIMIZER_HIDE_VAR(priv);
If this bug only affects GCC, you may wrap it with a
#ifdef CONFIG_CC_IS_GCC block.
  	return container_of(priv, struct net_device, priv);
  }
  
Kind regards,
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help