linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [V2][PATCH net] tipc: fix the big/little endian issue in tipc_dest
@ 2018-08-27  1:32 Haiqing Bai
  2018-08-27 22:24 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Haiqing Bai @ 2018-08-27  1:32 UTC (permalink / raw)
  To: netdev, jon.maloy, ying.xue, davem; +Cc: zhenbo.gao, haiqing.bai, linux-kernel

In function tipc_dest_push, the 32bit variables 'node' and 'port'
are stored separately in uppper and lower part of 64bit 'value'.
Then this value is assigned to dst->value which is a union like:
union
{
  struct {
    u32 port;
    u32 node;
  };
  u64 value;
}
This works on little-endian machines like x86 but fails on big-endian
machines.

The fix remove the 'value' stack parameter and even the 'value'
member of the union in tipc_dest, assign the 'node' and 'port' member
directly with the input parameter to avoid the endian issue.

Fixes: a80ae5306a73 ("tipc: improve destination linked list")

Signed-off-by: Zhenbo Gao <zhenbo.gao@windriver.com>
Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com>
---
 net/tipc/name_table.c | 10 ++++------
 net/tipc/name_table.h |  9 ++-------
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 88f027b..66d5b2c 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -980,20 +980,17 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)
 
 struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port)
 {
-	u64 value = (u64)node << 32 | port;
 	struct tipc_dest *dst;
 
 	list_for_each_entry(dst, l, list) {
-		if (dst->value != value)
-			continue;
-		return dst;
+		if (dst->node == node && dst->port == port)
+			return dst;
 	}
 	return NULL;
 }
 
 bool tipc_dest_push(struct list_head *l, u32 node, u32 port)
 {
-	u64 value = (u64)node << 32 | port;
 	struct tipc_dest *dst;
 
 	if (tipc_dest_find(l, node, port))
@@ -1002,7 +999,8 @@ bool tipc_dest_push(struct list_head *l, u32 node, u32 port)
 	dst = kmalloc(sizeof(*dst), GFP_ATOMIC);
 	if (unlikely(!dst))
 		return false;
-	dst->value = value;
+	dst->node = node;
+	dst->port = port;
 	list_add(&dst->list, l);
 	return true;
 }
diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h
index 0febba4..892bd75 100644
--- a/net/tipc/name_table.h
+++ b/net/tipc/name_table.h
@@ -133,13 +133,8 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
 
 struct tipc_dest {
 	struct list_head list;
-	union {
-		struct {
-			u32 port;
-			u32 node;
-		};
-		u64 value;
-	};
+	u32 port;
+	u32 node;
 };
 
 struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [V2][PATCH net] tipc: fix the big/little endian issue in tipc_dest
  2018-08-27  1:32 [V2][PATCH net] tipc: fix the big/little endian issue in tipc_dest Haiqing Bai
@ 2018-08-27 22:24 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-08-27 22:24 UTC (permalink / raw)
  To: Haiqing.Bai; +Cc: netdev, jon.maloy, ying.xue, zhenbo.gao, linux-kernel

From: Haiqing Bai <Haiqing.Bai@windriver.com>
Date: Mon, 27 Aug 2018 09:32:26 +0800

> In function tipc_dest_push, the 32bit variables 'node' and 'port'
> are stored separately in uppper and lower part of 64bit 'value'.
> Then this value is assigned to dst->value which is a union like:
> union
> {
>   struct {
>     u32 port;
>     u32 node;
>   };
>   u64 value;
> }
> This works on little-endian machines like x86 but fails on big-endian
> machines.
> 
> The fix remove the 'value' stack parameter and even the 'value'
> member of the union in tipc_dest, assign the 'node' and 'port' member
> directly with the input parameter to avoid the endian issue.
> 
> Fixes: a80ae5306a73 ("tipc: improve destination linked list")
> 
> Signed-off-by: Zhenbo Gao <zhenbo.gao@windriver.com>
> Acked-by: Jon Maloy <jon.maloy@ericsson.com>
> Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-27 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-27  1:32 [V2][PATCH net] tipc: fix the big/little endian issue in tipc_dest Haiqing Bai
2018-08-27 22:24 ` David Miller

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).