Skip to contentSkip to conversation

two fixes for tc ct command

PATCH In review Roi Dayan 2 participants 7 messages Nov 16, 2022 – Nov 24, 2022

Subsystems (2)
lore
Share & tools
lore

Roi Dayan

author
#0 lore raw

cover two fixes for tc ct command

Hi,

The first first is that ct commit nat src/dst should accept the command even without an address and the driver fills the address from the tuple.
The second commit fixes a segmentaion fault reading invalid argv pointer which is passing the available args passed by the user.

Thanks,
Roi

Roi Dayan (2):
tc: ct: Fix ct commit nat forcing addr
tc: ct: Fix invalid pointer derefence

 man/man8/tc-ct.8 | 2 +-
 tc/m_ct.c        | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.38.0
author
#1 lore raw

PATCH 1/2 tc: ct: Fix ct commit nat forcing addr

Action ct commit should accept nat src/dst without an addr. Fix it.

Fixes c8a494314c40 ("tc: Introduce tc ct action")
---
 man/man8/tc-ct.8 | 2 +-
 tc/m_ct.c        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
man/man8/tc-ct.8 +1 -1
index 2fb81ca29aa4..78d05e430c36 100644
@@ -47,7 +47,7 @@ Specify a masked 32bit mark to set for the connection (only valid with commit).
 Specify a masked 128bit label to set for the connection (only valid with commit).
 .TP
 .BI nat " NAT_SPEC"
-.BI Where " NAT_SPEC " ":= {src|dst} addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]"
+.BI Where " NAT_SPEC " ":= {src|dst} [addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]]"
 
 Specify src/dst and range of nat to configure for the connection (only valid with commit).
 .RS
tc/m_ct.c +2 -2
index a02bf0cc1655..1b8984075a67 100644
@@ -23,7 +23,7 @@ usage(void)
 		"	ct commit [force] [zone ZONE] [mark MASKED_MARK] [label MASKED_LABEL] [nat NAT_SPEC]\n"
 		"	ct [nat] [zone ZONE]\n"
 		"Where: ZONE is the conntrack zone table number\n"
-		"	NAT_SPEC is {src|dst} addr addr1[-addr2] [port port1[-port2]]\n"
+		"	NAT_SPEC is {src|dst} [addr addr1[-addr2] [port port1[-port2]]]\n"
 		"\n");
 	exit(-1);
 }
@@ -234,7 +234,7 @@ parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 
 			NEXT_ARG();
 			if (matches(*argv, "addr") != 0)
-				usage();
+				continue;
 
 			NEXT_ARG();
 			ret = ct_parse_nat_addr_range(*argv, n);
Signature · 1 line
2.38.0
author
#6 lore raw

PATCH 2/2 tc: ct: Fix invalid pointer derefence

In reply to Roi Dayan

Using mcaro NEXT_ARG_FWD does not validate argc. Use macro NEXT_ARG which validates argc while parsing args in the same loop iteration.

Fixes c8a494314c40 ("tc: Introduce tc ct action")
---
 tc/m_ct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tc/m_ct.c +1 -1
index 1b8984075a67..e1c4b822f8ac 100644
@@ -243,7 +243,7 @@ parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 				return -1;
 			}
 
-			NEXT_ARG_FWD();
+			NEXT_ARG();
 			if (matches(*argv, "port") != 0)
 				continue;
 
Signature · 1 line
2.38.0
#2 lore raw

Re: [PATCH iproute2 1/2] tc: ct: Fix ct commit nat forcing addr

In reply to Roi Dayan
Quoted 37 lines · On Wed, 16 Nov 2022 09:33:11 +0200 Roi Dayan <[email protected]> wrote:

Action ct commit should accept nat src/dst without an addr. Fix it.

Fixes c8a494314c40 ("tc: Introduce tc ct action")
---
 man/man8/tc-ct.8 | 2 +-
 tc/m_ct.c        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
man/man8/tc-ct.8 +1 -1
index 2fb81ca29aa4..78d05e430c36 100644
@@ -47,7 +47,7 @@ Specify a masked 32bit mark to set for the connection (only valid with commit).
 Specify a masked 128bit label to set for the connection (only valid with commit).
 .TP
 .BI nat " NAT_SPEC"
-.BI Where " NAT_SPEC " ":= {src|dst} addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]"
+.BI Where " NAT_SPEC " ":= {src|dst} [addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]]"
 
 Specify src/dst and range of nat to configure for the connection (only valid with commit).
 .RS
tc/m_ct.c +1 -1
index a02bf0cc1655..1b8984075a67 100644
@@ -23,7 +23,7 @@ usage(void)
 		"	ct commit [force] [zone ZONE] [mark MASKED_MARK] [label MASKED_LABEL] [nat NAT_SPEC]\n"
 		"	ct [nat] [zone ZONE]\n"
 		"Where: ZONE is the conntrack zone table number\n"
-		"	NAT_SPEC is {src|dst} addr addr1[-addr2] [port port1[-port2]]\n"
+		"	NAT_SPEC is {src|dst} [addr addr1[-addr2] [port port1[-port2]]]\n"
 		"\n");
 	exit(-1);
 }

tc/m_ct.c parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, · line 238

Quoted 6 lines
tc/m_ct.c +1 -1
@@ -234,7 +234,7 @@ parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 
 			NEXT_ARG();
 			if (matches(*argv, "addr") != 0)
-				usage();
+				continue;
 

This confuses me. Doing continue here will cause the current argument to be reprocessed so it would expect it to be zone | nat | clear | commit | force | index | mark | label which is not right.

author
#3 lore raw

Re: [PATCH iproute2 1/2] tc: ct: Fix ct commit nat forcing addr

Quoted 41 lines · Stephen Hemminger
Quoted 38 lines · On Wed, 16 Nov 2022 09:33:11 +0200 Roi Dayan <[email protected]> wrote:

Action ct commit should accept nat src/dst without an addr. Fix it.

Fixes c8a494314c40 ("tc: Introduce tc ct action")
---
 man/man8/tc-ct.8 | 2 +-
 tc/m_ct.c        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
man/man8/tc-ct.8 +1 -1
index 2fb81ca29aa4..78d05e430c36 100644
@@ -47,7 +47,7 @@ Specify a masked 32bit mark to set for the connection (only valid with commit).
 Specify a masked 128bit label to set for the connection (only valid with commit).
 .TP
 .BI nat " NAT_SPEC"
-.BI Where " NAT_SPEC " ":= {src|dst} addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]"
+.BI Where " NAT_SPEC " ":= {src|dst} [addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]]"
 
 Specify src/dst and range of nat to configure for the connection (only valid with commit).
 .RS
tc/m_ct.c +1 -1
index a02bf0cc1655..1b8984075a67 100644
@@ -23,7 +23,7 @@ usage(void)
 		"	ct commit [force] [zone ZONE] [mark MASKED_MARK] [label MASKED_LABEL] [nat NAT_SPEC]\n"
 		"	ct [nat] [zone ZONE]\n"
 		"Where: ZONE is the conntrack zone table number\n"
-		"	NAT_SPEC is {src|dst} addr addr1[-addr2] [port port1[-port2]]\n"
+		"	NAT_SPEC is {src|dst} [addr addr1[-addr2] [port port1[-port2]]]\n"
 		"\n");
 	exit(-1);
 }
@@ -234,7 +234,7 @@ parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 
Quoted 11 lines

tc/m_ct.c parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, · line 238

Quoted 5 lines
tc/m_ct.c +1 -1
 			NEXT_ARG();
 			if (matches(*argv, "addr") != 0)
-				usage();
+				continue;
 

This confuses me. Doing continue here will cause the current argument to be reprocessed so it would expect it to be zone | nat | clear | commit | force | index | mark | label which is not right.

its the opposite. "nat" came first. if matches() didn't find "addr" it continues the loop of args. if matches did find "addr" it continues to next line which is ct_parse_nat_addr_range() to parse the address.

author
#4 lore raw

Re: [PATCH iproute2 1/2] tc: ct: Fix ct commit nat forcing addr

Quoted 56 lines · Roi Dayan
Quoted 41 lines · Stephen Hemminger
Quoted 38 lines · On Wed, 16 Nov 2022 09:33:11 +0200 Roi Dayan <[email protected]> wrote:

Action ct commit should accept nat src/dst without an addr. Fix it.

Fixes c8a494314c40 ("tc: Introduce tc ct action")
---
 man/man8/tc-ct.8 | 2 +-
 tc/m_ct.c        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
man/man8/tc-ct.8 +1 -1
index 2fb81ca29aa4..78d05e430c36 100644
@@ -47,7 +47,7 @@ Specify a masked 32bit mark to set for the connection (only valid with commit).
 Specify a masked 128bit label to set for the connection (only valid with commit).
 .TP
 .BI nat " NAT_SPEC"
-.BI Where " NAT_SPEC " ":= {src|dst} addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]"
+.BI Where " NAT_SPEC " ":= {src|dst} [addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]]"
 
 Specify src/dst and range of nat to configure for the connection (only valid with commit).
 .RS
tc/m_ct.c +1 -1
index a02bf0cc1655..1b8984075a67 100644
@@ -23,7 +23,7 @@ usage(void)
 		"	ct commit [force] [zone ZONE] [mark MASKED_MARK] [label MASKED_LABEL] [nat NAT_SPEC]\n"
 		"	ct [nat] [zone ZONE]\n"
 		"Where: ZONE is the conntrack zone table number\n"
-		"	NAT_SPEC is {src|dst} addr addr1[-addr2] [port port1[-port2]]\n"
+		"	NAT_SPEC is {src|dst} [addr addr1[-addr2] [port port1[-port2]]]\n"
 		"\n");
 	exit(-1);
 }
@@ -234,7 +234,7 @@ parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 
Quoted 11 lines

tc/m_ct.c parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, · line 238

Quoted 5 lines
tc/m_ct.c +1 -1
 			NEXT_ARG();
 			if (matches(*argv, "addr") != 0)
-				usage();
+				continue;
 

This confuses me. Doing continue here will cause the current argument to be reprocessed so it would expect it to be zone | nat | clear | commit | force | index | mark | label which is not right.

Quoted 5 lines

its the opposite. "nat" came first. if matches() didn't find "addr" it continues the loop of args. if matches did find "addr" it continues to next line which is ct_parse_nat_addr_range() to parse the address.

Got your comment wrong so yes the current arg will be reprocessed and this is what we want.
This will make "addr" optional and there should be some action after ct commit nat. next loop iteration should break and continue parse next action usually a goto action.

author
#5 lore raw

Re: [PATCH iproute2 1/2] tc: ct: Fix ct commit nat forcing addr

Quoted 65 lines · Roi Dayan
Quoted 56 lines · Roi Dayan
Quoted 41 lines · Stephen Hemminger
Quoted 38 lines · On Wed, 16 Nov 2022 09:33:11 +0200 Roi Dayan <[email protected]> wrote:

Action ct commit should accept nat src/dst without an addr. Fix it.

Fixes c8a494314c40 ("tc: Introduce tc ct action")
---
 man/man8/tc-ct.8 | 2 +-
 tc/m_ct.c        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
man/man8/tc-ct.8 +1 -1
index 2fb81ca29aa4..78d05e430c36 100644
@@ -47,7 +47,7 @@ Specify a masked 32bit mark to set for the connection (only valid with commit).
 Specify a masked 128bit label to set for the connection (only valid with commit).
 .TP
 .BI nat " NAT_SPEC"
-.BI Where " NAT_SPEC " ":= {src|dst} addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]"
+.BI Where " NAT_SPEC " ":= {src|dst} [addr" " addr1" "[-" "addr2" "] [port " "port1" "[-" "port2" "]]]"
 
 Specify src/dst and range of nat to configure for the connection (only valid with commit).
 .RS
tc/m_ct.c +1 -1
index a02bf0cc1655..1b8984075a67 100644
@@ -23,7 +23,7 @@ usage(void)
 		"	ct commit [force] [zone ZONE] [mark MASKED_MARK] [label MASKED_LABEL] [nat NAT_SPEC]\n"
 		"	ct [nat] [zone ZONE]\n"
 		"Where: ZONE is the conntrack zone table number\n"
-		"	NAT_SPEC is {src|dst} addr addr1[-addr2] [port port1[-port2]]\n"
+		"	NAT_SPEC is {src|dst} [addr addr1[-addr2] [port port1[-port2]]]\n"
 		"\n");
 	exit(-1);
 }
@@ -234,7 +234,7 @@ parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 
Quoted 11 lines

tc/m_ct.c parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, · line 238

Quoted 5 lines
tc/m_ct.c +1 -1
 			NEXT_ARG();
 			if (matches(*argv, "addr") != 0)
-				usage();
+				continue;
 

This confuses me. Doing continue here will cause the current argument to be reprocessed so it would expect it to be zone | nat | clear | commit | force | index | mark | label which is not right.

Quoted 5 lines

its the opposite. "nat" came first. if matches() didn't find "addr" it continues the loop of args. if matches did find "addr" it continues to next line which is ct_parse_nat_addr_range() to parse the address.

Quoted 6 lines

Got your comment wrong so yes the current arg will be reprocessed and this is what we want.
This will make "addr" optional and there should be some action after ct commit nat. next loop iteration should break and continue parse next action usually a goto action.

Hi Stephen,

Can you look at this again please?
this is the same as done in other args like "port" right after and probably in other actions.
If "addr" is not the next arg we continue the loop and parse again as expected for the other ct args or getting to else and breaking to continue.

Thanks,
Roi