diff mbox series

[ipsec-next,v10,2/3] xfrm: Add dir validation to "out" data path lookup

Message ID 274c82dfea0d656f59f69ccaab46d4319f0ef54c.1712828282.git.antony.antony@secunet.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [ipsec-next,v10,1/3] xfrm: Add Direction to the SA in or out | expand

Checks

Context Check Description
netdev/series_format warning Series does not have a cover letter; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5023 this patch: 5023
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: noureddine@arista.com heng.guo@windriver.com dsahern@kernel.org 0x7f454c46@gmail.com fruggeri@arista.com
netdev/build_clang success Errors and warnings before: 1066 this patch: 1066
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5299 this patch: 5299
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-04-11--12-00 (tests: 960)

Commit Message

Antony Antony April 11, 2024, 9:42 a.m. UTC
Introduces validation for the x->dir attribute within the XFRM output
data lookup path. If the configured direction does not match the expected
direction, out, increment the XfrmOutDirError counter and drop the packet
to ensure data integrity and correct flow handling.

grep -vw 0 /proc/net/xfrm_stat
XfrmOutPolError         	2
XfrmOutDirError         	2

Signed-off-by: Antony Antony <antony.antony@secunet.com>
---
 include/uapi/linux/snmp.h | 1 +
 net/xfrm/xfrm_policy.c    | 6 ++++++
 net/xfrm/xfrm_proc.c      | 1 +
 3 files changed, 8 insertions(+)

Comments

Nicolas Dichtel April 12, 2024, 1:49 p.m. UTC | #1
Le 11/04/2024 à 11:42, Antony Antony a écrit :
> Introduces validation for the x->dir attribute within the XFRM output
> data lookup path. If the configured direction does not match the expected
> direction, out, increment the XfrmOutDirError counter and drop the packet
> to ensure data integrity and correct flow handling.
> 
> grep -vw 0 /proc/net/xfrm_stat
> XfrmOutPolError         	2
> XfrmOutDirError         	2
> 
> Signed-off-by: Antony Antony <antony.antony@secunet.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Nicolas Dichtel April 12, 2024, 1:53 p.m. UTC | #2
Le 11/04/2024 à 11:42, Antony Antony a écrit :
> Introduces validation for the x->dir attribute within the XFRM output
> data lookup path. If the configured direction does not match the expected
> direction, out, increment the XfrmOutDirError counter and drop the packet
> to ensure data integrity and correct flow handling.
> 
> grep -vw 0 /proc/net/xfrm_stat
> XfrmOutPolError         	2
> XfrmOutDirError         	2
After thinking a bit more to the naming, what about
LINUX_MIB_XFRMOUTSTATEDIRERROR / XfrmOutStateDirError ?
Simon Horman April 18, 2024, 9:24 a.m. UTC | #3
On Thu, Apr 11, 2024 at 11:42:13AM +0200, Antony Antony wrote:
> Introduces validation for the x->dir attribute within the XFRM output
> data lookup path. If the configured direction does not match the expected
> direction, out, increment the XfrmOutDirError counter and drop the packet
> to ensure data integrity and correct flow handling.
> 
> grep -vw 0 /proc/net/xfrm_stat
> XfrmOutPolError         	2
> XfrmOutDirError         	2
> 
> Signed-off-by: Antony Antony <antony.antony@secunet.com>

...

> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index 6affe5cd85d8..7deeb21dae15 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -2489,6 +2489,12 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
>  
>  		x = xfrm_state_find(remote, local, fl, tmpl, policy, &error,
>  				    family, policy->if_id);
> +		if (x->dir && x->dir != XFRM_SA_DIR_OUT) {
> +			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTDIRERROR);
> +			xfrm_state_put(x);
> +			error = -EINVAL;
> +			goto fail;
> +		}

Hi Antony,

the line below assumes that x may be NULL,
but the new code above dereferences x unconditionally.
Is this ok?

Flagged by Smatch.

>  
>  		if (x && x->km.state == XFRM_STATE_VALID) {
>  			xfrm[nx++] = x;

...
Antony Antony April 21, 2024, 10:13 p.m. UTC | #4
Hi Simon,

On Thu, Apr 18, 2024 at 10:24:21 +0100, Simon Horman wrote:
> On Thu, Apr 11, 2024 at 11:42:13AM +0200, Antony Antony wrote:
> > Introduces validation for the x->dir attribute within the XFRM output
> > data lookup path. If the configured direction does not match the expected
> > direction, out, increment the XfrmOutDirError counter and drop the packet
> > to ensure data integrity and correct flow handling.
> > 
> > grep -vw 0 /proc/net/xfrm_stat
> > XfrmOutPolError         	2
> > XfrmOutDirError         	2
> > 
> > Signed-off-by: Antony Antony <antony.antony@secunet.com>
> 
> ...
> 
> > diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> > index 6affe5cd85d8..7deeb21dae15 100644
> > --- a/net/xfrm/xfrm_policy.c
> > +++ b/net/xfrm/xfrm_policy.c
> > @@ -2489,6 +2489,12 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
> >  
> >  		x = xfrm_state_find(remote, local, fl, tmpl, policy, &error,
> >  				    family, policy->if_id);
> > +		if (x->dir && x->dir != XFRM_SA_DIR_OUT) {
> > +			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTDIRERROR);
> > +			xfrm_state_put(x);
> > +			error = -EINVAL;
> > +			goto fail;
> > +		}
> 
> Hi Antony,
> 
> the line below assumes that x may be NULL,
> but the new code above dereferences x unconditionally.
> Is this ok?

probably not. I added a fix in v11.


> 
> Flagged by Smatch.

thanks.

> 
> >  
> >  		if (x && x->km.state == XFRM_STATE_VALID) {
> >  			xfrm[nx++] = x;
> 
> ...
diff mbox series

Patch

diff --git a/include/uapi/linux/snmp.h b/include/uapi/linux/snmp.h
index a0819c6a5988..00e179c382c0 100644
--- a/include/uapi/linux/snmp.h
+++ b/include/uapi/linux/snmp.h
@@ -337,6 +337,7 @@  enum
 	LINUX_MIB_XFRMFWDHDRERROR,		/* XfrmFwdHdrError*/
 	LINUX_MIB_XFRMOUTSTATEINVALID,		/* XfrmOutStateInvalid */
 	LINUX_MIB_XFRMACQUIREERROR,		/* XfrmAcquireError */
+	LINUX_MIB_XFRMOUTDIRERROR,		/* XfrmOutDirError */
 	__LINUX_MIB_XFRMMAX
 };
 
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 6affe5cd85d8..7deeb21dae15 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2489,6 +2489,12 @@  xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
 
 		x = xfrm_state_find(remote, local, fl, tmpl, policy, &error,
 				    family, policy->if_id);
+		if (x->dir && x->dir != XFRM_SA_DIR_OUT) {
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTDIRERROR);
+			xfrm_state_put(x);
+			error = -EINVAL;
+			goto fail;
+		}
 
 		if (x && x->km.state == XFRM_STATE_VALID) {
 			xfrm[nx++] = x;
diff --git a/net/xfrm/xfrm_proc.c b/net/xfrm/xfrm_proc.c
index 5f9bf8e5c933..aa993bdd29ed 100644
--- a/net/xfrm/xfrm_proc.c
+++ b/net/xfrm/xfrm_proc.c
@@ -41,6 +41,7 @@  static const struct snmp_mib xfrm_mib_list[] = {
 	SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
 	SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
 	SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR),
+	SNMP_MIB_ITEM("XfrmOutDirError", LINUX_MIB_XFRMOUTDIRERROR),
 	SNMP_MIB_SENTINEL
 };