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 <antony.antony@secunet.com> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
parent
a4a87fa4e9
commit
601a0867f8
@ -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)
|
||||
|
@ -337,6 +337,7 @@ enum
|
||||
LINUX_MIB_XFRMFWDHDRERROR, /* XfrmFwdHdrError*/
|
||||
LINUX_MIB_XFRMOUTSTATEINVALID, /* XfrmOutStateInvalid */
|
||||
LINUX_MIB_XFRMACQUIREERROR, /* XfrmAcquireError */
|
||||
LINUX_MIB_XFRMOUTSTATEDIRERROR, /* XfrmOutStateDirError */
|
||||
__LINUX_MIB_XFRMMAX
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user