Skip to content

Commit 15f5fe9

Browse files
antonyantonyklassert
authored andcommitted
xfrm: Log input direction mismatch error in one place
Previously, the offload data path decrypted the packet before checking the direction, leading to error logging and packet dropping. However, dropped packets wouldn't be visible in tcpdump or audit log. With this fix, the offload path, upon noticing SA direction mismatch, will pass the packet to the stack without decrypting it. The L3 layer will then log the error, audit, and drop ESP without decrypting or decapsulating it. This also ensures that the slow path records the error and audit log, making dropped packets visible in tcpdump. Fixes: 304b44f ("xfrm: Add dir validation to "in" data path lookup") Signed-off-by: Antony Antony <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 54fcc61 commit 15f5fe9

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

net/ipv4/esp4_offload.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,
5656
x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
5757
(xfrm_address_t *)&ip_hdr(skb)->daddr,
5858
spi, IPPROTO_ESP, AF_INET);
59+
60+
if (unlikely(x && x->dir && x->dir != XFRM_SA_DIR_IN)) {
61+
/* non-offload path will record the error and audit log */
62+
xfrm_state_put(x);
63+
x = NULL;
64+
}
65+
5966
if (!x)
6067
goto out_reset;
6168

net/ipv6/esp6_offload.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,
8383
x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
8484
(xfrm_address_t *)&ipv6_hdr(skb)->daddr,
8585
spi, IPPROTO_ESP, AF_INET6);
86+
87+
if (unlikely(x && x->dir && x->dir != XFRM_SA_DIR_IN)) {
88+
/* non-offload path will record the error and audit log */
89+
xfrm_state_put(x);
90+
x = NULL;
91+
}
92+
8693
if (!x)
8794
goto out_reset;
8895

net/xfrm/xfrm_input.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
474474
if (encap_type < 0 || (xo && xo->flags & XFRM_GRO)) {
475475
x = xfrm_input_state(skb);
476476

477-
if (unlikely(x->dir && x->dir != XFRM_SA_DIR_IN)) {
478-
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEDIRERROR);
479-
goto drop;
480-
}
481-
482477
if (unlikely(x->km.state != XFRM_STATE_VALID)) {
483478
if (x->km.state == XFRM_STATE_ACQ)
484479
XFRM_INC_STATS(net, LINUX_MIB_XFRMACQUIREERROR);

0 commit comments

Comments
 (0)