Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30935198 authored by Haiqing Bai's avatar Haiqing Bai Committed by David S. Miller
Browse files

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: a80ae530 ("tipc: improve destination linked list")
Signed-off-by: default avatarZhenbo Gao <zhenbo.gao@windriver.com>
Acked-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarHaiqing Bai <Haiqing.Bai@windriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ca2b1d2d
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -980,12 +980,10 @@ 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;
		if (dst->node == node && dst->port == port)
			return dst;
	}
	return NULL;
@@ -993,7 +991,6 @@ struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port)

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;
}
+2 −7
Original line number Diff line number Diff line
@@ -133,14 +133,9 @@ void tipc_nametbl_stop(struct net *net);

struct tipc_dest {
	struct list_head list;
	union {
		struct {
	u32 port;
	u32 node;
};
		u64 value;
	};
};

struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port);
bool tipc_dest_push(struct list_head *l, u32 node, u32 port);