Skip to content

Commit 776d451

Browse files
committed
netfilter: nf_tables: restrict tunnel object to NFPROTO_NETDEV
Bail out on using the tunnel dst template from other than netdev family. Add the infrastructure to check for the family in objects. Fixes: af308b9 ("netfilter: nf_tables: add tunnel support") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fb366fc commit 776d451

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ void nft_obj_notify(struct net *net, const struct nft_table *table,
13511351
* @type: stateful object numeric type
13521352
* @owner: module owner
13531353
* @maxattr: maximum netlink attribute
1354+
* @family: address family for AF-specific object types
13541355
* @policy: netlink attribute policy
13551356
*/
13561357
struct nft_object_type {
@@ -1360,6 +1361,7 @@ struct nft_object_type {
13601361
struct list_head list;
13611362
u32 type;
13621363
unsigned int maxattr;
1364+
u8 family;
13631365
struct module *owner;
13641366
const struct nla_policy *policy;
13651367
};

net/netfilter/nf_tables_api.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7551,23 +7551,27 @@ static int nft_object_dump(struct sk_buff *skb, unsigned int attr,
75517551
return -1;
75527552
}
75537553

7554-
static const struct nft_object_type *__nft_obj_type_get(u32 objtype)
7554+
static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family)
75557555
{
75567556
const struct nft_object_type *type;
75577557

75587558
list_for_each_entry(type, &nf_tables_objects, list) {
7559+
if (type->family != NFPROTO_UNSPEC &&
7560+
type->family != family)
7561+
continue;
7562+
75597563
if (objtype == type->type)
75607564
return type;
75617565
}
75627566
return NULL;
75637567
}
75647568

75657569
static const struct nft_object_type *
7566-
nft_obj_type_get(struct net *net, u32 objtype)
7570+
nft_obj_type_get(struct net *net, u32 objtype, u8 family)
75677571
{
75687572
const struct nft_object_type *type;
75697573

7570-
type = __nft_obj_type_get(objtype);
7574+
type = __nft_obj_type_get(objtype, family);
75717575
if (type != NULL && try_module_get(type->owner))
75727576
return type;
75737577

@@ -7660,7 +7664,7 @@ static int nf_tables_newobj(struct sk_buff *skb, const struct nfnl_info *info,
76607664
if (info->nlh->nlmsg_flags & NLM_F_REPLACE)
76617665
return -EOPNOTSUPP;
76627666

7663-
type = __nft_obj_type_get(objtype);
7667+
type = __nft_obj_type_get(objtype, family);
76647668
if (WARN_ON_ONCE(!type))
76657669
return -ENOENT;
76667670

@@ -7674,7 +7678,7 @@ static int nf_tables_newobj(struct sk_buff *skb, const struct nfnl_info *info,
76747678
if (!nft_use_inc(&table->use))
76757679
return -EMFILE;
76767680

7677-
type = nft_obj_type_get(net, objtype);
7681+
type = nft_obj_type_get(net, objtype, family);
76787682
if (IS_ERR(type)) {
76797683
err = PTR_ERR(type);
76807684
goto err_type;

net/netfilter/nft_tunnel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ static const struct nft_object_ops nft_tunnel_obj_ops = {
713713

714714
static struct nft_object_type nft_tunnel_obj_type __read_mostly = {
715715
.type = NFT_OBJECT_TUNNEL,
716+
.family = NFPROTO_NETDEV,
716717
.ops = &nft_tunnel_obj_ops,
717718
.maxattr = NFTA_TUNNEL_KEY_MAX,
718719
.policy = nft_tunnel_key_policy,

0 commit comments

Comments
 (0)