Re: [syzbot] [net?] KASAN: slab-out-of-bounds Read in dsa_user_prechangeupper

From: Edward Adam Davis
Date: Tue Jan 16 2024 - 09:19:45 EST


please test slab-out-of-bounds Read in dsa_user_prechangeupper

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 3e7aeb78ab01

diff --git a/net/dsa/user.h b/net/dsa/user.h
index 996069130bea..9a40918ee7fc 100644
--- a/net/dsa/user.h
+++ b/net/dsa/user.h
@@ -53,7 +53,11 @@ int dsa_user_manage_vlan_filtering(struct net_device *dev,

static inline struct dsa_port *dsa_user_to_port(const struct net_device *dev)
{
- struct dsa_user_priv *p = netdev_priv(dev);
+ const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
+ struct dsa_user_priv *p = ops->priv_size >= sizeof(*p) ?
+ netdev_priv(dev) : NULL;
+ if (!p)
+ return NULL;

return p->dp;
}