linux-stable/net
George Spelvin fd0c42c4de batman-adv: fix batadv_nc_random_weight_tq
and change to pseudorandom numbers, as this is a traffic dithering
operation that doesn't need crypto-grade.

The previous code operated in 4 steps:

1. Generate a random byte 0 <= rand_tq <= 255
2. Multiply it by BATADV_TQ_MAX_VALUE - tq
3. Divide by 255 (= BATADV_TQ_MAX_VALUE)
4. Return BATADV_TQ_MAX_VALUE - rand_tq

This would apperar to scale (BATADV_TQ_MAX_VALUE - tq) by a random
value between 0/255 and 255/255.

But!  The intermediate value between steps 3 and 4 is stored in a u8
variable.  So it's truncated, and most of the time, is less than 255, after
which the division produces 0.  Specifically, if tq is odd, the product is
always even, and can never be 255.  If tq is even, there's exactly one
random byte value that will produce a product byte of 255.

Thus, the return value is 255 (511/512 of the time) or 254 (1/512
of the time).

If we assume that the truncation is a bug, and the code is meant to scale
the input, a simpler way of looking at it is that it's returning a random
value between tq and BATADV_TQ_MAX_VALUE, inclusive.

Well, we have an optimized function for doing just that.

Fixes: 3c12de9a5c ("batman-adv: network coding - code and transmit packets if possible")
Signed-off-by: George Spelvin <lkml@sdf.org>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2020-04-21 10:08:04 +02:00
..
6lowpan
9p 9pnet: allow making incomplete read requests 2020-03-27 09:29:56 +00:00
802
8021q
appletalk
atm
ax25
batman-adv batman-adv: fix batadv_nc_random_weight_tq 2020-04-21 10:08:04 +02:00
bluetooth Bluetooth: L2CAP: Use DEFER_SETUP to group ECRED connections 2020-03-25 22:16:08 +01:00
bpf bpf: Fix build warning regarding missing prototypes 2020-03-28 18:13:18 +01:00
bpfilter SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
bridge
caif
can
ceph libceph: directly skip to the end of redirect reply 2020-03-30 12:42:41 +02:00
core neigh: support smaller retrans_time settting 2020-04-02 17:55:26 -07:00
dcb
dccp
decnet Remove DST_HOST 2020-03-23 21:57:44 -07:00
dns_resolver KEYS: Don't write out to userspace while holding key semaphore 2020-03-29 12:40:41 +01:00
dsa net: dsa: dsa_bridge_mtu_normalization() can be static 2020-04-02 06:51:56 -07:00
ethernet
ethtool ethtool: provide timestamping information with TSINFO_GET request 2020-03-29 22:32:37 -07:00
hsr Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-03-25 18:58:11 -07:00
ieee802154
ife
ipv4 Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-03-31 17:29:33 -07:00
ipv6 ipv6: rpl: fix loop iteration 2020-04-06 10:05:42 -07:00
iucv
kcm
key
l2tp
l3mdev
lapb
llc
mac80211 Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-03-30 20:48:43 -07:00
mac802154
mpls net: add net available in build_state 2020-03-29 22:30:57 -07:00
mptcp mptcp: add some missing pr_fmt defines 2020-04-03 16:06:32 -07:00
ncsi
netfilter x86: update AS_* macros to binutils >=2.23, supporting ADX and AVX2 2020-04-09 00:12:48 +09:00
netlabel
netlink Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-03-25 18:58:11 -07:00
netrom
nfc
nsh
openvswitch net: openvswitch: use hlist_for_each_entry_rcu instead of hlist_for_each_entry 2020-04-02 17:48:12 -07:00
packet
phonet
psample
qrtr
rds
rfkill
rose
rxrpc KEYS: Don't write out to userspace while holding key semaphore 2020-03-29 12:40:41 +01:00
sched net_sched: fix a missing refcnt in tcindex_init() 2020-04-03 16:00:08 -07:00
sctp Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-03-30 20:48:43 -07:00
smc
strparser
sunrpc NFS client updates for Linux 5.7 2020-04-07 13:51:39 -07:00
switchdev
tipc tipc: Add a missing case of TIPC_DIRECT_MSG type 2020-03-26 11:21:02 -07:00
tls net/tls: Annotate access to sk_prot with READ_ONCE/WRITE_ONCE 2020-03-21 20:08:17 -07:00
unix
vmw_vsock
wimax
wireless SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
x25
xdp
xfrm Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next 2020-03-30 10:59:20 -07:00
compat.c
Kconfig net: Fix CONFIG_NET_CLS_ACT=n and CONFIG_NFT_FWD_NETDEV={y, m} build 2020-03-25 12:24:33 -07:00
Makefile
socket.c for-5.7/io_uring-2020-03-29 2020-03-30 12:18:49 -07:00
sysctl_net.c