* [PATCH 0/2] pull request for net: batman-adv 2019-08-30
@ 2019-08-30 7:25 Simon Wunderlich
2019-08-30 7:25 ` [PATCH 1/2] batman-adv: Only read OGM tvlv_len after buffer len check Simon Wunderlich
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Simon Wunderlich @ 2019-08-30 7:25 UTC (permalink / raw)
To: davem; +Cc: netdev, b.a.t.m.a.n, Simon Wunderlich
Hi David,
here is another small batman-adv pull request for net.
Please pull or let me know of any problem!
Thank you,
Simon
The following changes since commit 3ee1bb7aae97324ec9078da1f00cb2176919563f:
batman-adv: fix uninit-value in batadv_netlink_get_ifindex() (2019-08-14 19:27:07 +0200)
are available in the Git repository at:
git://git.open-mesh.org/linux-merge.git tags/batadv-net-for-davem-20190830
for you to fetch changes up to 0ff0f15a32c093381ad1abc06abe85afb561ab28:
batman-adv: Only read OGM2 tvlv_len after buffer len check (2019-08-23 18:20:31 +0200)
----------------------------------------------------------------
Here are two batman-adv bugfixes:
- Fix OGM and OGMv2 header read boundary check,
by Sven Eckelmann (2 patches)
----------------------------------------------------------------
Sven Eckelmann (2):
batman-adv: Only read OGM tvlv_len after buffer len check
batman-adv: Only read OGM2 tvlv_len after buffer len check
net/batman-adv/bat_iv_ogm.c | 20 +++++++++++++-------
net/batman-adv/bat_v_ogm.c | 18 ++++++++++++------
2 files changed, 25 insertions(+), 13 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] batman-adv: Only read OGM tvlv_len after buffer len check
2019-08-30 7:25 [PATCH 0/2] pull request for net: batman-adv 2019-08-30 Simon Wunderlich
@ 2019-08-30 7:25 ` Simon Wunderlich
2019-08-30 7:25 ` [PATCH 2/2] batman-adv: Only read OGM2 " Simon Wunderlich
2019-08-31 20:18 ` [PATCH 0/2] pull request for net: batman-adv 2019-08-30 David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Simon Wunderlich @ 2019-08-30 7:25 UTC (permalink / raw)
To: davem
Cc: netdev, b.a.t.m.a.n, Sven Eckelmann, syzbot+355cab184197dbbfa384,
Antonio Quartulli, Simon Wunderlich
From: Sven Eckelmann <sven@narfation.org>
Multiple batadv_ogm_packet can be stored in an skbuff. The functions
batadv_iv_ogm_send_to_if()/batadv_iv_ogm_receive() use
batadv_iv_ogm_aggr_packet() to check if there is another additional
batadv_ogm_packet in the skb or not before they continue processing the
packet.
The length for such an OGM is BATADV_OGM_HLEN +
batadv_ogm_packet->tvlv_len. The check must first check that at least
BATADV_OGM_HLEN bytes are available before it accesses tvlv_len (which is
part of the header. Otherwise it might try read outside of the currently
available skbuff to get the content of tvlv_len.
Fixes: ef26157747d4 ("batman-adv: tvlv - basic infrastructure")
Reported-by: syzbot+355cab184197dbbfa384@syzkaller.appspotmail.com
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Acked-by: Antonio Quartulli <a@unstable.cc>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/bat_iv_ogm.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 240ed70912d6..d78938e3e008 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -277,17 +277,23 @@ static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)
* batadv_iv_ogm_aggr_packet() - checks if there is another OGM attached
* @buff_pos: current position in the skb
* @packet_len: total length of the skb
- * @tvlv_len: tvlv length of the previously considered OGM
+ * @ogm_packet: potential OGM in buffer
*
* Return: true if there is enough space for another OGM, false otherwise.
*/
-static bool batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
- __be16 tvlv_len)
+static bool
+batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
+ const struct batadv_ogm_packet *ogm_packet)
{
int next_buff_pos = 0;
- next_buff_pos += buff_pos + BATADV_OGM_HLEN;
- next_buff_pos += ntohs(tvlv_len);
+ /* check if there is enough space for the header */
+ next_buff_pos += buff_pos + sizeof(*ogm_packet);
+ if (next_buff_pos > packet_len)
+ return false;
+
+ /* check if there is enough space for the optional TVLV */
+ next_buff_pos += ntohs(ogm_packet->tvlv_len);
return (next_buff_pos <= packet_len) &&
(next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
@@ -315,7 +321,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
/* adjust all flags and log packets */
while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
- batadv_ogm_packet->tvlv_len)) {
+ batadv_ogm_packet)) {
/* we might have aggregated direct link packets with an
* ordinary base packet
*/
@@ -1704,7 +1710,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
/* unpack the aggregated packets and process them one by one */
while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
- ogm_packet->tvlv_len)) {
+ ogm_packet)) {
batadv_iv_ogm_process(skb, ogm_offset, if_incoming);
ogm_offset += BATADV_OGM_HLEN;
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] batman-adv: Only read OGM2 tvlv_len after buffer len check
2019-08-30 7:25 [PATCH 0/2] pull request for net: batman-adv 2019-08-30 Simon Wunderlich
2019-08-30 7:25 ` [PATCH 1/2] batman-adv: Only read OGM tvlv_len after buffer len check Simon Wunderlich
@ 2019-08-30 7:25 ` Simon Wunderlich
2019-08-31 20:18 ` [PATCH 0/2] pull request for net: batman-adv 2019-08-30 David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Simon Wunderlich @ 2019-08-30 7:25 UTC (permalink / raw)
To: davem; +Cc: netdev, b.a.t.m.a.n, Sven Eckelmann, Simon Wunderlich
From: Sven Eckelmann <sven@narfation.org>
Multiple batadv_ogm2_packet can be stored in an skbuff. The functions
batadv_v_ogm_send_to_if() uses batadv_v_ogm_aggr_packet() to check if there
is another additional batadv_ogm2_packet in the skb or not before they
continue processing the packet.
The length for such an OGM2 is BATADV_OGM2_HLEN +
batadv_ogm2_packet->tvlv_len. The check must first check that at least
BATADV_OGM2_HLEN bytes are available before it accesses tvlv_len (which is
part of the header. Otherwise it might try read outside of the currently
available skbuff to get the content of tvlv_len.
Fixes: 9323158ef9f4 ("batman-adv: OGMv2 - implement originators logic")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/bat_v_ogm.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index fad95ef64e01..bc06e3cdfa84 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -631,17 +631,23 @@ batadv_v_ogm_process_per_outif(struct batadv_priv *bat_priv,
* batadv_v_ogm_aggr_packet() - checks if there is another OGM aggregated
* @buff_pos: current position in the skb
* @packet_len: total length of the skb
- * @tvlv_len: tvlv length of the previously considered OGM
+ * @ogm2_packet: potential OGM2 in buffer
*
* Return: true if there is enough space for another OGM, false otherwise.
*/
-static bool batadv_v_ogm_aggr_packet(int buff_pos, int packet_len,
- __be16 tvlv_len)
+static bool
+batadv_v_ogm_aggr_packet(int buff_pos, int packet_len,
+ const struct batadv_ogm2_packet *ogm2_packet)
{
int next_buff_pos = 0;
- next_buff_pos += buff_pos + BATADV_OGM2_HLEN;
- next_buff_pos += ntohs(tvlv_len);
+ /* check if there is enough space for the header */
+ next_buff_pos += buff_pos + sizeof(*ogm2_packet);
+ if (next_buff_pos > packet_len)
+ return false;
+
+ /* check if there is enough space for the optional TVLV */
+ next_buff_pos += ntohs(ogm2_packet->tvlv_len);
return (next_buff_pos <= packet_len) &&
(next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
@@ -818,7 +824,7 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb,
ogm_packet = (struct batadv_ogm2_packet *)skb->data;
while (batadv_v_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
- ogm_packet->tvlv_len)) {
+ ogm_packet)) {
batadv_v_ogm_process(skb, ogm_offset, if_incoming);
ogm_offset += BATADV_OGM2_HLEN;
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] pull request for net: batman-adv 2019-08-30
2019-08-30 7:25 [PATCH 0/2] pull request for net: batman-adv 2019-08-30 Simon Wunderlich
2019-08-30 7:25 ` [PATCH 1/2] batman-adv: Only read OGM tvlv_len after buffer len check Simon Wunderlich
2019-08-30 7:25 ` [PATCH 2/2] batman-adv: Only read OGM2 " Simon Wunderlich
@ 2019-08-31 20:18 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-08-31 20:18 UTC (permalink / raw)
To: sw; +Cc: netdev, b.a.t.m.a.n
From: Simon Wunderlich <sw@simonwunderlich.de>
Date: Fri, 30 Aug 2019 09:25:00 +0200
> here is another small batman-adv pull request for net.
>
> Please pull or let me know of any problem!
Pulled, thanks Simon.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-31 20:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30 7:25 [PATCH 0/2] pull request for net: batman-adv 2019-08-30 Simon Wunderlich
2019-08-30 7:25 ` [PATCH 1/2] batman-adv: Only read OGM tvlv_len after buffer len check Simon Wunderlich
2019-08-30 7:25 ` [PATCH 2/2] batman-adv: Only read OGM2 " Simon Wunderlich
2019-08-31 20:18 ` [PATCH 0/2] pull request for net: batman-adv 2019-08-30 David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).