Skip to content

Commit 8059918

Browse files
committed
netfilter: nft_ct: sanitize layer 3 and 4 protocol number in custom expectations
- Disallow families other than NFPROTO_{IPV4,IPV6,INET}. - Disallow layer 4 protocol with no ports, since destination port is a mandatory attribute for this object. Fixes: 857b460 ("netfilter: nft_ct: add ct expectations support") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 259eb32 commit 8059918

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

net/netfilter/nft_ct.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,31 @@ static int nft_ct_expect_obj_init(const struct nft_ctx *ctx,
12501250
if (tb[NFTA_CT_EXPECT_L3PROTO])
12511251
priv->l3num = ntohs(nla_get_be16(tb[NFTA_CT_EXPECT_L3PROTO]));
12521252

1253+
switch (priv->l3num) {
1254+
case NFPROTO_IPV4:
1255+
case NFPROTO_IPV6:
1256+
if (priv->l3num != ctx->family)
1257+
return -EINVAL;
1258+
1259+
fallthrough;
1260+
case NFPROTO_INET:
1261+
break;
1262+
default:
1263+
return -EOPNOTSUPP;
1264+
}
1265+
12531266
priv->l4proto = nla_get_u8(tb[NFTA_CT_EXPECT_L4PROTO]);
1267+
switch (priv->l4proto) {
1268+
case IPPROTO_TCP:
1269+
case IPPROTO_UDP:
1270+
case IPPROTO_UDPLITE:
1271+
case IPPROTO_DCCP:
1272+
case IPPROTO_SCTP:
1273+
break;
1274+
default:
1275+
return -EOPNOTSUPP;
1276+
}
1277+
12541278
priv->dport = nla_get_be16(tb[NFTA_CT_EXPECT_DPORT]);
12551279
priv->timeout = nla_get_u32(tb[NFTA_CT_EXPECT_TIMEOUT]);
12561280
priv->size = nla_get_u8(tb[NFTA_CT_EXPECT_SIZE]);

0 commit comments

Comments
 (0)