Skip to content

Commit 35c715c

Browse files
committed
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec
Steffen Klassert says: ==================== pull request (net): ipsec 2021-01-21 1) Fix a rare panic on SMP systems when packet reordering happens between anti replay check and update. From Shmulik Ladkani. 2) Fix disable_xfrm sysctl when used on xfrm interfaces. From Eyal Birger. 3) Fix a race in PF_KEY when the availability of crypto algorithms is set. From Cong Wang. 4) Fix a return value override in the xfrm policy selftests. From Po-Hsu Lin. 5) Fix an integer wraparound in xfrm_policy_addr_delta. From Visa Hankala. * 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec: xfrm: Fix wraparound in xfrm_policy_addr_delta() selftests: xfrm: fix test return value override issue in xfrm_policy.sh af_key: relax availability checks for skb size calculation xfrm: fix disable_xfrm sysctl when used on xfrm interfaces xfrm: Fix oops in xfrm_replay_advance_bmp ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 1c45ba9 + da64ae2 commit 35c715c

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

net/key/af_key.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,7 @@ static int count_ah_combs(const struct xfrm_tmpl *t)
29022902
break;
29032903
if (!aalg->pfkey_supported)
29042904
continue;
2905-
if (aalg_tmpl_set(t, aalg) && aalg->available)
2905+
if (aalg_tmpl_set(t, aalg))
29062906
sz += sizeof(struct sadb_comb);
29072907
}
29082908
return sz + sizeof(struct sadb_prop);
@@ -2920,7 +2920,7 @@ static int count_esp_combs(const struct xfrm_tmpl *t)
29202920
if (!ealg->pfkey_supported)
29212921
continue;
29222922

2923-
if (!(ealg_tmpl_set(t, ealg) && ealg->available))
2923+
if (!(ealg_tmpl_set(t, ealg)))
29242924
continue;
29252925

29262926
for (k = 1; ; k++) {
@@ -2931,7 +2931,7 @@ static int count_esp_combs(const struct xfrm_tmpl *t)
29312931
if (!aalg->pfkey_supported)
29322932
continue;
29332933

2934-
if (aalg_tmpl_set(t, aalg) && aalg->available)
2934+
if (aalg_tmpl_set(t, aalg))
29352935
sz += sizeof(struct sadb_comb);
29362936
}
29372937
}

net/xfrm/xfrm_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
660660
/* only the first xfrm gets the encap type */
661661
encap_type = 0;
662662

663-
if (async && x->repl->recheck(x, skb, seq)) {
663+
if (x->repl->recheck(x, skb, seq)) {
664664
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
665665
goto drop_unlock;
666666
}

net/xfrm/xfrm_policy.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,22 @@ static int xfrm_policy_addr_delta(const xfrm_address_t *a,
793793
const xfrm_address_t *b,
794794
u8 prefixlen, u16 family)
795795
{
796+
u32 ma, mb, mask;
796797
unsigned int pdw, pbi;
797798
int delta = 0;
798799

799800
switch (family) {
800801
case AF_INET:
801-
if (sizeof(long) == 4 && prefixlen == 0)
802-
return ntohl(a->a4) - ntohl(b->a4);
803-
return (ntohl(a->a4) & ((~0UL << (32 - prefixlen)))) -
804-
(ntohl(b->a4) & ((~0UL << (32 - prefixlen))));
802+
if (prefixlen == 0)
803+
return 0;
804+
mask = ~0U << (32 - prefixlen);
805+
ma = ntohl(a->a4) & mask;
806+
mb = ntohl(b->a4) & mask;
807+
if (ma < mb)
808+
delta = -1;
809+
else if (ma > mb)
810+
delta = 1;
811+
break;
805812
case AF_INET6:
806813
pdw = prefixlen >> 5;
807814
pbi = prefixlen & 0x1f;
@@ -812,10 +819,13 @@ static int xfrm_policy_addr_delta(const xfrm_address_t *a,
812819
return delta;
813820
}
814821
if (pbi) {
815-
u32 mask = ~0u << (32 - pbi);
816-
817-
delta = (ntohl(a->a6[pdw]) & mask) -
818-
(ntohl(b->a6[pdw]) & mask);
822+
mask = ~0U << (32 - pbi);
823+
ma = ntohl(a->a6[pdw]) & mask;
824+
mb = ntohl(b->a6[pdw]) & mask;
825+
if (ma < mb)
826+
delta = -1;
827+
else if (ma > mb)
828+
delta = 1;
819829
}
820830
break;
821831
default:
@@ -3078,8 +3088,8 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
30783088
xflo.flags = flags;
30793089

30803090
/* To accelerate a bit... */
3081-
if ((dst_orig->flags & DST_NOXFRM) ||
3082-
!net->xfrm.policy_count[XFRM_POLICY_OUT])
3091+
if (!if_id && ((dst_orig->flags & DST_NOXFRM) ||
3092+
!net->xfrm.policy_count[XFRM_POLICY_OUT]))
30833093
goto nopol;
30843094

30853095
xdst = xfrm_bundle_lookup(net, fl, family, dir, &xflo, if_id);

tools/testing/selftests/net/xfrm_policy.sh

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ check_xfrm() {
202202
# 1: iptables -m policy rule count != 0
203203
rval=$1
204204
ip=$2
205-
lret=0
205+
local lret=0
206206

207207
ip netns exec ns1 ping -q -c 1 10.0.2.$ip > /dev/null
208208

@@ -287,6 +287,47 @@ check_hthresh_repeat()
287287
return 0
288288
}
289289

290+
# insert non-overlapping policies in a random order and check that
291+
# all of them can be fetched using the traffic selectors.
292+
check_random_order()
293+
{
294+
local ns=$1
295+
local log=$2
296+
297+
for i in $(seq 100); do
298+
ip -net $ns xfrm policy flush
299+
for j in $(seq 0 16 255 | sort -R); do
300+
ip -net $ns xfrm policy add dst $j.0.0.0/24 dir out priority 10 action allow
301+
done
302+
for j in $(seq 0 16 255); do
303+
if ! ip -net $ns xfrm policy get dst $j.0.0.0/24 dir out > /dev/null; then
304+
echo "FAIL: $log" 1>&2
305+
return 1
306+
fi
307+
done
308+
done
309+
310+
for i in $(seq 100); do
311+
ip -net $ns xfrm policy flush
312+
for j in $(seq 0 16 255 | sort -R); do
313+
local addr=$(printf "e000:0000:%02x00::/56" $j)
314+
ip -net $ns xfrm policy add dst $addr dir out priority 10 action allow
315+
done
316+
for j in $(seq 0 16 255); do
317+
local addr=$(printf "e000:0000:%02x00::/56" $j)
318+
if ! ip -net $ns xfrm policy get dst $addr dir out > /dev/null; then
319+
echo "FAIL: $log" 1>&2
320+
return 1
321+
fi
322+
done
323+
done
324+
325+
ip -net $ns xfrm policy flush
326+
327+
echo "PASS: $log"
328+
return 0
329+
}
330+
290331
#check for needed privileges
291332
if [ "$(id -u)" -ne 0 ];then
292333
echo "SKIP: Need root privileges"
@@ -438,6 +479,8 @@ check_exceptions "exceptions and block policies after htresh change to normal"
438479

439480
check_hthresh_repeat "policies with repeated htresh change"
440481

482+
check_random_order ns3 "policies inserted in random order"
483+
441484
for i in 1 2 3 4;do ip netns del ns$i;done
442485

443486
exit $ret

0 commit comments

Comments
 (0)