Skip to content

Commit

Permalink
xfrm: Add dir validation to "out" data path lookup
Browse files Browse the repository at this point in the history
Introduces validation for the x->dir attribute within the XFRM output
data lookup path. If the configured direction does not match the expected
direction, output, increment the XfrmOutStateDirError counter and drop
the packet to ensure data integrity and correct flow handling.

grep -vw 0 /proc/net/xfrm_stat
XfrmOutPolError         	1
XfrmOutStateDirError    	1

Signed-off-by: Antony Antony <[email protected]>
Reviewed-by: Sabrina Dubroca <[email protected]>
Reviewed-by: Nicolas Dichtel <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
  • Loading branch information
antonyantony authored and klassert committed May 1, 2024
1 parent a4a87fa commit 601a086
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Documentation/networking/xfrm_proc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ XfrmOutPolError:

XfrmOutStateInvalid:
State is invalid, perhaps expired

XfrmOutStateDirError:
State direction mismatch (lookup found an input state on the output path, expected output or no direction)
1 change: 1 addition & 0 deletions include/uapi/linux/snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ enum
LINUX_MIB_XFRMFWDHDRERROR, /* XfrmFwdHdrError*/
LINUX_MIB_XFRMOUTSTATEINVALID, /* XfrmOutStateInvalid */
LINUX_MIB_XFRMACQUIREERROR, /* XfrmAcquireError */
LINUX_MIB_XFRMOUTSTATEDIRERROR, /* XfrmOutStateDirError */
__LINUX_MIB_XFRMMAX
};

Expand Down
6 changes: 6 additions & 0 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 && x->dir && x->dir != XFRM_SA_DIR_OUT) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEDIRERROR);
xfrm_state_put(x);
error = -EINVAL;
goto fail;
}

if (x && x->km.state == XFRM_STATE_VALID) {
xfrm[nx++] = x;
Expand Down
1 change: 1 addition & 0 deletions net/xfrm/xfrm_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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("XfrmOutStateDirError", LINUX_MIB_XFRMOUTSTATEDIRERROR),
SNMP_MIB_SENTINEL
};

Expand Down

0 comments on commit 601a086

Please sign in to comment.