[v1] lib/metrics: add check for invalid metric keys

Message ID 20180706132119.9013-1-remy.horton@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] lib/metrics: add check for invalid metric keys |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Remy Horton July 6, 2018, 1:21 p.m. UTC
  This patchset adds a check to rte_metrics_update_values()
that prevents the updating of metrics when presented with
an invalid metric key. Previously, doing the latter could
result in a crash.

Fixes: 349950ddb9c5 ("metrics: add information metrics library")

Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 lib/librte_metrics/rte_metrics.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Ferruh Yigit July 20, 2018, 3:31 p.m. UTC | #1
On 7/6/2018 2:21 PM, Remy Horton wrote:
> This patchset adds a check to rte_metrics_update_values()
> that prevents the updating of metrics when presented with
> an invalid metric key. Previously, doing the latter could
> result in a crash.
> 
> Fixes: 349950ddb9c5 ("metrics: add information metrics library")
> 
> Signed-off-by: Remy Horton <remy.horton@intel.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Thomas Monjalon July 26, 2018, 6:11 p.m. UTC | #2
Remy,
You are not new to DPDK. Please pay attention to details:
- subject does not start with lib/
- fixes of old commits must have Cc: stable@dpdk.org

20/07/2018 17:31, Ferruh Yigit:
> On 7/6/2018 2:21 PM, Remy Horton wrote:
> > This patchset adds a check to rte_metrics_update_values()
> > that prevents the updating of metrics when presented with
> > an invalid metric key. Previously, doing the latter could
> > result in a crash.
> > 
> > Fixes: 349950ddb9c5 ("metrics: add information metrics library")
> > 
> > Signed-off-by: Remy Horton <remy.horton@intel.com>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied, thanks
  
Remy Horton July 27, 2018, 7 a.m. UTC | #3
Harry,

Can you add the following to the cheat-sheet? Don't do many patches 
these days, and I'm not the only one to miss these recently..

..Remy

On 26/07/2018 19:11, Thomas Monjalon wrote:
> Remy,
> You are not new to DPDK. Please pay attention to details:
> - subject does not start with lib/
> - fixes of old commits must have Cc: stable@dpdk.org
>
> 20/07/2018 17:31, Ferruh Yigit:
>> On 7/6/2018 2:21 PM, Remy Horton wrote:
>>> This patchset adds a check to rte_metrics_update_values()
>>> that prevents the updating of metrics when presented with
>>> an invalid metric key. Previously, doing the latter could
>>> result in a crash.
>>>
>>> Fixes: 349950ddb9c5 ("metrics: add information metrics library")
>>>
>>> Signed-off-by: Remy Horton <remy.horton@intel.com>
>>
>> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
>
> Applied, thanks
>
>
  

Patch

diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c
index 258f058..b5638f5 100644
--- a/lib/librte_metrics/rte_metrics.c
+++ b/lib/librte_metrics/rte_metrics.c
@@ -159,6 +159,11 @@  rte_metrics_update_values(int port_id,
 	stats = memzone->addr;
 
 	rte_spinlock_lock(&stats->lock);
+
+	if (key >= stats->cnt_stats) {
+		rte_spinlock_unlock(&stats->lock);
+		return -EINVAL;
+	}
 	idx_metric = key;
 	cnt_setsize = 1;
 	while (idx_metric < stats->cnt_stats) {