hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8Y7PX CVE: NA
--------------------------------
The following error is reported when the kernel is compiled with CONFIG_SYSCTL disabled: aarch64-linux-ld: net/ipv4/inet_hashtables.o: in function `__inet_hash_connect': inet_hashtables.c:(.text+0x3564): undefined reference to `sysctl_local_port_allocation' aarch64-linux-ld: net/ipv4/inet_hashtables.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `sysctl_local_port_allocation' which may bind externally can not be used when making a shared object; recompile with -fPIC
inet_hashtables.c:(.text+0x3564): dangerous relocation: unsupported relocation
aarch64-linux-ld: inet_hashtables.c:(.text+0x3568): undefined reference to `sysctl_local_port_allocation' aarch64-linux-ld: inet_hashtables.c:(.text+0x3580): undefined reference to `sysctl_local_port_allocation' When CONFIG_SYSCTL is disabled, sysctl_local_port_allocation is undefined.
Fixes: 208a72041292 ("tcp/dccp: Add another way to allocate local ports in connect()") Reported-by: kernel test robot lkp@intel.com Closes: https://lore.kernel.org/oe-kbuild-all/202401180939.2N529UUe-lkp@intel.com/ Signed-off-by: Zhengchao Shao shaozhengchao@huawei.com --- net/ipv4/inet_hashtables.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index a24dcf39e9ae..14da0ce40bad 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -1011,7 +1011,10 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, struct inet_bind_bucket *tb; bool tb_created = false; u32 remaining, offset; - int ret, i, low, high, span_size; + int ret, i, low, high; +#if IS_ENABLED(CONFIG_SYSCTL) + int span_size; +#endif int l3mdev; u32 index;
@@ -1021,11 +1024,13 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, local_bh_enable(); return ret; } +#if IS_ENABLED(CONFIG_SYSCTL) /* local_port_allocation 0 means even and odd port allocation strategy * will be applied, so span size is 2; otherwise sequential allocation * will be used and span size is 1. Default value is 0. */ span_size = sysctl_local_port_allocation ? 1 : 2; +#endif
l3mdev = inet_sk_bound_l3mdev(sk);
@@ -1048,7 +1053,11 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, offset &= ~1U; other_parity_scan: port = low + offset; +#if IS_ENABLED(CONFIG_SYSCTL) for (i = 0; i < remaining; i += span_size, port += span_size) { +#else + for (i = 0; i < remaining; i += 2, port += 2) { +#endif if (unlikely(port >= high)) port -= remaining; if (inet_is_local_reserved_port(net, port)) @@ -1089,7 +1098,11 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, }
offset++; +#if IS_ENABLED(CONFIG_SYSCTL) if ((offset & 1) && remaining > 1 && span_size == 2) +#else + if ((offset & 1) && remaining > 1) +#endif goto other_parity_scan;
return -EADDRNOTAVAIL;