2018-08-23 09:20:19

by Haiqing Bai

[permalink] [raw]
Subject: [PATCH net] tipc: fix the big/little endian issue in tipc_dest

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: d06b2fa34f18 ("tipc: improve destination linked list")

Signed-off-by: Zhenbo Gao <[email protected]>
Acked-by: Jon Maloy <[email protected]>
Signed-off-by: Haiqing Bai <[email protected]>
---
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



2018-08-26 00:38:03

by David Miller

[permalink] [raw]
Subject: Re: [PATCH net] tipc: fix the big/little endian issue in tipc_dest

From: Haiqing Bai <[email protected]>
Date: Thu, 23 Aug 2018 16:49:18 +0800

> Fixes: d06b2fa34f18 ("tipc: improve destination linked list")

Please fix this:

[davem@localhost net]$ git describe d06b2fa34f18
fatal: Not a valid object name d06b2fa34f18

2018-08-27 02:02:50

by Haiqing Bai

[permalink] [raw]
Subject: RE: [PATCH net] tipc: fix the big/little endian issue in tipc_dest

Thanks, V2 will be send out.

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: 2018??8??26?? 8:37
To: Bai, Haiqing
Cc: [email protected]; [email protected]; Xue, Ying; Gao, Zhenbo; [email protected]
Subject: Re: [PATCH net] tipc: fix the big/little endian issue in tipc_dest

From: Haiqing Bai <[email protected]>
Date: Thu, 23 Aug 2018 16:49:18 +0800

> Fixes: d06b2fa34f18 ("tipc: improve destination linked list")

Please fix this:

[davem@localhost net]$ git describe d06b2fa34f18
fatal: Not a valid object name d06b2fa34f18