Skip to contentSkip to conversation

netfilter: nf_tables: fix loop checking with set element data

PATCH In review Pablo Neira Ayuso 2 participants 4 messages Feb 7, 2014

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: fix loop checking with set element data

This patch fixes two bugs:

* Restrict the validation to verdict maps only, since struct nft_data is declared as a union, data[0] may contain the values -3 or -4 which match with NFT_JUMP and NFT_GOTO. I think this will result in crash while performing the chain loop validation.

* Access to uninitialized data for end interval elements. The element data part is uninitialized in interval end elements.

---
 net/netfilter/nf_tables_api.c |    5 +++++
 1 file changed, 5 insertions(+)
net/netfilter/nf_tables_api.c +5 -0
index d0c790e3e..522becb 100644
@@ -2998,6 +2998,11 @@ static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx,
 					const struct nft_set_iter *iter,
 					const struct nft_set_elem *elem)
 {
+	if (!(set->flags & NFT_SET_MAP) ||
+	    set->dtype != NFT_DATA_VERDICT ||
+	    elem->flags & NFT_SET_ELEM_INTERVAL_END)
+		return 0;
+
 	switch (elem->data.verdict) {
 	case NFT_JUMP:
 	case NFT_GOTO:
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 10 lines · Pablo Neira Ayuso

This patch fixes two bugs:

* Restrict the validation to verdict maps only, since struct nft_data is declared as a union, data[0] may contain the values -3 or -4 which match with NFT_JUMP and NFT_GOTO. I think this will result in crash while performing the chain loop validation.

* Access to uninitialized data for end interval elements. The element data part is uninitialized in interval end elements.

That's not necessary. The function is only invoked for NFT_DATA_VERDICT.

Quoted 23 lines
---
 net/netfilter/nf_tables_api.c |    5 +++++
 1 file changed, 5 insertions(+)
net/netfilter/nf_tables_api.c +5 -0
index d0c790e3e..522becb 100644
@@ -2998,6 +2998,11 @@ static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx,
 					const struct nft_set_iter *iter,
 					const struct nft_set_elem *elem)
 {
+	if (!(set->flags & NFT_SET_MAP) ||
+	    set->dtype != NFT_DATA_VERDICT ||
+	    elem->flags & NFT_SET_ELEM_INTERVAL_END)
+		return 0;
+
 	switch (elem->data.verdict) {
 	case NFT_JUMP:
 	case NFT_GOTO:
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 20 lines · Patrick McHardy
Quoted 10 lines · Pablo Neira Ayuso

This patch fixes two bugs:

* Restrict the validation to verdict maps only, since struct nft_data is declared as a union, data[0] may contain the values -3 or -4 which match with NFT_JUMP and NFT_GOTO. I think this will result in crash while performing the chain loop validation.

* Access to uninitialized data for end interval elements. The element data part is uninitialized in interval end elements.

That's not necessary. The function is only invoked for NFT_DATA_VERDICT.

Quoted 5 lines
---
 net/netfilter/nf_tables_api.c |    5 +++++
 1 file changed, 5 insertions(+)
Quoted 13 lines

net/netfilter/nf_tables_api.c static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx, · line 3005

Quoted 13 lines
net/netfilter/nf_tables_api.c +5 -0
index d0c790e3e..522becb 100644
@@ -2998,6 +2998,11 @@ static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx,
 					const struct nft_set_iter *iter,
 					const struct nft_set_elem *elem)
 {
+	if (!(set->flags & NFT_SET_MAP) ||
+	    set->dtype != NFT_DATA_VERDICT ||
+	    elem->flags & NFT_SET_ELEM_INTERVAL_END)
+		return 0;
+

Right, I get the intention now.

This function is only called for maps with dtype verdict, so just the check for SET_ELEM_INTERVAL_END is all we need.

Quoted 9 lines
Quoted 5 lines
net/netfilter/nf_tables_api.c +0 -0
 	switch (elem->data.verdict) {
 	case NFT_JUMP:
 	case NFT_GOTO:
Signature · 1 line
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#3 lore raw
Quoted 37 lines · Patrick McHardy
Quoted 20 lines · Patrick McHardy
Quoted 10 lines · Pablo Neira Ayuso

This patch fixes two bugs:

* Restrict the validation to verdict maps only, since struct nft_data is declared as a union, data[0] may contain the values -3 or -4 which match with NFT_JUMP and NFT_GOTO. I think this will result in crash while performing the chain loop validation.

* Access to uninitialized data for end interval elements. The element data part is uninitialized in interval end elements.

That's not necessary. The function is only invoked for NFT_DATA_VERDICT.

Quoted 5 lines
---
 net/netfilter/nf_tables_api.c |    5 +++++
 1 file changed, 5 insertions(+)
Quoted 13 lines

net/netfilter/nf_tables_api.c static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx, · line 3005

Quoted 13 lines
net/netfilter/nf_tables_api.c +5 -0
index d0c790e3e..522becb 100644
@@ -2998,6 +2998,11 @@ static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx,
 					const struct nft_set_iter *iter,
 					const struct nft_set_elem *elem)
 {
+	if (!(set->flags & NFT_SET_MAP) ||
+	    set->dtype != NFT_DATA_VERDICT ||
+	    elem->flags & NFT_SET_ELEM_INTERVAL_END)
+		return 0;
+

Right, I get the intention now.

Quoted 2 lines

This function is only called for maps with dtype verdict, so just the check for SET_ELEM_INTERVAL_END is all we need.

Right, I overlook this:

        list_for_each_entry(set, &ctx->table->sets, list) {
                if (!(set->flags & NFT_SET_MAP) ||
                    set->dtype != NFT_DATA_VERDICT)
                        continue;

at the top of nf_tables_check_loops().