Skip to contentSkip to conversation

distributor: fix potential overflow bug

PATCH Applied Bruce Richardson 3 participants 3 messages Feb 17, 2022 – Feb 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 distributor: fix potential overflow bug

Coverity flags the fact that the tag values used in distributor are 32-bit, which means that when we use bit-manipulation to convert a tag match/no-match to a bit in an array, we need to typecast to a 64-bit type before shifting past 32 bits.

Coverity issue: 375808

Fixes 08ccf3faa6a9 ("distributor: new packet distributor library")
---
 lib/distributor/rte_distributor_single.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/distributor/rte_distributor_single.c +1 -2
index b653620688..60ca86152f 100644
@@ -247,8 +247,7 @@ rte_distributor_process_single(struct rte_distributor_single *d,
 			 * worker given by the bit-position
 			 */
 			for (i = 0; i < d->num_workers; i++)
-				match |= (!(d->in_flight_tags[i] ^ new_tag)
-					<< i);
+				match |= ((uint64_t)!(d->in_flight_tags[i] ^ new_tag) << i);
 
 			/* Only turned-on bits are considered as match */
 			match &= d->in_flight_bitmask;
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw

Hi Bruce,

Quoted 19 lines · Bruce Richardson

Coverity flags the fact that the tag values used in distributor are 32-bit, which means that when we use bit-manipulation to convert a tag match/no-match to a bit in an array, we need to typecast to a 64-bit type before shifting past 32 bits.

Coverity issue: 375808

Fixes 08ccf3faa6a9 ("distributor: new packet distributor library")
---
  lib/distributor/rte_distributor_single.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
lib/distributor/rte_distributor_single.c +0 -0
index b653620688..60ca86152f 100644

lib/distributor/rte_distributor_single.c rte_distributor_process_single(struct rte_distributor_single *d, · line 253

Quoted 9 lines
lib/distributor/rte_distributor_single.c +1 -2
@@ -247,8 +247,7 @@ rte_distributor_process_single(struct rte_distributor_single *d,
  			 * worker given by the bit-position
  			 */
  			for (i = 0; i < d->num_workers; i++)
-				match |= (!(d->in_flight_tags[i] ^ new_tag)
-					<< i);
+				match |= ((uint64_t)!(d->in_flight_tags[i] ^ new_tag) << i);
 
  			/* Only turned-on bits are considered as match */
  			match &= d->in_flight_bitmask;

LGTM

#2 lore raw

17/02/2022 16:24, David Hunt:

Quoted 12 lines

Hi Bruce,

Quoted 9 lines · Bruce Richardson

Coverity flags the fact that the tag values used in distributor are 32-bit, which means that when we use bit-manipulation to convert a tag match/no-match to a bit in an array, we need to typecast to a 64-bit type before shifting past 32 bits.

Coverity issue: 375808

Fixes 08ccf3faa6a9 ("distributor: new packet distributor library")
Quoted 5 lines
Quoted 1 line

LGTM

Applied, thanks.