net//netfilter/nf_flow_table_offload.c:80:21: warning: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0'

From: kbuild test robot
Date: Wed Dec 04 2019 - 14:34:51 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 63de37476ebd1e9bab6a9e17186dc5aa1da9ea99
commit: c29f74e0df7a02b8303bcdce93a7c0132d62577a netfilter: nf_flow_table: hardware offload support
date: 3 weeks ago
config: openrisc-allmodconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout c29f74e0df7a02b8303bcdce93a7c0132d62577a
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=openrisc

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

net//netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_match':
>> net//netfilter/nf_flow_table_offload.c:80:21: warning: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0' [-Woverflow]
80 | mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
| ^~~~~~~~~~~~
In function 'flow_offload_mangle',
inlined from 'flow_offload_port_snat' at net//netfilter/nf_flow_table_offload.c:268:2,
inlined from 'nf_flow_rule_route' at net//netfilter/nf_flow_table_offload.c:349:3:
>> net//netfilter/nf_flow_table_offload.c:112:2: warning: 'memcpy' forming offset [3, 4] is out of the bounds [0, 2] of object 'port' with type '__be16' {aka 'short unsigned int'} [-Warray-bounds]
112 | memcpy(&entry->mangle.val, value, sizeof(u32));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net//netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_route':
net//netfilter/nf_flow_table_offload.c:252:9: note: 'port' declared here
252 | __be16 port;
| ^~~~
In function 'flow_offload_mangle',
inlined from 'flow_offload_port_dnat' at net//netfilter/nf_flow_table_offload.c:294:2,
inlined from 'nf_flow_rule_route' at net//netfilter/nf_flow_table_offload.c:355:3:
>> net//netfilter/nf_flow_table_offload.c:112:2: warning: 'memcpy' forming offset [3, 4] is out of the bounds [0, 2] of object 'port' with type '__be16' {aka 'short unsigned int'} [-Warray-bounds]
112 | memcpy(&entry->mangle.val, value, sizeof(u32));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net//netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_route':
net//netfilter/nf_flow_table_offload.c:278:9: note: 'port' declared here
278 | __be16 port;
| ^~~~

vim +80 net//netfilter/nf_flow_table_offload.c

46
47 #define NF_FLOW_DISSECTOR(__match, __type, __field) \
48 (__match)->dissector.offset[__type] = \
49 offsetof(struct nf_flow_key, __field)
50
51 static int nf_flow_rule_match(struct nf_flow_match *match,
52 const struct flow_offload_tuple *tuple)
53 {
54 struct nf_flow_key *mask = &match->mask;
55 struct nf_flow_key *key = &match->key;
56
57 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_CONTROL, control);
58 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_BASIC, basic);
59 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4);
60 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_TCP, tcp);
61 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_PORTS, tp);
62
63 switch (tuple->l3proto) {
64 case AF_INET:
65 key->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
66 key->basic.n_proto = htons(ETH_P_IP);
67 key->ipv4.src = tuple->src_v4.s_addr;
68 mask->ipv4.src = 0xffffffff;
69 key->ipv4.dst = tuple->dst_v4.s_addr;
70 mask->ipv4.dst = 0xffffffff;
71 break;
72 default:
73 return -EOPNOTSUPP;
74 }
75 mask->basic.n_proto = 0xffff;
76
77 switch (tuple->l4proto) {
78 case IPPROTO_TCP:
79 key->tcp.flags = 0;
> 80 mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
81 match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_TCP);
82 break;
83 case IPPROTO_UDP:
84 break;
85 default:
86 return -EOPNOTSUPP;
87 }
88
89 key->basic.ip_proto = tuple->l4proto;
90 mask->basic.ip_proto = 0xff;
91
92 key->tp.src = tuple->src_port;
93 mask->tp.src = 0xffff;
94 key->tp.dst = tuple->dst_port;
95 mask->tp.dst = 0xffff;
96
97 match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_CONTROL) |
98 BIT(FLOW_DISSECTOR_KEY_BASIC) |
99 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
100 BIT(FLOW_DISSECTOR_KEY_PORTS);
101 return 0;
102 }
103
104 static void flow_offload_mangle(struct flow_action_entry *entry,
105 enum flow_action_mangle_base htype,
106 u32 offset, u8 *value, u8 *mask)
107 {
108 entry->id = FLOW_ACTION_MANGLE;
109 entry->mangle.htype = htype;
110 entry->mangle.offset = offset;
111 memcpy(&entry->mangle.mask, mask, sizeof(u32));
> 112 memcpy(&entry->mangle.val, value, sizeof(u32));
113 }
114

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx Intel Corporation

Attachment: .config.gz
Description: application/gzip