Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5397072imm; Sun, 26 Aug 2018 19:02:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZPhpxQXQ3tD/K4dABxZwegDIyBN79+k8wEMdJRnrwPe4XoHgZY6NRWmaRbRbOLJoNgfplb X-Received: by 2002:a17:902:6b4c:: with SMTP id g12-v6mr11216223plt.159.1535335371189; Sun, 26 Aug 2018 19:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535335371; cv=none; d=google.com; s=arc-20160816; b=FhYnE5Qtwu8GfRjmHOamj6Z3f36YPRRiLxC+OQBjATpUqfSuep4l1+NAPIcIgRXhBl 1j1y5tcMrwj5DMUj8AaLDq0Ht1JTMohESuqhhF3lxO/E39hTxuaVVltNV182BSw/I3xU zhE1CtX0M6AT7JmuSYOuVoae/lmSn4ja4Fag3xr/ZWZ+QV2tKe0Vex1bbBrzNBdPllq/ unCafF5xpfMMN0KLpc5UzASsAWJ5KhGBEPmoccs8BZqnYE8/u18ksK4AZp1HHWmcCkpf kZmqNvMsduH6n+3KrwYA1wd+ZtlPC2+3DXt9fGdlrCcDyoeN2whIR8xp+DRn4WyRbVNm DM1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=6Z7dxUM7+JCRzge4hYkkcrl9/8It2rvsUOnof5IdRf0=; b=G/q1yms+Yt7AGcl3GGDYj6z0Nt5NsBkwn2kBzQWR+OmtTDIx8sNCKTdEvhTIzP5upU FYsikUa+ghMczPNh4Ka4QQag8WHVUXUY9Tm15ZIVdllqfLO15uONHPjsEktgEH/cHbfO hBc3uATp8X6zH6fyxp9Nwa3A1NXDgffbWXoiCxrw0DiTH/IYyqjYeiG+fJiyw5GW/0DE InWSVZ0Cl+uvk9qYFea+B4TRAizlpd+BiDUvi1m5Gx6YHhZtiuvKPcvdGObgnlZzw2Nd DBSV9xvW/hJ/WbnEjJudP51oO7eUtahqE20u1XeotzkiWVbW6hXhhnEtmq8xgu+XR8LE 7KaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 87-v6si14533994pfi.60.2018.08.26.19.02.36; Sun, 26 Aug 2018 19:02:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727199AbeH0Fpy (ORCPT + 99 others); Mon, 27 Aug 2018 01:45:54 -0400 Received: from mail1.windriver.com ([147.11.146.13]:49868 "EHLO mail1.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbeH0Fpy (ORCPT ); Mon, 27 Aug 2018 01:45:54 -0400 Received: from ALA-HCA.corp.ad.wrs.com ([147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id w7R21MTb027605 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Sun, 26 Aug 2018 19:01:23 -0700 (PDT) Received: from pek-lpgtest5.wrs.com (128.224.153.85) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.408.0; Sun, 26 Aug 2018 19:01:22 -0700 From: Haiqing Bai To: , , , CC: , , Subject: [V2][PATCH net] tipc: fix the big/little endian issue in tipc_dest Date: Mon, 27 Aug 2018 09:32:26 +0800 Message-ID: <1535333546-16753-1-git-send-email-Haiqing.Bai@windriver.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Jon Maloy Signed-off-by: Haiqing Bai --- 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