diff mbox series

[2/7] netlink: Disallow certain flags in message constructor

Message ID 20240726161232.146982-2-denkenz@gmail.com (mailing list archive)
State New
Headers show
Series [1/7] netlink: Remove pointless checks | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Denis Kenzior July 26, 2024, 4:12 p.m. UTC
Certain flags are reserved for use by l_netlink when sending messages.
Other flags don't make sense for messages that are to be sent to the
kernel.  Disallow their use.
---
 ell/netlink.c        | 3 +++
 unit/test-genl-msg.c | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/ell/netlink.c b/ell/netlink.c
index 26c31679e4c7..58dfd9779875 100644
--- a/ell/netlink.c
+++ b/ell/netlink.c
@@ -751,6 +751,9 @@  LIB_EXPORT struct l_netlink_message *l_netlink_message_new_sized(uint16_t type,
 {
 	struct l_netlink_message *message;
 
+	if (flags & 0xff)
+		return NULL;
+
 	message = l_new(struct l_netlink_message, 1);
 
 	message->size = initial_len + NLMSG_HDRLEN;
diff --git a/unit/test-genl-msg.c b/unit/test-genl-msg.c
index 3d996f4e242a..d10a87f30e3b 100644
--- a/unit/test-genl-msg.c
+++ b/unit/test-genl-msg.c
@@ -134,7 +134,7 @@  static void build_set_station_netlink(const void *data)
 	struct l_netlink_message *m;
 	struct genlmsghdr genlhdr = { .cmd = 18, .version = 0, .reserved = 0 };
 
-	m = l_netlink_message_new(0x17, NLM_F_REQUEST | NLM_F_ACK);
+	m = l_netlink_message_new(0x17, 0);
 	assert(m);
 
 	assert(!l_netlink_message_add_header(m, &genlhdr, sizeof(genlhdr)));
@@ -153,6 +153,7 @@  static void build_set_station_netlink(const void *data)
 				sizeof(set_station_request), do_debug, "[MSG] ");
 	}
 
+	m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
 	assert(m->hdr->nlmsg_len == sizeof(set_station_request));
 	assert(!memcmp(m->data, set_station_request,
 					sizeof(set_station_request)));
@@ -292,7 +293,7 @@  static void build_set_rekey_offload_netlink(const void *data)
 	struct l_netlink_message *m;
 	struct genlmsghdr genlhdr = { .cmd = 79, .version = 0, .reserved = 0 };
 
-	m = l_netlink_message_new(0x1b, NLM_F_REQUEST | NLM_F_ACK);
+	m = l_netlink_message_new(0x1b, 0);
 	assert(m);
 
 	assert(!l_netlink_message_add_header(m, &genlhdr, sizeof(genlhdr)));
@@ -315,6 +316,7 @@  static void build_set_rekey_offload_netlink(const void *data)
 				do_debug, "[MSG] ");
 	}
 
+	m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
 	assert(m->hdr->nlmsg_len == sizeof(set_rekey_offload_request));
 	assert(!memcmp(m->data, set_rekey_offload_request,
 					sizeof(set_rekey_offload_request)));