net: esp{4,6}: fix potential MTU calculation overflows
Subsystems (3)
PATCH 1/1 net: esp{4,6}: fix potential MTU calculation overflows
Commit 91657eafb ("xfrm: take net hdr len into account for esp payload size calculation") introduced a possible interger overflow in esp{4,6}_get_mtu() handlers in case of x->props.mode equals XFRM_MODE_TUNNEL. Thus, the following expression will overflow
unsigned int net_adj;
...
<case ipv{4,6} XFRM_MODE_TUNNEL>
net_adj = 0;
...
return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
net_adj) & ~(align - 1)) + (net_adj - 2);where (net_adj - 2) would be evaluated as <foo> + (0 - 2) in an unsigned context. Fix it by simply removing brackets as those operations here do not need to have special precedence.
---
Note: only compile tested, maybe Benjamin can comment on why he added
brackets around this expression. *If* this is valid (which I do not think), then this needs at least a big comment explaining so.
net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/esp4.c +1 -1
@@ -477,7 +477,7 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) }return ((mtu - x->props.header_len -crypto_aead_authsize (esp->aead) - - net_adj) & ~(align -1 )) + (net_adj -2 ); + net_adj) & ~(align -1 )) + net_adj -2 ; }static void esp4_err (struct sk_buff *skb,u32 info)
net/ipv6/esp6.c +1 -1
@@ -425,7 +425,7 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu) net_adj =0 ;return ((mtu - x->props.header_len -crypto_aead_authsize (esp->aead) - - net_adj) & ~(align -1 )) + (net_adj -2 ); + net_adj) & ~(align -1 )) + net_adj -2 ; } static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
Signature · 1 line
1.7.11.7
Quoted 13 lines · Daniel Borkmann
Commit
91657eafb("xfrm: take net hdr len into account for esp payload size calculation") introduced a possible interger overflow in esp{4,6}_get_mtu() handlers in case ofx->props.modeequalsXFRM_MODE_TUNNEL. Thus, the following expression will overflowunsigned int net_adj; ... <case ipv{4,6} XFRM_MODE_TUNNEL> net_adj = 0; ... return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - net_adj) & ~(align - 1)) + (net_adj - 2);
Quoted 2 lines
where (
net_adj- 2) would be evaluated as <foo> + (0 - 2) in an unsigned context. Fix it by simply removing brackets as those operations here
I can see this creating problems if there was comparison or type promotion, but I don't see an integer overflow.
In any case, it is right to remove the parentheses. They are dubious style at the expense of correctness. They have no effect in this case.
Quoted 43 lines
do not need to have special precedence.
Signed-off-by Daniel Borkmann <[email protected]>Cc Benjamin Poirier <[email protected]>Cc Steffen Klassert <[email protected]>---
Note: only compile tested, maybe Benjamin can comment on why he added
brackets around this expression. *If* this is valid (which I do not think), then this needs at least a big comment explaining so.net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)net/ipv4/esp4.c +1
-1@@ -477,7 +477,7 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) }return ((mtu - x->props.header_len -crypto_aead_authsize (esp->aead) - - net_adj) & ~(align -1 )) + (net_adj -2 ); + net_adj) & ~(align -1 )) + net_adj -2 ; }static void esp4_err (struct sk_buff *skb,u32 info)net/ipv6/esp6.c +1
-1@@ -425,7 +425,7 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu) net_adj =0 ;return ((mtu - x->props.header_len -crypto_aead_authsize (esp->aead) - - net_adj) & ~(align -1 )) + (net_adj -2 ); + net_adj) & ~(align -1 )) + net_adj -2 ; } static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,Signature · 1 line
1.7.11.7
From: Daniel Borkmann <[email protected]>
Date: Mon, 5 Aug 2013 12:49:35 +0200
Quoted 13 lines
Commit
91657eafb("xfrm: take net hdr len into account for esp payload size calculation") introduced a possible interger overflow in esp{4,6}_get_mtu() handlers in case ofx->props.modeequalsXFRM_MODE_TUNNEL. Thus, the following expression will overflowunsigned int net_adj; ... <case ipv{4,6} XFRM_MODE_TUNNEL> net_adj = 0; ... return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - net_adj) & ~(align - 1)) + (net_adj - 2);
Quoted 5 lines
where (
net_adj- 2) would be evaluated as <foo> + (0 - 2) in an unsigned context. Fix it by simply removing brackets as those operations here do not need to have special precedence.Signed-off-by Daniel Borkmann <[email protected]>
Applied.