Commit dc5306a8 authored by Kees Cook's avatar Kees Cook Committed by Paolo Abeni

decnet: Use container_of() for struct dn_neigh casts

Clang's structure layout randomization feature gets upset when it sees
struct neighbor (which is randomized) cast to struct dn_neigh:

net/decnet/dn_route.c:1123:15: error: casting from randomized structure pointer type 'struct neighbour *' to 'struct dn_neigh *'
			gateway = ((struct dn_neigh *)neigh)->addr;
				   ^

Update all the open-coded casts to use container_of() to do the conversion
instead of depending on strict member ordering.
Reported-by: default avatarkernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/202205041247.WKBEHGS5-lkp@intel.com
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Yajun Deng <yajun.deng@linux.dev>
Cc: Zheng Yongjun <zhengyongjun3@huawei.com>
Cc: Bill Wendling <morbo@google.com>
Cc: linux-decnet-user@lists.sourceforge.net
Cc: netdev@vger.kernel.org
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220508102217.2647184-1-keescook@chromium.orgSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 1809c30b
...@@ -854,7 +854,7 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa) ...@@ -854,7 +854,7 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
memcpy(msg->neighbor, dn_hiord, ETH_ALEN); memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
if (dn_db->router) { if (dn_db->router) {
struct dn_neigh *dn = (struct dn_neigh *)dn_db->router; struct dn_neigh *dn = container_of(dn_db->router, struct dn_neigh, n);
dn_dn2eth(msg->neighbor, dn->addr); dn_dn2eth(msg->neighbor, dn->addr);
} }
...@@ -902,7 +902,7 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa) ...@@ -902,7 +902,7 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
{ {
int n; int n;
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr); struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
struct dn_neigh *dn = (struct dn_neigh *)dn_db->router; struct dn_neigh *dn = container_of(dn_db->router, struct dn_neigh, n);
struct sk_buff *skb; struct sk_buff *skb;
size_t size; size_t size;
unsigned char *ptr; unsigned char *ptr;
......
...@@ -426,7 +426,8 @@ int dn_neigh_router_hello(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -426,7 +426,8 @@ int dn_neigh_router_hello(struct net *net, struct sock *sk, struct sk_buff *skb)
if (!dn_db->router) { if (!dn_db->router) {
dn_db->router = neigh_clone(neigh); dn_db->router = neigh_clone(neigh);
} else { } else {
if (msg->priority > ((struct dn_neigh *)dn_db->router)->priority) if (msg->priority > container_of(dn_db->router,
struct dn_neigh, n)->priority)
neigh_release(xchg(&dn_db->router, neigh_clone(neigh))); neigh_release(xchg(&dn_db->router, neigh_clone(neigh)));
} }
} }
......
...@@ -1120,7 +1120,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o ...@@ -1120,7 +1120,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
/* Ok then, we assume its directly connected and move on */ /* Ok then, we assume its directly connected and move on */
select_source: select_source:
if (neigh) if (neigh)
gateway = ((struct dn_neigh *)neigh)->addr; gateway = container_of(neigh, struct dn_neigh, n)->addr;
if (gateway == 0) if (gateway == 0)
gateway = fld.daddr; gateway = fld.daddr;
if (fld.saddr == 0) { if (fld.saddr == 0) {
...@@ -1429,7 +1429,7 @@ static int dn_route_input_slow(struct sk_buff *skb) ...@@ -1429,7 +1429,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
/* Use the default router if there is one */ /* Use the default router if there is one */
neigh = neigh_clone(dn_db->router); neigh = neigh_clone(dn_db->router);
if (neigh) { if (neigh) {
gateway = ((struct dn_neigh *)neigh)->addr; gateway = container_of(neigh, struct dn_neigh, n)->addr;
goto make_route; goto make_route;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment