telemetry: reset data before passing it to callback

Message ID 20230207184520.1238366-1-rjarry@redhat.com (mailing list archive)
State Rejected, archived
Delegated to: David Marchand
Headers
Series telemetry: reset data before passing it to callback |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Robin Jarry Feb. 7, 2023, 6:45 p.m. UTC
  If a telemetry endpoint callback returns 0 without modifying the data
object, output_json() may be called with undefined contents in data.
This can cause crashes and/or worse (double free, etc.).

Reset data before passing it to the endpoint callbacks.

Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
Cc: stable@dpdk.org

Signed-off-by: Robin Jarry <rjarry@redhat.com>
---
 lib/telemetry/telemetry.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Bruce Richardson Feb. 8, 2023, 9:03 a.m. UTC | #1
On Tue, Feb 07, 2023 at 07:45:20PM +0100, Robin Jarry wrote:
> If a telemetry endpoint callback returns 0 without modifying the data
> object, output_json() may be called with undefined contents in data.
> This can cause crashes and/or worse (double free, etc.).
> 
> Reset data before passing it to the endpoint callbacks.
> 
> Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> ---
>  lib/telemetry/telemetry.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
This is also fixed by patch http://patches.dpdk.org/project/dpdk/patch/20230120033456.29710-3-fengchengwen@huawei.com/

While both work the same way, I think I prefer the fix to set "= {0}" on
init rather than explicit memset.

/Bruce
  
Robin Jarry Feb. 8, 2023, 12:32 p.m. UTC | #2
Bruce Richardson, Feb 08, 2023 at 10:03:
> This is also fixed by patch http://patches.dpdk.org/project/dpdk/patch/20230120033456.29710-3-fengchengwen@huawei.com/
>
> While both work the same way, I think I prefer the fix to set "= {0}" on
> init rather than explicit memset.

Oh I had missed that one. Any of these two patches should be applied and
backported. Feel free to take the first one that was sent :)

As I said in the commit message, it can cause the whole application to
crash. It may also expose data from other telemetry endpoint handlers to
other handlers, I don't think this can be considered as a security issue
but I may be wrong.
  

Patch

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 655191bcf17f..6303429bb0c9 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -335,6 +335,8 @@  perform_command(telemetry_cb fn, const char *cmd, const char *param, int s)
 {
 	struct rte_tel_data data;
 
+	memset(&data, 0, sizeof(data));
+
 	int ret = fn(cmd, param, &data);
 	if (ret < 0) {
 		char out_buf[MAX_CMD_LEN + 10];