From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Elena Agostini <eagostini@nvidia.com>
Subject: [PATCH v2 1/2] test-gpudev: avoid use-after-free and free-non-heap warnings
Date: Mon, 28 Oct 2024 12:01:02 -0700 [thread overview]
Message-ID: <20241028190301.264378-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20241028190301.264378-1-stephen@networkplumber.org>
Remove the test intentionally frees a bad pointer in GPU memory,
and GCC sees that at compile time now.
Fix use after free in printf.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test-gpudev/main.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c
index f065e6cd81..30fe573bf9 100644
--- a/app/test-gpudev/main.c
+++ b/app/test-gpudev/main.c
@@ -96,29 +96,19 @@ alloc_gpu_memory(uint16_t gpu_id)
goto error;
}
- ret = rte_gpu_mem_free(gpu_id, (uint8_t *)(ptr_1)+0x700);
- if (ret < 0) {
- printf("GPU memory 0x%p NOT freed: GPU driver didn't find this memory address internally.\n",
- (uint8_t *)(ptr_1)+0x700);
- } else {
- fprintf(stderr, "ERROR: rte_gpu_mem_free freed GPU memory 0x%p\n",
- (uint8_t *)(ptr_1)+0x700);
- goto error;
- }
-
+ printf("GPU memory 0x%p free\n", ptr_2);
ret = rte_gpu_mem_free(gpu_id, ptr_2);
if (ret < 0) {
fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret);
goto error;
}
- printf("GPU memory 0x%p freed\n", ptr_2);
+ printf("GPU memory 0x%p free\n", ptr_1);
ret = rte_gpu_mem_free(gpu_id, ptr_1);
if (ret < 0) {
fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret);
goto error;
}
- printf("GPU memory 0x%p freed\n", ptr_1);
printf("\n=======> TEST: PASSED\n");
return 0;
@@ -228,12 +218,12 @@ gpu_mem_cpu_map(uint16_t gpu_id)
}
printf("GPU memory CPU unmapped, 0x%p not valid anymore\n", ptr_cpu);
+ printf("GPU memory 0x%p freeing\n", ptr_gpu);
ret = rte_gpu_mem_free(gpu_id, ptr_gpu);
if (ret < 0) {
fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret);
goto error;
}
- printf("GPU memory 0x%p freed\n", ptr_gpu);
printf("\n=======> TEST: PASSED\n");
return 0;
--
2.45.2
next prev parent reply other threads:[~2024-10-28 19:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 22:58 [PATCH 0/2] gpudev: annotate memory allocation Stephen Hemminger
2024-10-17 22:58 ` [PATCH 1/2] test-gpudev: avoid use-after-free and free-non-heap warnings Stephen Hemminger
2024-10-17 22:58 ` [PATCH 2/2] gpudev: add malloc annotations to rte_gpu_mem_alloc Stephen Hemminger
2024-10-28 19:01 ` [PATCH v2 0/2] gpudev: annotate memory allocation functions Stephen Hemminger
2024-10-28 19:01 ` Stephen Hemminger [this message]
2024-10-28 19:01 ` [PATCH v2 2/2] gpudev: add malloc annotations to rte_gpu_mem_alloc Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241028190301.264378-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=eagostini@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).