Skip to contentSkip to conversation

Sanitize two error conditions in netlink code

PATCH In review Phil Sutter 2 participants 5 messages May 16, 2025 – May 20, 2025 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Sanitize two error conditions in netlink code

While reviewing netlink deserialization code I noticed these two potential issues. Submitting them separately from other work as they are clear fixes (IMO).

Phil Sutter (2):
netlink: Avoid potential NULL-ptr deref parsing set elem expressions
netlink: Catch unknown types when deserializing objects

 src/netlink.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.0
author reviewer
#1 lore raw

PATCH 1/2 netlink: Avoid potential NULL-ptr deref parsing set elem expressions

Since netlink_parse_set_expr() may return NULL, the following deref must be guarded.

Fixes e6d1d0d611958 ("src: add set element multi-statement support")
---
 src/netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/netlink.c +2 -1
index d88912457c591..0724190a25d6f 100644
@@ -969,7 +969,8 @@ static int set_elem_parse_expressions(struct nftnl_expr *e, void *data)
 	struct stmt *stmt;
 
 	stmt = netlink_parse_set_expr(set, cache, e);
-	list_add_tail(&stmt->list, &setelem_parse_ctx->stmt_list);
+	if (stmt)
+		list_add_tail(&stmt->list, &setelem_parse_ctx->stmt_list);
 
 	return 0;
 }
Signature · 1 line
2.49.0
author reviewer
#2 lore raw

PATCH 2/2 netlink: Catch unknown types when deserializing objects

In reply to Phil Sutter

Print an error message and discard the object instead of returning it to the caller. At least when trying to print it, we would hit an assert() in obj_type_name() anyway.

Fixes 4756d92e517ae ("src: listing of stateful objects")
---
 src/netlink.c | 4 ++++
 1 file changed, 4 insertions(+)
src/netlink.c +4 -0
index 0724190a25d6f..52010c74d4f30 100644
@@ -1802,6 +1802,10 @@ struct obj *netlink_delinearize_obj(struct netlink_ctx *ctx,
 		obj->synproxy.flags =
 			nftnl_obj_get_u32(nlo, NFTNL_OBJ_SYNPROXY_FLAGS);
 		break;
+	default:
+		netlink_io_error(ctx, NULL, "Unknown object type %u", type);
+		obj_free(obj);
+		return NULL;
 	}
 	obj->type = type;
 
Signature · 1 line
2.49.0
maintainer
#3 lore raw
In reply to Phil Sutter
Quoted 3 lines · Phil Sutter

While reviewing netlink deserialization code I noticed these two potential issues. Submitting them separately from other work as they are clear fixes (IMO).

Thanks Phil, please push them out.

author reviewer
#4 lore raw
Quoted 6 lines · Florian Westphal
Quoted 3 lines · Phil Sutter

While reviewing netlink deserialization code I noticed these two potential issues. Submitting them separately from other work as they are clear fixes (IMO).

Thanks Phil, please push them out.

Series applied, thanks!