* [PATCH] event/dlb2: fix invalid shift value
@ 2022-03-02 15:12 Timothy McDaniel
2022-03-03 9:25 ` Jerin Jacob
0 siblings, 1 reply; 2+ messages in thread
From: Timothy McDaniel @ 2022-03-02 15:12 UTC (permalink / raw)
To: jerinj; +Cc: john.mcnamara, dev
Add a check to ensure that all shift counts are valid.
Shifting by more than 63 bits may result in undefined behavior, as
noted during coverity scan.
Fixes: e697f35dbdd1 ("event/dlb2: update rolling mask used for dequeue")
Coverity issue: 376527
Signed-off-by: Timothy McDaniel <timothy.mcdaniel@intel.com>
---
drivers/event/dlb2/dlb2.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/event/dlb2/dlb2.c b/drivers/event/dlb2/dlb2.c
index 09abdd1660..7789dd74e0 100644
--- a/drivers/event/dlb2/dlb2.c
+++ b/drivers/event/dlb2/dlb2.c
@@ -3916,15 +3916,17 @@ dlb2_hw_dequeue_sparse(struct dlb2_eventdev *dlb2,
&events[num],
&qes[0],
num_avail);
- num += n_iter;
- /* update rolling_mask for vector code support */
- m_rshift = qm_port->cq_rolling_mask >> n_iter;
- m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
- m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
- m2_lshift = qm_port->cq_rolling_mask_2 <<
+ if (n_iter != 0) {
+ num += n_iter;
+ /* update rolling_mask for vector code support */
+ m_rshift = qm_port->cq_rolling_mask >> n_iter;
+ m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
+ m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
+ m2_lshift = qm_port->cq_rolling_mask_2 <<
(64 - n_iter);
- qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
- qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
+ qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
+ qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
+ }
} else { /* !use_scalar */
num_avail = dlb2_recv_qe_sparse_vec(qm_port,
&events[num],
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] event/dlb2: fix invalid shift value
2022-03-02 15:12 [PATCH] event/dlb2: fix invalid shift value Timothy McDaniel
@ 2022-03-03 9:25 ` Jerin Jacob
0 siblings, 0 replies; 2+ messages in thread
From: Jerin Jacob @ 2022-03-03 9:25 UTC (permalink / raw)
To: Timothy McDaniel; +Cc: Jerin Jacob, John McNamara, dpdk-dev
On Wed, Mar 2, 2022 at 8:42 PM Timothy McDaniel
<timothy.mcdaniel@intel.com> wrote:
>
> Add a check to ensure that all shift counts are valid.
> Shifting by more than 63 bits may result in undefined behavior, as
> noted during coverity scan.
>
> Fixes: e697f35dbdd1 ("event/dlb2: update rolling mask used for dequeue")
> Coverity issue: 376527
Applied to dpdk-next-net-eventdev/for-main. Thanks
> Signed-off-by: Timothy McDaniel <timothy.mcdaniel@intel.com>
> ---
> drivers/event/dlb2/dlb2.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/event/dlb2/dlb2.c b/drivers/event/dlb2/dlb2.c
> index 09abdd1660..7789dd74e0 100644
> --- a/drivers/event/dlb2/dlb2.c
> +++ b/drivers/event/dlb2/dlb2.c
> @@ -3916,15 +3916,17 @@ dlb2_hw_dequeue_sparse(struct dlb2_eventdev *dlb2,
> &events[num],
> &qes[0],
> num_avail);
> - num += n_iter;
> - /* update rolling_mask for vector code support */
> - m_rshift = qm_port->cq_rolling_mask >> n_iter;
> - m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
> - m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
> - m2_lshift = qm_port->cq_rolling_mask_2 <<
> + if (n_iter != 0) {
> + num += n_iter;
> + /* update rolling_mask for vector code support */
> + m_rshift = qm_port->cq_rolling_mask >> n_iter;
> + m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
> + m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
> + m2_lshift = qm_port->cq_rolling_mask_2 <<
> (64 - n_iter);
> - qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
> - qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
> + qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
> + qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
> + }
> } else { /* !use_scalar */
> num_avail = dlb2_recv_qe_sparse_vec(qm_port,
> &events[num],
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-03 9:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 15:12 [PATCH] event/dlb2: fix invalid shift value Timothy McDaniel
2022-03-03 9:25 ` Jerin Jacob
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).