Skip to contentSkip to conversation

net: tipc: fix possible infoleak in tipc_mon_rcv()

PATCH In review Hangyu Hua 3 participants 5 messages Jun 28, 2022 – Jun 30, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH v2 1/1 net: tipc: fix possible infoleak in tipc_mon_rcv()

dom_bef is use to cache current domain record only if current domain exists. But when current domain does not exist, dom_bef will still be used in mon_identify_lost_members. This may lead to an information leak.

Fix this by adding a memset before using dom_bef.

Fixes 35c55c9877f8 ("tipc: add neighbor monitoring framework")

---

v2: remove redundant 'dom_bef.member_cnt = 0;'

 net/tipc/monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/monitor.c +1 -1
index 2f4d23238a7e..03b5d0b65169 100644
@@ -534,7 +534,7 @@ void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
 	state->peer_gen = new_gen;
 
 	/* Cache current domain record for later use */
-	dom_bef.member_cnt = 0;
+	memset(&dom_bef, 0, sizeof(dom_bef));
 	dom = peer->domain;
 	if (dom)
 		memcpy(&dom_bef, dom, dom->len);
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 37 lines

-----Original Message-----
From: Hangyu Hua <[email protected]>
Sent: Tuesday, June 28, 2022 3:31 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Tung Quang Nguyen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Hangyu Hua <[email protected]>
Subject: [PATCH v2] net: tipc: fix possible infoleak in tipc_mon_rcv()

dom_bef is use to cache current domain record only if current domain exists. But when current domain does not exist, dom_bef will still be used in mon_identify_lost_members. This may lead to an information leak.

Fix this by adding a memset before using dom_bef.

Fixes 35c55c9877f8 ("tipc: add neighbor monitoring framework")

---

v2: remove redundant 'dom_bef.member_cnt = 0;'

 net/tipc/monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/monitor.c +1 -2
index 2f4d23238a7e..03b5d0b65169 100644
@@ -534,7 +534,7 @@ void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
 	state->peer_gen = new_gen;
 
 	/* Cache current domain record for later use */
-	dom_bef.member_cnt = 0;
+	memset(&dom_bef, 0, sizeof(dom_bef));
 	dom = peer->domain;
 	if (dom)
 		memcpy(&dom_bef, dom, dom->len);
--
Quoted 1 line

2.25.1

maintainer
#2 lore raw
In reply to Hangyu Hua
Quoted 3 lines · On Tue, 28 Jun 2022 16:31:22 +0800 Hangyu Hua wrote:

dom_bef is use to cache current domain record only if current domain exists. But when current domain does not exist, dom_bef will still be used in mon_identify_lost_members. This may lead to an information leak.

AFAICT applied_bef must be zero if peer->domain was 0, so I don't think mon_identify_lost_members() will do anything.

Quoted 4 lines

Fix this by adding a memset before using dom_bef.

Fixes 35c55c9877f8 ("tipc: add neighbor monitoring framework")
author
#3 lore raw
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 28 Jun 2022 16:31:22 +0800 Hangyu Hua wrote:

dom_bef is use to cache current domain record only if current domain exists. But when current domain does not exist, dom_bef will still be used in mon_identify_lost_members. This may lead to an information leak.

AFAICT applied_bef must be zero if peer->domain was 0, so I don't think mon_identify_lost_members() will do anything.

void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
struct tipc_mon_state *state, int bearer_id)
{
...

	if (!dom || (dom->len < new_dlen)) {
		kfree(dom);
		dom = kmalloc(new_dlen, GFP_ATOMIC);	<--- [1]
		peer->domain = dom;
		if (!dom)
			goto exit;
	}

...
}

peer->domain will be NULL when [1] fails. But there will not change peer->applied to 0. In this case, if tipc_mon_rcv is called again then an information leak will happen.

Thanks,
Hangyu.

Quoted 4 lines
Quoted 4 lines

Fix this by adding a memset before using dom_bef.

Fixes 35c55c9877f8 ("tipc: add neighbor monitoring framework")
maintainer
#4 lore raw
Quoted 21 lines · On Thu, 30 Jun 2022 17:19:21 +0800 Hangyu Hua wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 28 Jun 2022 16:31:22 +0800 Hangyu Hua wrote:

dom_bef is use to cache current domain record only if current domain exists. But when current domain does not exist, dom_bef will still be used in mon_identify_lost_members. This may lead to an information leak.

AFAICT applied_bef must be zero if peer->domain was 0, so I don't think mon_identify_lost_members() will do anything.

void tipc_mon_rcv(struct net *net, void *data, u16 dlen, u32 addr,
struct tipc_mon_state *state, int bearer_id)
{
...

	if (!dom || (dom->len < new_dlen)) {
		kfree(dom);
		dom = kmalloc(new_dlen, GFP_ATOMIC);	<--- [1]
		peer->domain = dom;
		if (!dom)
			goto exit;
	}
Quoted 6 lines

...
}

peer->domain will be NULL when [1] fails. But there will not change peer->applied to 0. In this case, if tipc_mon_rcv is called again then an information leak will happen.

I see, good analysis! Jon, Xue - is there a reason domain gets wiped on memory allocation failure? I'd think we should leave the previous pointer in place instead of freeing it first.