Skip to content

Commit 601a086

Browse files
antonyantonyklassert
authored andcommitted
xfrm: Add dir validation to "out" data path lookup
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]>
1 parent a4a87fa commit 601a086

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

Documentation/networking/xfrm_proc.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ XfrmOutPolError:
111111

112112
XfrmOutStateInvalid:
113113
State is invalid, perhaps expired
114+
115+
XfrmOutStateDirError:
116+
State direction mismatch (lookup found an input state on the output path, expected output or no direction)

include/uapi/linux/snmp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ enum
337337
LINUX_MIB_XFRMFWDHDRERROR, /* XfrmFwdHdrError*/
338338
LINUX_MIB_XFRMOUTSTATEINVALID, /* XfrmOutStateInvalid */
339339
LINUX_MIB_XFRMACQUIREERROR, /* XfrmAcquireError */
340+
LINUX_MIB_XFRMOUTSTATEDIRERROR, /* XfrmOutStateDirError */
340341
__LINUX_MIB_XFRMMAX
341342
};
342343

net/xfrm/xfrm_policy.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,12 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
24892489

24902490
x = xfrm_state_find(remote, local, fl, tmpl, policy, &error,
24912491
family, policy->if_id);
2492+
if (x && x->dir && x->dir != XFRM_SA_DIR_OUT) {
2493+
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEDIRERROR);
2494+
xfrm_state_put(x);
2495+
error = -EINVAL;
2496+
goto fail;
2497+
}
24922498

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

net/xfrm/xfrm_proc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static const struct snmp_mib xfrm_mib_list[] = {
4141
SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
4242
SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
4343
SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR),
44+
SNMP_MIB_ITEM("XfrmOutStateDirError", LINUX_MIB_XFRMOUTSTATEDIRERROR),
4445
SNMP_MIB_SENTINEL
4546
};
4647

0 commit comments

Comments
 (0)