Skip to contentSkip to conversation

owner: Fix potential array out of bounds access

PATCH In review Pablo Neira Ayuso 1 participant 2 messages Dec 21, 2022 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 owner: Fix potential array out of bounds access

If the link target length exceeds 'sizeof(tmp)' bytes, readlink() will return 'sizeof(tmp)'. Using this value as index is illegal.

Original update from Phil, for the conntrack-tools tree, which also has a copy of this function.

Fixes 6d085b22a8b5 ("table: support for the table owner flag")

---
Same as:

https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/

 src/owner.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/owner.c +1 -1
index 2d98a2e98028..20bed38b2a09 100644
@@ -66,7 +66,7 @@ static char *portid2name(pid_t pid, uint32_t portid, unsigned long inode)
 			continue;
 
 		rl = readlink(procname, tmp, sizeof(tmp));
-		if (rl <= 0 || rl > (ssize_t)sizeof(tmp))
+		if (rl <= 0 || rl >= (ssize_t)sizeof(tmp))
 			continue;
 
 		tmp[rl] = 0;
Signature · 1 line
2.30.2
author maintainer
#1 lore raw
Quoted 5 lines · Pablo Neira Ayuso

If the link target length exceeds 'sizeof(tmp)' bytes, readlink() will return 'sizeof(tmp)'. Using this value as index is illegal.

Original update from Phil, for the conntrack-tools tree, which also has a copy of this function.

For the record: If this code is generalized, this code is a candidate for libmnl I think.