distributor: fix potential overflow bug

Message ID 20220217150239.69876-1-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Bruce Richardson Feb. 17, 2022, 3:02 p.m. UTC
  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")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/distributor/rte_distributor_single.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Hunt, David Feb. 17, 2022, 3:24 p.m. UTC | #1
Hi Bruce,

On 17/2/2022 3:02 PM, Bruce Richardson wrote:
> 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")
> Cc: stable@dpdk.org
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>   lib/distributor/rte_distributor_single.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/distributor/rte_distributor_single.c b/lib/distributor/rte_distributor_single.c
> index b653620688..60ca86152f 100644
> --- a/lib/distributor/rte_distributor_single.c
> +++ b/lib/distributor/rte_distributor_single.c
> @@ -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

Acked-by: David Hunt <david.hunt@intel.com>
  
Thomas Monjalon Feb. 27, 2022, 6:07 p.m. UTC | #2
17/02/2022 16:24, David Hunt:
> Hi Bruce,
> 
> On 17/2/2022 3:02 PM, Bruce Richardson wrote:
> > 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")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> LGTM
> 
> Acked-by: David Hunt <david.hunt@intel.com>

Applied, thanks.
  

Patch

diff --git a/lib/distributor/rte_distributor_single.c b/lib/distributor/rte_distributor_single.c
index b653620688..60ca86152f 100644
--- a/lib/distributor/rte_distributor_single.c
+++ b/lib/distributor/rte_distributor_single.c
@@ -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;