stack: occasional crash due to uninitialized variable

Message ID 1738632218-5796-1-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series stack: occasional crash due to uninitialized variable |

Checks

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

Commit Message

Andre Muezerie Feb. 4, 2025, 1:23 a.m. UTC
Variable "success" was not being initialized and there was a code
path where the last do/while loop in __rte_stack_lf_pop_elems
looked at the value of this variable before it was set to any.

Compiling with msvc resulted in stack_lf_autotest sometimes crashing.

The fix is to initialize the variable. This same fix was applied to
stack\rte_stack_lf_generic.h in the past but was missed here.

Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")
Cc: stable@dpdk.org

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 lib/stack/rte_stack_lf_c11.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

David Marchand Feb. 4, 2025, 12:45 p.m. UTC | #1
On Tue, Feb 4, 2025 at 2:24 AM Andre Muezerie
<andremue@linux.microsoft.com> wrote:
>
> Variable "success" was not being initialized and there was a code
> path where the last do/while loop in __rte_stack_lf_pop_elems
> looked at the value of this variable before it was set to any.
>
> Compiling with msvc resulted in stack_lf_autotest sometimes crashing.
>
> The fix is to initialize the variable. This same fix was applied to
> stack\rte_stack_lf_generic.h in the past but was missed here.
>
> Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")
> Cc: stable@dpdk.org
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>

Indeed, good catch.
Reviewed-by: David Marchand <david.marchand@redhat.com>
  
David Marchand March 6, 2025, 1:19 p.m. UTC | #2
On Tue, Feb 4, 2025 at 2:24 AM Andre Muezerie
<andremue@linux.microsoft.com> wrote:
>
> Variable "success" was not being initialized and there was a code
> path where the last do/while loop in __rte_stack_lf_pop_elems
> looked at the value of this variable before it was set to any.
>
> Compiling with msvc resulted in stack_lf_autotest sometimes crashing.
>
> The fix is to initialize the variable. This same fix was applied to
> stack\rte_stack_lf_generic.h in the past but was missed here.
>
> Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")
> Cc: stable@dpdk.org
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>

Applied, thanks.
  

Patch

diff --git a/lib/stack/rte_stack_lf_c11.h b/lib/stack/rte_stack_lf_c11.h
index 60d46e963b..ee1c79c095 100644
--- a/lib/stack/rte_stack_lf_c11.h
+++ b/lib/stack/rte_stack_lf_c11.h
@@ -77,7 +77,7 @@  __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
 {
 	struct rte_stack_lf_head old_head;
 	uint64_t len;
-	int success;
+	int success = 0;
 
 	/* Reserve num elements, if available */
 	len = rte_atomic_load_explicit(&list->len, rte_memory_order_relaxed);