All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] pull request for net: batman-adv 2020-04-27
@ 2020-04-27 15:00 ` Simon Wunderlich
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2020-04-27 15:00 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Simon Wunderlich

Hi David,

here are some bugfixes which we would like to have integrated into net.

Please pull or let me know of any problem!

Thank you,
      Simon

The following changes since commit 8f3d9f354286745c751374f5f1fcafee6b3f3136:

  Linux 5.7-rc1 (2020-04-12 12:35:55 -0700)

are available in the Git repository at:

  git://git.open-mesh.org/linux-merge.git tags/batadv-net-for-davem-20200427

for you to fetch changes up to 6f91a3f7af4186099dd10fa530dd7e0d9c29747d:

  batman-adv: Fix refcnt leak in batadv_v_ogm_process (2020-04-21 10:08:05 +0200)

----------------------------------------------------------------
Here are some batman-adv bugfixes:

 - fix random number generation in network coding, by George Spelvin

 - fix reference counter leaks, by Xiyu Yang (3 patches)

----------------------------------------------------------------
George Spelvin (1):
      batman-adv: fix batadv_nc_random_weight_tq

Xiyu Yang (3):
      batman-adv: Fix refcnt leak in batadv_show_throughput_override
      batman-adv: Fix refcnt leak in batadv_store_throughput_override
      batman-adv: Fix refcnt leak in batadv_v_ogm_process

 net/batman-adv/bat_v_ogm.c      | 2 +-
 net/batman-adv/network-coding.c | 9 +--------
 net/batman-adv/sysfs.c          | 3 ++-
 3 files changed, 4 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/4] pull request for net: batman-adv 2020-04-27
@ 2020-04-27 15:00 ` Simon Wunderlich
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2020-04-27 15:00 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n

Hi David,

here are some bugfixes which we would like to have integrated into net.

Please pull or let me know of any problem!

Thank you,
      Simon

The following changes since commit 8f3d9f354286745c751374f5f1fcafee6b3f3136:

  Linux 5.7-rc1 (2020-04-12 12:35:55 -0700)

are available in the Git repository at:

  git://git.open-mesh.org/linux-merge.git tags/batadv-net-for-davem-20200427

for you to fetch changes up to 6f91a3f7af4186099dd10fa530dd7e0d9c29747d:

  batman-adv: Fix refcnt leak in batadv_v_ogm_process (2020-04-21 10:08:05 +0200)

----------------------------------------------------------------
Here are some batman-adv bugfixes:

 - fix random number generation in network coding, by George Spelvin

 - fix reference counter leaks, by Xiyu Yang (3 patches)

----------------------------------------------------------------
George Spelvin (1):
      batman-adv: fix batadv_nc_random_weight_tq

Xiyu Yang (3):
      batman-adv: Fix refcnt leak in batadv_show_throughput_override
      batman-adv: Fix refcnt leak in batadv_store_throughput_override
      batman-adv: Fix refcnt leak in batadv_v_ogm_process

 net/batman-adv/bat_v_ogm.c      | 2 +-
 net/batman-adv/network-coding.c | 9 +--------
 net/batman-adv/sysfs.c          | 3 ++-
 3 files changed, 4 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] batman-adv: fix batadv_nc_random_weight_tq
  2020-04-27 15:00 ` Simon Wunderlich
  (?)
@ 2020-04-27 15:00 ` Simon Wunderlich
  -1 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2020-04-27 15:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, b.a.t.m.a.n, George Spelvin, Sven Eckelmann, Simon Wunderlich

From: George Spelvin <lkml@sdf.org>

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: 3c12de9a5c75 ("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>
---
 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 8f0717c3f7b5..b0469d15da0e 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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] batman-adv: Fix refcnt leak in batadv_show_throughput_override
  2020-04-27 15:00 ` Simon Wunderlich
  (?)
  (?)
@ 2020-04-27 15:00 ` Simon Wunderlich
  -1 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2020-04-27 15:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, b.a.t.m.a.n, Xiyu Yang, Xin Tan, Sven Eckelmann,
	Simon Wunderlich

From: Xiyu Yang <xiyuyang19@fudan.edu.cn>

batadv_show_throughput_override() invokes batadv_hardif_get_by_netdev(),
which gets a batadv_hard_iface object from net_dev with increased refcnt
and its reference is assigned to a local pointer 'hard_iface'.

When batadv_show_throughput_override() returns, "hard_iface" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The issue happens in the normal path of
batadv_show_throughput_override(), which forgets to decrease the refcnt
increased by batadv_hardif_get_by_netdev() before the function returns,
causing a refcnt leak.

Fix this issue by calling batadv_hardif_put() before the
batadv_show_throughput_override() returns in the normal path.

Fixes: 0b5ecc6811bd ("batman-adv: add throughput override attribute to hard_ifaces")
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index c45962d8527b..c0b00268aac4 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -1190,6 +1190,7 @@ static ssize_t batadv_show_throughput_override(struct kobject *kobj,
 
 	tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
 
+	batadv_hardif_put(hard_iface);
 	return sprintf(buff, "%u.%u MBit\n", tp_override / 10,
 		       tp_override % 10);
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] batman-adv: Fix refcnt leak in batadv_store_throughput_override
  2020-04-27 15:00 ` Simon Wunderlich
                   ` (2 preceding siblings ...)
  (?)
@ 2020-04-27 15:00 ` Simon Wunderlich
  -1 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2020-04-27 15:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, b.a.t.m.a.n, Xiyu Yang, Xin Tan, Sven Eckelmann,
	Simon Wunderlich

From: Xiyu Yang <xiyuyang19@fudan.edu.cn>

batadv_show_throughput_override() invokes batadv_hardif_get_by_netdev(),
which gets a batadv_hard_iface object from net_dev with increased refcnt
and its reference is assigned to a local pointer 'hard_iface'.

When batadv_store_throughput_override() returns, "hard_iface" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The issue happens in one error path of
batadv_store_throughput_override(). When batadv_parse_throughput()
returns NULL, the refcnt increased by batadv_hardif_get_by_netdev() is
not decreased, causing a refcnt leak.

Fix this issue by jumping to "out" label when batadv_parse_throughput()
returns NULL.

Fixes: 0b5ecc6811bd ("batman-adv: add throughput override attribute to hard_ifaces")
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index c0b00268aac4..0f962dcd239e 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -1150,7 +1150,7 @@ static ssize_t batadv_store_throughput_override(struct kobject *kobj,
 	ret = batadv_parse_throughput(net_dev, buff, "throughput_override",
 				      &tp_override);
 	if (!ret)
-		return count;
+		goto out;
 
 	old_tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
 	if (old_tp_override == tp_override)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] batman-adv: Fix refcnt leak in batadv_v_ogm_process
  2020-04-27 15:00 ` Simon Wunderlich
                   ` (3 preceding siblings ...)
  (?)
@ 2020-04-27 15:00 ` Simon Wunderlich
  -1 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2020-04-27 15:00 UTC (permalink / raw)
  To: davem
  Cc: netdev, b.a.t.m.a.n, Xiyu Yang, Xin Tan, Sven Eckelmann,
	Simon Wunderlich

From: Xiyu Yang <xiyuyang19@fudan.edu.cn>

batadv_v_ogm_process() invokes batadv_hardif_neigh_get(), which returns
a reference of the neighbor object to "hardif_neigh" with increased
refcount.

When batadv_v_ogm_process() returns, "hardif_neigh" becomes invalid, so
the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one exception handling paths of
batadv_v_ogm_process(). When batadv_v_ogm_orig_get() fails to get the
orig node and returns NULL, the refcnt increased by
batadv_hardif_neigh_get() is not decreased, causing a refcnt leak.

Fix this issue by jumping to "out" label when batadv_v_ogm_orig_get()
fails to get the orig node.

Fixes: 9323158ef9f4 ("batman-adv: OGMv2 - implement originators logic")
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/bat_v_ogm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index 969466218999..80b87b1f4e3a 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -893,7 +893,7 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
 
 	orig_node = batadv_v_ogm_orig_get(bat_priv, ogm_packet->orig);
 	if (!orig_node)
-		return;
+		goto out;
 
 	neigh_node = batadv_neigh_node_get_or_create(orig_node, if_incoming,
 						     ethhdr->h_source);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] pull request for net: batman-adv 2020-04-27
  2020-04-27 15:00 ` Simon Wunderlich
                   ` (4 preceding siblings ...)
  (?)
@ 2020-04-27 20:03 ` David Miller
  -1 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2020-04-27 20:03 UTC (permalink / raw)
  To: sw; +Cc: netdev, b.a.t.m.a.n

From: Simon Wunderlich <sw@simonwunderlich.de>
Date: Mon, 27 Apr 2020 17:00:35 +0200

> here are some bugfixes which we would like to have integrated into net.
> 
> Please pull or let me know of any problem!

Pulled, thanks Simon.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-27 20:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 15:00 [PATCH 0/4] pull request for net: batman-adv 2020-04-27 Simon Wunderlich
2020-04-27 15:00 ` Simon Wunderlich
2020-04-27 15:00 ` [PATCH 1/4] batman-adv: fix batadv_nc_random_weight_tq Simon Wunderlich
2020-04-27 15:00 ` [PATCH 2/4] batman-adv: Fix refcnt leak in batadv_show_throughput_override Simon Wunderlich
2020-04-27 15:00 ` [PATCH 3/4] batman-adv: Fix refcnt leak in batadv_store_throughput_override Simon Wunderlich
2020-04-27 15:00 ` [PATCH 4/4] batman-adv: Fix refcnt leak in batadv_v_ogm_process Simon Wunderlich
2020-04-27 20:03 ` [PATCH 0/4] pull request for net: batman-adv 2020-04-27 David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.