Skip to contentSkip to conversation

netfilter: nf_tables: fix possible null-pointer dereference in object update

PATCH Applied Fernando Fernandez Mancera 3 participants 6 messages Sep 4, 2019 – Nov 1, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: nf_tables: fix possible null-pointer dereference in object update

Not all objects need an update operation. If the object type doesn't implement an update operation and the user tries to update it there will be a EOPNOTSUPP error instead of a null pointer.

Fixes d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object update operation")
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
index cf767bc58e18..013d28899cab 100644
@@ -5140,6 +5140,9 @@ static int nf_tables_updobj(const struct nft_ctx *ctx,
 	struct nft_trans *trans;
 	int err;
 
+	if (!obj->ops->update)
+		return -EOPNOTSUPP;
+
 	trans = nft_trans_alloc(ctx, NFT_MSG_NEWOBJ,
 				sizeof(struct nft_trans_obj));
 	if (!trans)
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 3 lines · Fernando Fernandez Mancera

Not all objects need an update operation. If the object type doesn't implement an update operation and the user tries to update it there will be a EOPNOTSUPP error instead of a null pointer.

Applied, thanks.

#2 lore raw
In reply to Fernando Fernandez Mancera

Hi Fernando,

Quoted 26 lines · Fernando Fernandez Mancera

Not all objects need an update operation. If the object type doesn't implement an update operation and the user tries to update it there will be a EOPNOTSUPP error instead of a null pointer.

Fixes d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object update operation")
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
index cf767bc58e18..013d28899cab 100644
@@ -5140,6 +5140,9 @@ static int nf_tables_updobj(const struct nft_ctx *ctx,
 	struct nft_trans *trans;
 	int err;
 
+	if (!obj->ops->update)
+		return -EOPNOTSUPP;
+
 	trans = nft_trans_alloc(ctx, NFT_MSG_NEWOBJ,
 				sizeof(struct nft_trans_obj));
 	if (!trans)
Signature · 1 line
2.20.1

I think this introduced a regression when adding an object that already exists:

    # nft add table inet foobar
    # nft add counter inet foobar my_counter
    # nft add counter inet foobar my_counter
    Error: Could not process rule: Operation not supported
    add counter inet foobar my_counter
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It applies to all objects that don't provide an update handler; counter, ct helper, ct timeout, ct exception, etc.

#3 lore raw
Quoted 46 lines · Eric Garver

Hi Fernando,

Quoted 1 line · Fernando Fernandez Mancera

Not all objects need an update operation. If the object type doesn't

implement

Quoted 1 line

an update operation and the user tries to update it there will be a

EOPNOTSUPP

Quoted 3 lines

error instead of a null pointer.

Fixes d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object

update operation")

Review

Quoted 6 lines
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/net/netfilter/nf_tables_api.c

net/netfilter/nf_tables_api.c static int nf_tables_updobj(const struct

Quoted 4 lines

index cf767bc58e18..013d28899cab 100644

net/netfilter/nf_tables_api.c +0 -0
@@ -5140,6 +5140,9 @@ static int nf_tables_updobj(const struct

nft_ctx *ctx,

Quoted 11 lines
net/netfilter/nf_tables_api.c +3 -0
 	struct nft_trans *trans;
 	int err;
 
+	if (!obj->ops->update)
+		return -EOPNOTSUPP;
+
 	trans = nft_trans_alloc(ctx, NFT_MSG_NEWOBJ,
 				sizeof(struct nft_trans_obj));
 	if (!trans)
Signature · 1 line
2.20.1

I think this introduced a regression when adding an object that already exists:

   # nft add table inet foobar
   # nft add counter inet foobar my_counter
   # nft add counter inet foobar my_counter
   Error: Could not process rule: Operation not supported
   add counter inet foobar my_counter
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 3 lines

It applies to all objects that don't provide an update handler; counter,
ct helper, ct timeout, ct exception, etc.

Hi Eric,

It seems that you are right. What would be the behaviour here? Resets the object properties?

Thanks Eric!

#4 lore raw
Quoted 47 lines · Fernando Fernández Mancera
Quoted 46 lines · Eric Garver

Hi Fernando,

Quoted 1 line · Fernando Fernandez Mancera

Not all objects need an update operation. If the object type doesn't

implement

Quoted 1 line

an update operation and the user tries to update it there will be a

EOPNOTSUPP

Quoted 3 lines

error instead of a null pointer.

Fixes d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object

update operation")

Review

Quoted 6 lines
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/net/netfilter/nf_tables_api.c

net/netfilter/nf_tables_api.c static int nf_tables_updobj(const struct

Quoted 4 lines

index cf767bc58e18..013d28899cab 100644

net/netfilter/nf_tables_api.c +0 -0
@@ -5140,6 +5140,9 @@ static int nf_tables_updobj(const struct

nft_ctx *ctx,

Quoted 11 lines
net/netfilter/nf_tables_api.c +3 -0
 	struct nft_trans *trans;
 	int err;
 
+	if (!obj->ops->update)
+		return -EOPNOTSUPP;
+
 	trans = nft_trans_alloc(ctx, NFT_MSG_NEWOBJ,
 				sizeof(struct nft_trans_obj));
 	if (!trans)
Signature · 1 line
2.20.1

I think this introduced a regression when adding an object that already exists:

   # nft add table inet foobar
   # nft add counter inet foobar my_counter
   # nft add counter inet foobar my_counter
   Error: Could not process rule: Operation not supported
   add counter inet foobar my_counter
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 7 lines
Quoted 3 lines

It applies to all objects that don't provide an update handler; counter,
ct helper, ct timeout, ct exception, etc.

Hi Eric,

It seems that you are right. What would be the behaviour here? Resets the object properties?

I don't know what the correct behavior is in the kernel - maybe it silently skips it. i.e. no attempt to update, but returns no error.

From a user perspective it should happily accept the re-add.

    # nft add table inet foobar
    # nft add counter inet foobar my_counter
    # nft add counter inet foobar my_counter
    ** no error **

Unless the "create" verb is used, then we should get an error:

    # nft create counter inet foobar my_counter
    Error: Could not process rule: File exists
    create counter inet foobar my_counter
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#5 lore raw
Quoted 73 lines · Eric Garver
Quoted 1 line · Fernando Fernández Mancera

El 1 de noviembre de 2019 15:42:46 CET, Eric Garver

Quoted 5 lines · <[email protected]> escribió:
Quoted 5 lines

Hi Fernando,

Quoted 1 line · Fernando Fernandez Mancera

Not all objects need an update operation. If the object type

doesn't

Quoted 2 lines
Quoted 2 lines

implement

Quoted 1 line

an update operation and the user tries to update it there will be

a

Quoted 4 lines
Quoted 4 lines

EOPNOTSUPP

Quoted 3 lines

error instead of a null pointer.

Fixes d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful

object

Quoted 16 lines
Quoted 16 lines

update operation")

Review

Quoted 6 lines
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/net/netfilter/nf_tables_api.c

net/netfilter/nf_tables_api.c static int nf_tables_updobj(const struct

Quoted 4 lines

index cf767bc58e18..013d28899cab 100644

net/netfilter/nf_tables_api.c +0 -0
@@ -5140,6 +5140,9 @@ static int nf_tables_updobj(const struct

nft_ctx *ctx,

Quoted 3 lines
net/netfilter/nf_tables_api.c +0 -0
 	struct nft_trans *trans;
 	int err;
 
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
net/netfilter/nf_tables_api.c +3 -0
+	if (!obj->ops->update)
+		return -EOPNOTSUPP;
+
 	trans = nft_trans_alloc(ctx, NFT_MSG_NEWOBJ,
 				sizeof(struct nft_trans_obj));
 	if (!trans)
Signature · 1 line
2.20.1

I think this introduced a regression when adding an object that

already

Quoted 9 lines
Quoted 9 lines

exists:

   # nft add table inet foobar
   # nft add counter inet foobar my_counter
   # nft add counter inet foobar my_counter
   Error: Could not process rule: Operation not supported
   add counter inet foobar my_counter
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 7 lines
Quoted 3 lines

It applies to all objects that don't provide an update handler; counter,
ct helper, ct timeout, ct exception, etc.

Hi Eric,

It seems that you are right. What would be the behaviour here? Resets

the object properties?

I don't know what the correct behavior is in the kernel - maybe it silently skips it. i.e. no attempt to update, but returns no error.

From a user perspective it should happily accept the re-add.

   # nft add table inet foobar
   # nft add counter inet foobar my_counter
   # nft add counter inet foobar my_counter
   ** no error **
Quoted 6 lines

Unless the "create" verb is used, then we should get an error:

   # nft create counter inet foobar my_counter
   Error: Could not process rule: File exists
   create counter inet foobar my_counter
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sure, I am going to prepare a patch for this. Sorry about the regression. Thanks!