Skip to contentSkip to conversation

iproute_lwtunnel: Add check for result of get_u32 function

PATCH In review Maks Mishin 2 participants 3 messages Jul 7, 2024 – Jul 8, 2024

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

PATCH 1/1 iproute_lwtunnel: Add check for result of get_u32 function

---
 ip/iproute_lwtunnel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/iproute_lwtunnel.c +2 -1
index b4df4348..2946fa4d 100644
@@ -1484,7 +1484,8 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
 				NEXT_ARG();
 				if (hmac_ok++)
 					duparg2("hmac", *argv);
-				get_u32(&hmac, *argv, 0);
+				if (get_u32(&hmac, *argv, 0) || hmac == 0)
+					invarg("\"hmac\" value is invalid\n", *argv);
 			} else {
 				continue;
 			}
Signature · 1 line
2.30.2
#1 lore raw
Quoted 10 lines · On Sun, 7 Jul 2024 18:49:28 +0300 Maks Mishin <[email protected]> wrote:
---
 ip/iproute_lwtunnel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/iproute_lwtunnel.c +0 -0
index b4df4348..2946fa4d 100644

ip/iproute_lwtunnel.c static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp, · line 1491

Quoted 9 lines
ip/iproute_lwtunnel.c +2 -1
@@ -1484,7 +1484,8 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
 				NEXT_ARG();
 				if (hmac_ok++)
 					duparg2("hmac", *argv);
-				get_u32(&hmac, *argv, 0);
+				if (get_u32(&hmac, *argv, 0) || hmac == 0)
+					invarg("\"hmac\" value is invalid\n", *argv);
 			} else {
 				continue;
 			}
Fixes 8db158b9caac ("iproute: add support for SRv6 local segment processing")

The message is not that great. Becomes:
Error: argument "XXX" is wrong: "hmac" value is invalid.

But the rest of the tunnel parsing is equally as cryptic on error messages.

#2 lore raw
In reply to Maks Mishin
Quoted 10 lines · On Sun, 7 Jul 2024 18:49:28 +0300 Maks Mishin <[email protected]> wrote:
---
 ip/iproute_lwtunnel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/iproute_lwtunnel.c +0 -0
index b4df4348..2946fa4d 100644

ip/iproute_lwtunnel.c static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp, · line 1491

Quoted 9 lines
ip/iproute_lwtunnel.c +2 -1
@@ -1484,7 +1484,8 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
 				NEXT_ARG();
 				if (hmac_ok++)
 					duparg2("hmac", *argv);
-				get_u32(&hmac, *argv, 0);
+				if (get_u32(&hmac, *argv, 0) || hmac == 0)
+					invarg("\"hmac\" value is invalid\n", *argv);
 			} else {
 				continue;
 			}

There is another unchecked call to get_u32() in the same file. Please fix all of them and add more detail in commit message.

If the get_XXX functions are modified to force checks on return value get:

iproute_lwtunnel.c: In function ‘parse_encap_seg6’:
iproute_lwtunnel.c:972:25: warning: ignoring return value of ‘get_u32’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  972 |                         get_u32(&hmac, *argv, 0);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~
iproute_lwtunnel.c: In function ‘parse_encap_seg6local’:
iproute_lwtunnel.c:1487:33: warning: ignoring return value of ‘get_u32’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 1487 |                                 get_u32(&hmac, *argv, 0);
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~