Skip to content

Commit

Permalink
netfilter: nf_tables: do not allow to delete table with owner by handle
Browse files Browse the repository at this point in the history
nft_table_lookup_byhandle() also needs to validate the netlink PortID
owner when deleting a table by handle.

Fixes: 6001a93 ("netfilter: nftables: introduce table ownership")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
ummakynes authored and intel-lab-lkp committed Jun 22, 2021
1 parent 47fa869 commit cdd859c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions net/netfilter/nf_tables_api.c
Expand Up @@ -583,15 +583,19 @@ static struct nft_table *nft_table_lookup(const struct net *net,

static struct nft_table *nft_table_lookup_byhandle(const struct net *net,
const struct nlattr *nla,
u8 genmask)
u8 genmask, u32 nlpid)
{
struct nftables_pernet *nft_net;
struct nft_table *table;

nft_net = nft_pernet(net);
list_for_each_entry(table, &nft_net->tables, list) {
if (be64_to_cpu(nla_get_be64(nla)) == table->handle &&
nft_active_genmask(table, genmask))
nft_active_genmask(table, genmask)) {
if (nft_table_has_owner(table) &&
nlpid && table->nlpid != nlpid)
return ERR_PTR(-EPERM);

return table;
}

Expand Down Expand Up @@ -1279,7 +1283,8 @@ static int nf_tables_deltable(struct sk_buff *skb, const struct nfnl_info *info,

if (nla[NFTA_TABLE_HANDLE]) {
attr = nla[NFTA_TABLE_HANDLE];
table = nft_table_lookup_byhandle(net, attr, genmask);
table = nft_table_lookup_byhandle(net, attr, genmask,
NETLINK_CB(skb).portid);
} else {
attr = nla[NFTA_TABLE_NAME];
table = nft_table_lookup(net, attr, family, genmask,
Expand Down

0 comments on commit cdd859c

Please sign in to comment.