Skip to contentSkip to conversation

m_tunnel_key: Add check for result hex2mem()

PATCH In review Maks Mishin 2 participants 2 messages Feb 18, 2024 – Feb 19, 2024

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

PATCH 1/1 m_tunnel_key: Add check for result hex2mem()

Added check for hex2mem() result to report of error with incorrect args.

---
 tc/m_tunnel_key.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tc/m_tunnel_key.c +4 -1
index ff699cc8..9bb5c2aa 100644
@@ -575,7 +575,10 @@ static void tunnel_key_print_geneve_options(struct rtattr *attr)
 		data_len = RTA_PAYLOAD(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]);
 		hexstring_n2a(RTA_DATA(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]),
 			      data_len, data, sizeof(data));
-		hex2mem(data, data_r, data_len);
+
+		if (hex2mem(data, data_r, data_len) < 0)
+			invarg("labels mask must be a hex string\n", data);
+
 		offset += data_len + 20;
 		rem -= data_len + 20;
 		i = RTA_DATA(attr) + offset;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 13 lines · On Sun, 18 Feb 2024 23:40:26 +0300 Maks Mishin <[email protected]> wrote:

Added check for hex2mem() result to report of error with incorrect args.

---
 tc/m_tunnel_key.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tc/m_tunnel_key.c +0 -0
index ff699cc8..9bb5c2aa 100644

tc/m_tunnel_key.c static void tunnel_key_print_geneve_options(struct rtattr *attr) · line 581

Quoted 8 lines
tc/m_tunnel_key.c +4 -1
@@ -575,7 +575,10 @@ static void tunnel_key_print_geneve_options(struct rtattr *attr)
 		data_len = RTA_PAYLOAD(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]);
 		hexstring_n2a(RTA_DATA(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]),
 			      data_len, data, sizeof(data));
-		hex2mem(data, data_r, data_len);
+
+		if (hex2mem(data, data_r, data_len) < 0)
+			invarg("labels mask must be a hex string\n", data);
+

invarg() is intended only for use in command line args.
This is where the result of a geneve option from kernel netlink is being parsed. Not user input.

Not sure why hex2mem is needed here at all? The original data is in the netlink message. Doing the inverse is redundant.