Skip to content

Commit 19ebbd6

Browse files
herbertxLee Jones
authored andcommitted
xfrm: Use correct address family in xfrm_state_find
[ Upstream commit e94ee171349db84c7cfdc5fefbebe414054d0924 ] The struct flowi must never be interpreted by itself as its size depends on the address family. Therefore it must always be grouped with its original family value. In this particular instance, the original family value is lost in the function xfrm_state_find. Therefore we get a bogus read when it's coupled with the wrong family which would occur with inter- family xfrm states. This patch fixes it by keeping the original family value. Note that the same bug could potentially occur in LSM through the xfrm_state_pol_flow_match hook. I checked the current code there and it seems to be safe for now as only secid is used which is part of struct flowi_common. But that API should be changed so that so that we don't get new bugs in the future. We could do that by replacing fl with just secid or adding a family field. Reported-by: [email protected] Fixes: 48b8d78 ("[XFRM]: State selection update to use inner...") Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Steffen Klassert <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Lee Jones <[email protected]> Change-Id: I3429b987f2dfb9bcb3b1f7b4f4a12e9b334bc018
1 parent 6910196 commit 19ebbd6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

net/xfrm/xfrm_state.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,8 @@ static void xfrm_state_look_at(struct xfrm_policy *pol, struct xfrm_state *x,
742742
*/
743743
if (x->km.state == XFRM_STATE_VALID) {
744744
if ((x->sel.family &&
745-
!xfrm_selector_match(&x->sel, fl, x->sel.family)) ||
745+
(x->sel.family != family ||
746+
!xfrm_selector_match(&x->sel, fl, family))) ||
746747
!security_xfrm_state_pol_flow_match(x, pol, fl))
747748
return;
748749

@@ -755,7 +756,9 @@ static void xfrm_state_look_at(struct xfrm_policy *pol, struct xfrm_state *x,
755756
*acq_in_progress = 1;
756757
} else if (x->km.state == XFRM_STATE_ERROR ||
757758
x->km.state == XFRM_STATE_EXPIRED) {
758-
if (xfrm_selector_match(&x->sel, fl, x->sel.family) &&
759+
if ((!x->sel.family ||
760+
(x->sel.family == family &&
761+
xfrm_selector_match(&x->sel, fl, family))) &&
759762
security_xfrm_state_pol_flow_match(x, pol, fl))
760763
*error = -ESRCH;
761764
}
@@ -791,7 +794,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
791794
tmpl->mode == x->props.mode &&
792795
tmpl->id.proto == x->id.proto &&
793796
(tmpl->id.spi == x->id.spi || !tmpl->id.spi))
794-
xfrm_state_look_at(pol, x, fl, encap_family,
797+
xfrm_state_look_at(pol, x, fl, family,
795798
&best, &acquire_in_progress, &error);
796799
}
797800
if (best || acquire_in_progress)
@@ -807,7 +810,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
807810
tmpl->mode == x->props.mode &&
808811
tmpl->id.proto == x->id.proto &&
809812
(tmpl->id.spi == x->id.spi || !tmpl->id.spi))
810-
xfrm_state_look_at(pol, x, fl, encap_family,
813+
xfrm_state_look_at(pol, x, fl, family,
811814
&best, &acquire_in_progress, &error);
812815
}
813816

0 commit comments

Comments
 (0)