Repository : ssh://git@diktynna/batman-adv
On branch : master
>---------------------------------------------------------------
commit db48c60b0edb995450ee846157364bd09bb23762
Author: George Spelvin <lkml(a)sdf.org>
Date: Sun Mar 8 09:44:59 2020 -0400
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: c3289f3650d3 ("batman-adv: network coding - code and transmit packets if possible")
Signed-off-by: George Spelvin <lkml(a)sdf.org>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
>---------------------------------------------------------------
db48c60b0edb995450ee846157364bd09bb23762
net/batman-adv/network-coding.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 8f0717c3..b0469d15 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -1009,15 +1009,8 @@ static struct batadv_nc_path *batadv_nc_get_path(struct batadv_priv *bat_priv,
*/
static u8 batadv_nc_random_weight_tq(u8 tq)
{
- u8 rand_val, rand_tq;
-
- get_random_bytes(&rand_val, sizeof(rand_val));
-
/* randomize the estimated packet loss (max TQ - estimated TQ) */
- rand_tq = rand_val * (BATADV_TQ_MAX_VALUE - tq);
-
- /* normalize the randomized packet loss */
- rand_tq /= BATADV_TQ_MAX_VALUE;
+ u8 rand_tq = prandom_u32_max(BATADV_TQ_MAX_VALUE + 1 - tq);
/* convert to (randomized) estimated tq again */
return BATADV_TQ_MAX_VALUE - rand_tq;
The annotated tag, v5.7-rc1 has been created
at 424aeb7bac4af3be0964d0b578a385efb0b82930 (tag)
tagging 8f3d9f354286745c751374f5f1fcafee6b3f3136 (commit)
replaces v5.6
tagged by Linus Torvalds
on Sun Apr 12 12:36:05 2020 -0700
- Shortlog ------------------------------------------------------------
Linux 5.7-rc1
-----BEGIN PGP SIGNATURE-----
iQFSBAABCAA8FiEEq68RxlopcLEwq+PEeb4+QwBBGIYFAl6TbaUeHHRvcnZhbGRz
QGxpbnV4LWZvdW5kYXRpb24ub3JnAAoJEHm+PkMAQRiGhgkH/iWpiKvosA20HJjC
rBqYeJPxQsgZTuBieWJ+MeVxbpcF7RlM4c+glyvg3QJhHwIEG58dl6LBrQbAyBAR
aFHNojr1iAYOruVCGnU3pA008YZiwUIDv/ZQ4DF8fmIU2vI2mJ6qHBv3XDl4G2uR
Nwz8Eu9AgIwZM5coomVOSmoWyFy7Vxmb7W+3t5VmKsvOWx4ib9kyQtOIkvQDEl7j
XCbWfI0xDQr6LFOm4jnCi5R/LhJ2LIqqIvHHrunbpszM8IwK797jCXz4im+dmd5Y
+km46N7a8pDqri36xXz1gdBAU3eG7Pt1NyvfjwRVTdX4GquQ2MT0GoojxbLxUP3y
3pEsQuE=
=whbL
-----END PGP SIGNATURE-----
David S. Miller (1):
Merge git://git.kernel.org/.../netdev/net
Gustavo A. R. Silva (1):
batman-adv: Replace zero-length array with flexible-array member
Simon Wunderlich (1):
batman-adv: Start new development cycle
Sven Eckelmann (1):
batman-adv: Avoid RCU list-traversal in spinlock
-----------------------------------------------------------------------
--
linux integration