* [PATCH] net/xfrm/xfrm_replay: avoid division by zero
@ 2013-01-17 18:58 Nickolai Zeldovich
2013-01-17 20:46 ` David Miller
2013-01-18 8:57 ` Steffen Klassert
0 siblings, 2 replies; 3+ messages in thread
From: Nickolai Zeldovich @ 2013-01-17 18:58 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Nickolai Zeldovich, netdev, linux-kernel
All of the xfrm_replay->advance functions in xfrm_replay.c check if
x->replay_esn->replay_window is zero (and return if so). However,
one of them, xfrm_replay_advance_bmp(), divides by that value (in the
'%' operator) before doing the check, which can potentially trigger
a divide-by-zero exception. Some compilers will also assume that the
earlier division means the value cannot be zero later, and thus will
eliminate the subsequent zero check as dead code.
This patch moves the division to after the check.
Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
---
net/xfrm/xfrm_replay.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c
index 765f6fe..35754cc 100644
--- a/net/xfrm/xfrm_replay.c
+++ b/net/xfrm/xfrm_replay.c
@@ -242,11 +242,13 @@ static void xfrm_replay_advance_bmp(struct xfrm_state *x, __be32 net_seq)
u32 diff;
struct xfrm_replay_state_esn *replay_esn = x->replay_esn;
u32 seq = ntohl(net_seq);
- u32 pos = (replay_esn->seq - 1) % replay_esn->replay_window;
+ u32 pos;
if (!replay_esn->replay_window)
return;
+ pos = (replay_esn->seq - 1) % replay_esn->replay_window;
+
if (seq > replay_esn->seq) {
diff = seq - replay_esn->seq;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net/xfrm/xfrm_replay: avoid division by zero
2013-01-17 18:58 [PATCH] net/xfrm/xfrm_replay: avoid division by zero Nickolai Zeldovich
@ 2013-01-17 20:46 ` David Miller
2013-01-18 8:57 ` Steffen Klassert
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2013-01-17 20:46 UTC (permalink / raw)
To: nickolai; +Cc: steffen.klassert, herbert, netdev, linux-kernel
From: Nickolai Zeldovich <nickolai@csail.mit.edu>
Date: Thu, 17 Jan 2013 13:58:28 -0500
> All of the xfrm_replay->advance functions in xfrm_replay.c check if
> x->replay_esn->replay_window is zero (and return if so). However,
> one of them, xfrm_replay_advance_bmp(), divides by that value (in the
> '%' operator) before doing the check, which can potentially trigger
> a divide-by-zero exception. Some compilers will also assume that the
> earlier division means the value cannot be zero later, and thus will
> eliminate the subsequent zero check as dead code.
>
> This patch moves the division to after the check.
>
> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
I'm assuming Steffen will take care of this patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/xfrm/xfrm_replay: avoid division by zero
2013-01-17 18:58 [PATCH] net/xfrm/xfrm_replay: avoid division by zero Nickolai Zeldovich
2013-01-17 20:46 ` David Miller
@ 2013-01-18 8:57 ` Steffen Klassert
1 sibling, 0 replies; 3+ messages in thread
From: Steffen Klassert @ 2013-01-18 8:57 UTC (permalink / raw)
To: Nickolai Zeldovich; +Cc: Herbert Xu, David S. Miller, netdev, linux-kernel
On Thu, Jan 17, 2013 at 01:58:28PM -0500, Nickolai Zeldovich wrote:
> All of the xfrm_replay->advance functions in xfrm_replay.c check if
> x->replay_esn->replay_window is zero (and return if so). However,
> one of them, xfrm_replay_advance_bmp(), divides by that value (in the
> '%' operator) before doing the check, which can potentially trigger
> a divide-by-zero exception. Some compilers will also assume that the
> earlier division means the value cannot be zero later, and thus will
> eliminate the subsequent zero check as dead code.
>
> This patch moves the division to after the check.
>
> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-01-18 8:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-17 18:58 [PATCH] net/xfrm/xfrm_replay: avoid division by zero Nickolai Zeldovich
2013-01-17 20:46 ` David Miller
2013-01-18 8:57 ` Steffen Klassert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).