diff options
author | Willem de Bruijn <willemb@google.com> | 2015-06-17 15:59:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-07-10 12:49:28 -0400 |
commit | 2c330edb4b31fdf18c6a6c4d1d9b482632c3925b (patch) | |
tree | b709ec58c3b868315473e5e08e9c1c423693cc4c /net/packet | |
parent | d7884e43677ba8618ae2f1ead7b96b215b409e20 (diff) |
packet: avoid out of bounds read in round robin fanout
[ Upstream commit 468479e6043c84f5a65299cc07cb08a22a28c2b1 ]
PACKET_FANOUT_LB computes f->rr_cur such that it is modulo
f->num_members. It returns the old value unconditionally, but
f->num_members may have changed since the last store. Ensure
that the return value is always < num.
When modifying the logic, simplify it further by replacing the loop
with an unconditional atomic increment.
Fixes: dc99f600698d ("packet: Add fanout support.")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/packet')
-rw-r--r-- | net/packet/af_packet.c | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 131545a06f05..fe1610ddeacf 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -1272,16 +1272,6 @@ static void packet_sock_destruct(struct sock *sk) | |||
1272 | sk_refcnt_debug_dec(sk); | 1272 | sk_refcnt_debug_dec(sk); |
1273 | } | 1273 | } |
1274 | 1274 | ||
1275 | static int fanout_rr_next(struct packet_fanout *f, unsigned int num) | ||
1276 | { | ||
1277 | int x = atomic_read(&f->rr_cur) + 1; | ||
1278 | |||
1279 | if (x >= num) | ||
1280 | x = 0; | ||
1281 | |||
1282 | return x; | ||
1283 | } | ||
1284 | |||
1285 | static unsigned int fanout_demux_hash(struct packet_fanout *f, | 1275 | static unsigned int fanout_demux_hash(struct packet_fanout *f, |
1286 | struct sk_buff *skb, | 1276 | struct sk_buff *skb, |
1287 | unsigned int num) | 1277 | unsigned int num) |
@@ -1293,13 +1283,9 @@ static unsigned int fanout_demux_lb(struct packet_fanout *f, | |||
1293 | struct sk_buff *skb, | 1283 | struct sk_buff *skb, |
1294 | unsigned int num) | 1284 | unsigned int num) |
1295 | { | 1285 | { |
1296 | int cur, old; | 1286 | unsigned int val = atomic_inc_return(&f->rr_cur); |
1297 | 1287 | ||
1298 | cur = atomic_read(&f->rr_cur); | 1288 | return val % num; |
1299 | while ((old = atomic_cmpxchg(&f->rr_cur, cur, | ||
1300 | fanout_rr_next(f, num))) != cur) | ||
1301 | cur = old; | ||
1302 | return cur; | ||
1303 | } | 1289 | } |
1304 | 1290 | ||
1305 | static unsigned int fanout_demux_cpu(struct packet_fanout *f, | 1291 | static unsigned int fanout_demux_cpu(struct packet_fanout *f, |