Skip to content

Commit 44991d6

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
Pablo Neira Ayuso says: ==================== Netfilter/IPVS fixes for net The following patchset contains Netfilter/IPVS fixes for net: 1) Fix incorrect sockopts unregistration from error path, from Florian Westphal. 2) A few patches to provide better error reporting when missing kernel netfilter options are missing in .config. 3) Fix dormant table flag updates. 4) Memleak in IPVS when adding service with IP_VS_SVC_F_HASHED flag. * git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf: ipvs: ignore IP_VS_SVC_F_HASHED flag when adding service netfilter: nf_tables: fix table flag updates netfilter: nf_tables: extended netlink error reporting for chain type netfilter: nf_tables: missing error reporting for not selected expressions netfilter: conntrack: unregister ipv4 sockopts on error unwind ==================== Link: https://lore.kernel.org/r/20210527190115.98503-1-pablo@netfilter.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents fb91702 + 56e4ee8 commit 44991d6

4 files changed

Lines changed: 59 additions & 35 deletions

File tree

‎include/net/netfilter/nf_tables.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,16 +1506,10 @@ struct nft_trans_chain {
15061506

15071507
struct nft_trans_table {
15081508
bool update;
1509-
u8 state;
1510-
u32 flags;
15111509
};
15121510

15131511
#define nft_trans_table_update(trans) \
15141512
(((struct nft_trans_table *)trans->data)->update)
1515-
#define nft_trans_table_state(trans) \
1516-
(((struct nft_trans_table *)trans->data)->state)
1517-
#define nft_trans_table_flags(trans) \
1518-
(((struct nft_trans_table *)trans->data)->flags)
15191513

15201514
struct nft_trans_elem {
15211515
struct nft_set *set;

‎net/netfilter/ipvs/ip_vs_ctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u,
13671367
ip_vs_addr_copy(svc->af, &svc->addr, &u->addr);
13681368
svc->port = u->port;
13691369
svc->fwmark = u->fwmark;
1370-
svc->flags = u->flags;
1370+
svc->flags = u->flags & ~IP_VS_SVC_F_HASHED;
13711371
svc->timeout = u->timeout * HZ;
13721372
svc->netmask = u->netmask;
13731373
svc->ipvs = ipvs;

‎net/netfilter/nf_conntrack_proto.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ int nf_conntrack_proto_init(void)
664664

665665
#if IS_ENABLED(CONFIG_IPV6)
666666
cleanup_sockopt:
667-
nf_unregister_sockopt(&so_getorigdst6);
667+
nf_unregister_sockopt(&so_getorigdst);
668668
#endif
669669
return ret;
670670
}

‎net/netfilter/nf_tables_api.c‎

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net,
736736
goto nla_put_failure;
737737

738738
if (nla_put_string(skb, NFTA_TABLE_NAME, table->name) ||
739-
nla_put_be32(skb, NFTA_TABLE_FLAGS, htonl(table->flags)) ||
739+
nla_put_be32(skb, NFTA_TABLE_FLAGS,
740+
htonl(table->flags & NFT_TABLE_F_MASK)) ||
740741
nla_put_be32(skb, NFTA_TABLE_USE, htonl(table->use)) ||
741742
nla_put_be64(skb, NFTA_TABLE_HANDLE, cpu_to_be64(table->handle),
742743
NFTA_TABLE_PAD))
@@ -947,20 +948,22 @@ static int nf_tables_table_enable(struct net *net, struct nft_table *table)
947948

948949
static void nf_tables_table_disable(struct net *net, struct nft_table *table)
949950
{
951+
table->flags &= ~NFT_TABLE_F_DORMANT;
950952
nft_table_disable(net, table, 0);
953+
table->flags |= NFT_TABLE_F_DORMANT;
951954
}
952955

953-
enum {
954-
NFT_TABLE_STATE_UNCHANGED = 0,
955-
NFT_TABLE_STATE_DORMANT,
956-
NFT_TABLE_STATE_WAKEUP
957-
};
956+
#define __NFT_TABLE_F_INTERNAL (NFT_TABLE_F_MASK + 1)
957+
#define __NFT_TABLE_F_WAS_DORMANT (__NFT_TABLE_F_INTERNAL << 0)
958+
#define __NFT_TABLE_F_WAS_AWAKEN (__NFT_TABLE_F_INTERNAL << 1)
959+
#define __NFT_TABLE_F_UPDATE (__NFT_TABLE_F_WAS_DORMANT | \
960+
__NFT_TABLE_F_WAS_AWAKEN)
958961

959962
static int nf_tables_updtable(struct nft_ctx *ctx)
960963
{
961964
struct nft_trans *trans;
962965
u32 flags;
963-
int ret = 0;
966+
int ret;
964967

965968
if (!ctx->nla[NFTA_TABLE_FLAGS])
966969
return 0;
@@ -985,21 +988,27 @@ static int nf_tables_updtable(struct nft_ctx *ctx)
985988

986989
if ((flags & NFT_TABLE_F_DORMANT) &&
987990
!(ctx->table->flags & NFT_TABLE_F_DORMANT)) {
988-
nft_trans_table_state(trans) = NFT_TABLE_STATE_DORMANT;
991+
ctx->table->flags |= NFT_TABLE_F_DORMANT;
992+
if (!(ctx->table->flags & __NFT_TABLE_F_UPDATE))
993+
ctx->table->flags |= __NFT_TABLE_F_WAS_AWAKEN;
989994
} else if (!(flags & NFT_TABLE_F_DORMANT) &&
990995
ctx->table->flags & NFT_TABLE_F_DORMANT) {
991-
ret = nf_tables_table_enable(ctx->net, ctx->table);
992-
if (ret >= 0)
993-
nft_trans_table_state(trans) = NFT_TABLE_STATE_WAKEUP;
996+
ctx->table->flags &= ~NFT_TABLE_F_DORMANT;
997+
if (!(ctx->table->flags & __NFT_TABLE_F_UPDATE)) {
998+
ret = nf_tables_table_enable(ctx->net, ctx->table);
999+
if (ret < 0)
1000+
goto err_register_hooks;
1001+
1002+
ctx->table->flags |= __NFT_TABLE_F_WAS_DORMANT;
1003+
}
9941004
}
995-
if (ret < 0)
996-
goto err;
9971005

998-
nft_trans_table_flags(trans) = flags;
9991006
nft_trans_table_update(trans) = true;
10001007
nft_trans_commit_list_add_tail(ctx->net, trans);
1008+
10011009
return 0;
1002-
err:
1010+
1011+
err_register_hooks:
10031012
nft_trans_destroy(trans);
10041013
return ret;
10051014
}
@@ -1905,7 +1914,7 @@ static int nft_chain_parse_netdev(struct net *net,
19051914
static int nft_chain_parse_hook(struct net *net,
19061915
const struct nlattr * const nla[],
19071916
struct nft_chain_hook *hook, u8 family,
1908-
bool autoload)
1917+
struct netlink_ext_ack *extack, bool autoload)
19091918
{
19101919
struct nftables_pernet *nft_net = nft_pernet(net);
19111920
struct nlattr *ha[NFTA_HOOK_MAX + 1];
@@ -1935,8 +1944,10 @@ static int nft_chain_parse_hook(struct net *net,
19351944
if (nla[NFTA_CHAIN_TYPE]) {
19361945
type = nf_tables_chain_type_lookup(net, nla[NFTA_CHAIN_TYPE],
19371946
family, autoload);
1938-
if (IS_ERR(type))
1947+
if (IS_ERR(type)) {
1948+
NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TYPE]);
19391949
return PTR_ERR(type);
1950+
}
19401951
}
19411952
if (hook->num >= NFT_MAX_HOOKS || !(type->hook_mask & (1 << hook->num)))
19421953
return -EOPNOTSUPP;
@@ -1945,8 +1956,11 @@ static int nft_chain_parse_hook(struct net *net,
19451956
hook->priority <= NF_IP_PRI_CONNTRACK)
19461957
return -EOPNOTSUPP;
19471958

1948-
if (!try_module_get(type->owner))
1959+
if (!try_module_get(type->owner)) {
1960+
if (nla[NFTA_CHAIN_TYPE])
1961+
NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TYPE]);
19491962
return -ENOENT;
1963+
}
19501964

19511965
hook->type = type;
19521966

@@ -2057,7 +2071,8 @@ static int nft_chain_add(struct nft_table *table, struct nft_chain *chain)
20572071
static u64 chain_id;
20582072

20592073
static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
2060-
u8 policy, u32 flags)
2074+
u8 policy, u32 flags,
2075+
struct netlink_ext_ack *extack)
20612076
{
20622077
const struct nlattr * const *nla = ctx->nla;
20632078
struct nft_table *table = ctx->table;
@@ -2079,7 +2094,8 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
20792094
if (flags & NFT_CHAIN_BINDING)
20802095
return -EOPNOTSUPP;
20812096

2082-
err = nft_chain_parse_hook(net, nla, &hook, family, true);
2097+
err = nft_chain_parse_hook(net, nla, &hook, family, extack,
2098+
true);
20832099
if (err < 0)
20842100
return err;
20852101

@@ -2234,7 +2250,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
22342250
return -EEXIST;
22352251
}
22362252
err = nft_chain_parse_hook(ctx->net, nla, &hook, ctx->family,
2237-
false);
2253+
extack, false);
22382254
if (err < 0)
22392255
return err;
22402256

@@ -2447,7 +2463,7 @@ static int nf_tables_newchain(struct sk_buff *skb, const struct nfnl_info *info,
24472463
extack);
24482464
}
24492465

2450-
return nf_tables_addchain(&ctx, family, genmask, policy, flags);
2466+
return nf_tables_addchain(&ctx, family, genmask, policy, flags, extack);
24512467
}
24522468

24532469
static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,
@@ -3328,8 +3344,10 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
33283344
if (n == NFT_RULE_MAXEXPRS)
33293345
goto err1;
33303346
err = nf_tables_expr_parse(&ctx, tmp, &expr_info[n]);
3331-
if (err < 0)
3347+
if (err < 0) {
3348+
NL_SET_BAD_ATTR(extack, tmp);
33323349
goto err1;
3350+
}
33333351
size += expr_info[n].ops->size;
33343352
n++;
33353353
}
@@ -8547,10 +8565,14 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
85478565
switch (trans->msg_type) {
85488566
case NFT_MSG_NEWTABLE:
85498567
if (nft_trans_table_update(trans)) {
8550-
if (nft_trans_table_state(trans) == NFT_TABLE_STATE_DORMANT)
8568+
if (!(trans->ctx.table->flags & __NFT_TABLE_F_UPDATE)) {
8569+
nft_trans_destroy(trans);
8570+
break;
8571+
}
8572+
if (trans->ctx.table->flags & NFT_TABLE_F_DORMANT)
85518573
nf_tables_table_disable(net, trans->ctx.table);
85528574

8553-
trans->ctx.table->flags = nft_trans_table_flags(trans);
8575+
trans->ctx.table->flags &= ~__NFT_TABLE_F_UPDATE;
85548576
} else {
85558577
nft_clear(net, trans->ctx.table);
85568578
}
@@ -8768,9 +8790,17 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
87688790
switch (trans->msg_type) {
87698791
case NFT_MSG_NEWTABLE:
87708792
if (nft_trans_table_update(trans)) {
8771-
if (nft_trans_table_state(trans) == NFT_TABLE_STATE_WAKEUP)
8793+
if (!(trans->ctx.table->flags & __NFT_TABLE_F_UPDATE)) {
8794+
nft_trans_destroy(trans);
8795+
break;
8796+
}
8797+
if (trans->ctx.table->flags & __NFT_TABLE_F_WAS_DORMANT) {
87728798
nf_tables_table_disable(net, trans->ctx.table);
8773-
8799+
trans->ctx.table->flags |= NFT_TABLE_F_DORMANT;
8800+
} else if (trans->ctx.table->flags & __NFT_TABLE_F_WAS_AWAKEN) {
8801+
trans->ctx.table->flags &= ~NFT_TABLE_F_DORMANT;
8802+
}
8803+
trans->ctx.table->flags &= ~__NFT_TABLE_F_UPDATE;
87748804
nft_trans_destroy(trans);
87758805
} else {
87768806
list_del_rcu(&trans->ctx.table->list);

0 commit comments

Comments
 (0)