Skip to content

Commit 2da4c18

Browse files
committed
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec
Steffen Klassert says: ==================== 1) Fix packet receiving of standard IP tunnels when the xfrm_interface module is installed. From Xin Long. 2) Fix a race condition between spi allocating and hash list resizing. From zhuoliang zhang. ==================== Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents fea07a4 + a779d91 commit 2da4c18

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

net/ipv4/xfrm4_tunnel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
6464
static struct xfrm_tunnel xfrm_tunnel_handler __read_mostly = {
6565
.handler = xfrm_tunnel_rcv,
6666
.err_handler = xfrm_tunnel_err,
67-
.priority = 3,
67+
.priority = 4,
6868
};
6969

7070
#if IS_ENABLED(CONFIG_IPV6)
7171
static struct xfrm_tunnel xfrm64_tunnel_handler __read_mostly = {
7272
.handler = xfrm_tunnel_rcv,
7373
.err_handler = xfrm_tunnel_err,
74-
.priority = 2,
74+
.priority = 3,
7575
};
7676
#endif
7777

net/ipv6/xfrm6_tunnel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ static const struct xfrm_type xfrm6_tunnel_type = {
303303
static struct xfrm6_tunnel xfrm6_tunnel_handler __read_mostly = {
304304
.handler = xfrm6_tunnel_rcv,
305305
.err_handler = xfrm6_tunnel_err,
306-
.priority = 2,
306+
.priority = 3,
307307
};
308308

309309
static struct xfrm6_tunnel xfrm46_tunnel_handler __read_mostly = {
310310
.handler = xfrm6_tunnel_rcv,
311311
.err_handler = xfrm6_tunnel_err,
312-
.priority = 2,
312+
.priority = 3,
313313
};
314314

315315
static int __net_init xfrm6_tunnel_net_init(struct net *net)

net/xfrm/xfrm_interface.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,14 @@ static struct xfrm6_tunnel xfrmi_ipv6_handler __read_mostly = {
803803
.handler = xfrmi6_rcv_tunnel,
804804
.cb_handler = xfrmi_rcv_cb,
805805
.err_handler = xfrmi6_err,
806-
.priority = -1,
806+
.priority = 2,
807807
};
808808

809809
static struct xfrm6_tunnel xfrmi_ip6ip_handler __read_mostly = {
810810
.handler = xfrmi6_rcv_tunnel,
811811
.cb_handler = xfrmi_rcv_cb,
812812
.err_handler = xfrmi6_err,
813-
.priority = -1,
813+
.priority = 2,
814814
};
815815
#endif
816816

@@ -848,14 +848,14 @@ static struct xfrm_tunnel xfrmi_ipip_handler __read_mostly = {
848848
.handler = xfrmi4_rcv_tunnel,
849849
.cb_handler = xfrmi_rcv_cb,
850850
.err_handler = xfrmi4_err,
851-
.priority = -1,
851+
.priority = 3,
852852
};
853853

854854
static struct xfrm_tunnel xfrmi_ipip6_handler __read_mostly = {
855855
.handler = xfrmi4_rcv_tunnel,
856856
.cb_handler = xfrmi_rcv_cb,
857857
.err_handler = xfrmi4_err,
858-
.priority = -1,
858+
.priority = 2,
859859
};
860860
#endif
861861

net/xfrm/xfrm_state.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
20042004
int err = -ENOENT;
20052005
__be32 minspi = htonl(low);
20062006
__be32 maxspi = htonl(high);
2007+
__be32 newspi = 0;
20072008
u32 mark = x->mark.v & x->mark.m;
20082009

20092010
spin_lock_bh(&x->lock);
@@ -2022,21 +2023,22 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
20222023
xfrm_state_put(x0);
20232024
goto unlock;
20242025
}
2025-
x->id.spi = minspi;
2026+
newspi = minspi;
20262027
} else {
20272028
u32 spi = 0;
20282029
for (h = 0; h < high-low+1; h++) {
20292030
spi = low + prandom_u32()%(high-low+1);
20302031
x0 = xfrm_state_lookup(net, mark, &x->id.daddr, htonl(spi), x->id.proto, x->props.family);
20312032
if (x0 == NULL) {
2032-
x->id.spi = htonl(spi);
2033+
newspi = htonl(spi);
20332034
break;
20342035
}
20352036
xfrm_state_put(x0);
20362037
}
20372038
}
2038-
if (x->id.spi) {
2039+
if (newspi) {
20392040
spin_lock_bh(&net->xfrm.xfrm_state_lock);
2041+
x->id.spi = newspi;
20402042
h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, x->props.family);
20412043
hlist_add_head_rcu(&x->byspi, net->xfrm.state_byspi + h);
20422044
spin_unlock_bh(&net->xfrm.xfrm_state_lock);

0 commit comments

Comments
 (0)