Skip to contentSkip to conversation

conntrack: add sanity check to netlink socket filter API

PATCH New Pablo Neira Ayuso 1 participant 1 message Jan 11, 2023 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 conntrack: add sanity check to netlink socket filter API

Validate that filtering by layer 4 protocol number and protocol state fits into the existing maps that is used internally.

---
 src/conntrack/filter.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
src/conntrack/filter.c +15 -2
index 4cbc116454cf..57b22945fc3b 100644
@@ -11,18 +11,31 @@
 
 static void filter_attr_l4proto(struct nfct_filter *filter, const void *value)
 {
+	int protonum;
+
 	if (filter->l4proto_len >= __FILTER_L4PROTO_MAX)
 		return;
 
-	set_bit(*((int *) value), filter->l4proto_map);
+	protonum = *(int *)value;
+	if (protonum >= IPPROTO_MAX)
+		return;
+
+	set_bit(protonum, filter->l4proto_map);
 	filter->l4proto_len++;
 }
 
-static void 
+#ifndef BITS_PER_BYTE
+#define BITS_PER_BYTE	8
+#endif
+
+static void
 filter_attr_l4proto_state(struct nfct_filter *filter, const void *value)
 {
 	const struct nfct_filter_proto *this = value;
 
+	if (this->state >= sizeof(filter->l4proto_state[0].map) * BITS_PER_BYTE)
+		return;
+
 	set_bit_u16(this->state, &filter->l4proto_state[this->proto].map);
 	filter->l4proto_state[this->proto].len++;
 }
Signature · 1 line
2.30.2