diff mbox series

[v2,6.1] netfilter: Null pointer dereference in nf_tables_updobj

Message ID 20230117154548.3403346-1-alok.a.tiwari@oracle.com
State Accepted
Delegated to: Pablo Neira
Headers show
Series [v2,6.1] netfilter: Null pointer dereference in nf_tables_updobj | expand

Commit Message

ALOK TIWARI Jan. 17, 2023, 3:45 p.m. UTC
static analyzer detect null pointer dereference case for 'type'
function __nft_obj_type_get() can return NULL value which require to handle
if type is NULL pointer return -ENOENT

Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Pablo Neira Ayuso Jan. 17, 2023, 3:52 p.m. UTC | #1
On Tue, Jan 17, 2023 at 07:45:49AM -0800, Alok Tiwari wrote:
> static analyzer detect null pointer dereference case for 'type'
> function __nft_obj_type_get() can return NULL value which require to handle
> if type is NULL pointer return -ENOENT

Applied, thanks.

I have appended:

This should not ever happen, because if an object is found, then that
implies there is an object type, but let's add this as a failsafe check.
diff mbox series

Patch

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 3ba8c291fcaa..dca5352bdf3d 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -6951,6 +6951,9 @@  static int nf_tables_newobj(struct sk_buff *skb, const struct nfnl_info *info,
 			return -EOPNOTSUPP;
 
 		type = __nft_obj_type_get(objtype);
+		if (WARN_ON_ONCE(!type))
+			return -ENOENT;
+
 		nft_ctx_init(&ctx, net, skb, info->nlh, family, table, NULL, nla);
 
 		return nf_tables_updobj(&ctx, type, nla[NFTA_OBJ_DATA], obj);