* [PATCH 1/1] selftests: vsock: avoid mktemp -u for Unix socket paths
@ 2026-04-05 19:57 CaoRuichuang
2026-04-09 17:00 ` Simon Horman
2026-04-10 3:52 ` [PATCH v2] selftests: vsock: avoid races creating " Cao Ruichuang
0 siblings, 2 replies; 5+ messages in thread
From: CaoRuichuang @ 2026-04-05 19:57 UTC (permalink / raw)
To: Stefano Garzarella, Shuah Khan
Cc: virtualization, netdev, linux-kselftest, linux-kernel,
CaoRuichuang
The namespace tests create temporary Unix socket paths with mktemp -u and
then hand them to socat. That only prints an unused pathname and leaves
a race before the socket is created.
Create a private temporary directory with mktemp -d and place the Unix
socket inside it instead. This keeps the path unique without relying on
mktemp -u for filesystem socket names.
Signed-off-by: CaoRuichuang <create0818@163.com>
---
tools/testing/selftests/vsock/vmtest.sh | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh
index 86e338886..91e0037d2 100755
--- a/tools/testing/selftests/vsock/vmtest.sh
+++ b/tools/testing/selftests/vsock/vmtest.sh
@@ -718,6 +718,7 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
local pids pid pidfile
local ns0 ns1 port
declare -a pids
+ local unixdir
local unixfile
ns0="global0"
ns1="global1"
@@ -736,7 +737,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
oops_before=$(vm_dmesg_oops_count "${ns0}")
warn_before=$(vm_dmesg_warn_count "${ns0}")
- unixfile=$(mktemp -u /tmp/XXXX.sock)
+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
+ unixfile="${unixdir}/sock"
ip netns exec "${ns1}" \
socat TCP-LISTEN:"${TEST_HOST_PORT}",fork \
UNIX-CONNECT:"${unixfile}" &
@@ -758,6 +760,7 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
terminate_pids "${pids[@]}"
terminate_pidfiles "${pidfile}"
+ rm -rf "${unixdir}"
if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
return "${KSFT_FAIL}"
@@ -814,6 +817,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
local ns0="global0"
local ns1="global1"
local port=12345
+ local unixdir
local unixfile
local dmesg_rc
local pidfile
@@ -826,7 +830,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
log_host "Setup socat bridge from ns ${ns0} to ns ${ns1} over port ${port}"
- unixfile=$(mktemp -u /tmp/XXXX.sock)
+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
+ unixfile="${unixdir}/sock"
ip netns exec "${ns0}" \
socat TCP-LISTEN:"${port}" UNIX-CONNECT:"${unixfile}" &
@@ -845,7 +850,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
if ! vm_start "${pidfile}" "${ns0}"; then
log_host "failed to start vm (cid=${cid}, ns=${ns0})"
terminate_pids "${pids[@]}"
- rm -f "${unixfile}"
+ rm -rf "${unixdir}"
return "${KSFT_FAIL}"
fi
@@ -862,7 +867,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
terminate_pidfiles "${pidfile}"
terminate_pids "${pids[@]}"
- rm -f "${unixfile}"
+ rm -rf "${unixdir}"
if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
return "${KSFT_FAIL}"
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/1] selftests: vsock: avoid mktemp -u for Unix socket paths
2026-04-05 19:57 [PATCH 1/1] selftests: vsock: avoid mktemp -u for Unix socket paths CaoRuichuang
@ 2026-04-09 17:00 ` Simon Horman
2026-04-10 3:52 ` [PATCH v2] selftests: vsock: avoid races creating " Cao Ruichuang
1 sibling, 0 replies; 5+ messages in thread
From: Simon Horman @ 2026-04-09 17:00 UTC (permalink / raw)
To: CaoRuichuang
Cc: Stefano Garzarella, Shuah Khan, virtualization, netdev,
linux-kselftest, linux-kernel
On Mon, Apr 06, 2026 at 03:57:33AM +0800, CaoRuichuang wrote:
> The namespace tests create temporary Unix socket paths with mktemp -u and
> then hand them to socat. That only prints an unused pathname and leaves
> a race before the socket is created.
>
> Create a private temporary directory with mktemp -d and place the Unix
> socket inside it instead. This keeps the path unique without relying on
> mktemp -u for filesystem socket names.
>
> Signed-off-by: CaoRuichuang <create0818@163.com>
I think the subject could be improved a bit.
More along the lines of the problem being solved,
less on how it is achieved.
...
> @@ -845,7 +850,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> if ! vm_start "${pidfile}" "${ns0}"; then
> log_host "failed to start vm (cid=${cid}, ns=${ns0})"
> terminate_pids "${pids[@]}"
> - rm -f "${unixfile}"
> + rm -rf "${unixdir}"
rm -rf makes me feel queasy.
Can rmdir, and rm, ideally without the -f, be used instead?
rm "$unixfile"
rmdir "$unixdir"
> return "${KSFT_FAIL}"
> fi
>
...
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2] selftests: vsock: avoid races creating Unix socket paths
2026-04-05 19:57 [PATCH 1/1] selftests: vsock: avoid mktemp -u for Unix socket paths CaoRuichuang
2026-04-09 17:00 ` Simon Horman
@ 2026-04-10 3:52 ` Cao Ruichuang
2026-04-10 8:33 ` Stefano Garzarella
1 sibling, 1 reply; 5+ messages in thread
From: Cao Ruichuang @ 2026-04-10 3:52 UTC (permalink / raw)
To: stefano.garzarella
Cc: sgarzare, shuah, virtualization, netdev, linux-kselftest,
linux-kernel, horms, Cao Ruichuang
Signed-off-by: Cao Ruichuang <create0818@163.com>
---
v2:
- retitle the patch to describe the race being fixed
- replace rm -rf with explicit rm and rmdir cleanup
tools/testing/selftests/vsock/vmtest.sh | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh
index 86e338886b3..c345fa539d3 100755
--- a/tools/testing/selftests/vsock/vmtest.sh
+++ b/tools/testing/selftests/vsock/vmtest.sh
@@ -718,6 +718,7 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
local pids pid pidfile
local ns0 ns1 port
declare -a pids
+ local unixdir
local unixfile
ns0="global0"
ns1="global1"
@@ -736,7 +737,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
oops_before=$(vm_dmesg_oops_count "${ns0}")
warn_before=$(vm_dmesg_warn_count "${ns0}")
- unixfile=$(mktemp -u /tmp/XXXX.sock)
+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
+ unixfile="${unixdir}/sock"
ip netns exec "${ns1}" \
socat TCP-LISTEN:"${TEST_HOST_PORT}",fork \
UNIX-CONNECT:"${unixfile}" &
@@ -758,6 +760,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
terminate_pids "${pids[@]}"
terminate_pidfiles "${pidfile}"
+ rm "${unixfile}"
+ rmdir "${unixdir}"
if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
return "${KSFT_FAIL}"
@@ -814,6 +818,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
local ns0="global0"
local ns1="global1"
local port=12345
+ local unixdir
local unixfile
local dmesg_rc
local pidfile
@@ -826,7 +831,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
log_host "Setup socat bridge from ns ${ns0} to ns ${ns1} over port ${port}"
- unixfile=$(mktemp -u /tmp/XXXX.sock)
+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
+ unixfile="${unixdir}/sock"
ip netns exec "${ns0}" \
socat TCP-LISTEN:"${port}" UNIX-CONNECT:"${unixfile}" &
@@ -845,7 +851,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
if ! vm_start "${pidfile}" "${ns0}"; then
log_host "failed to start vm (cid=${cid}, ns=${ns0})"
terminate_pids "${pids[@]}"
- rm -f "${unixfile}"
+ rm "${unixfile}"
+ rmdir "${unixdir}"
return "${KSFT_FAIL}"
fi
@@ -862,7 +869,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
terminate_pidfiles "${pidfile}"
terminate_pids "${pids[@]}"
- rm -f "${unixfile}"
+ rm "${unixfile}"
+ rmdir "${unixdir}"
if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
return "${KSFT_FAIL}"
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] selftests: vsock: avoid races creating Unix socket paths
2026-04-10 3:52 ` [PATCH v2] selftests: vsock: avoid races creating " Cao Ruichuang
@ 2026-04-10 8:33 ` Stefano Garzarella
2026-04-10 9:06 ` Stefano Garzarella
0 siblings, 1 reply; 5+ messages in thread
From: Stefano Garzarella @ 2026-04-10 8:33 UTC (permalink / raw)
To: Cao Ruichuang
Cc: stefano.garzarella, shuah, virtualization, netdev,
linux-kselftest, linux-kernel, horms
On Fri, Apr 10, 2026 at 11:52:37AM +0800, Cao Ruichuang wrote:
No patch description at all?
>Signed-off-by: Cao Ruichuang <create0818@163.com>
>---
>v2:
>- retitle the patch to describe the race being fixed
>- replace rm -rf with explicit rm and rmdir cleanup
>
> tools/testing/selftests/vsock/vmtest.sh | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
>diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh
>index 86e338886b3..c345fa539d3 100755
>--- a/tools/testing/selftests/vsock/vmtest.sh
>+++ b/tools/testing/selftests/vsock/vmtest.sh
>@@ -718,6 +718,7 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
> local pids pid pidfile
> local ns0 ns1 port
> declare -a pids
>+ local unixdir
> local unixfile
> ns0="global0"
> ns1="global1"
>@@ -736,7 +737,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
> oops_before=$(vm_dmesg_oops_count "${ns0}")
> warn_before=$(vm_dmesg_warn_count "${ns0}")
>
>- unixfile=$(mktemp -u /tmp/XXXX.sock)
>+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
>+ unixfile="${unixdir}/sock"
> ip netns exec "${ns1}" \
> socat TCP-LISTEN:"${TEST_HOST_PORT}",fork \
> UNIX-CONNECT:"${unixfile}" &
>@@ -758,6 +760,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
>
> terminate_pids "${pids[@]}"
> terminate_pidfiles "${pidfile}"
>+ rm "${unixfile}"
>+ rmdir "${unixdir}"
>
> if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
> return "${KSFT_FAIL}"
>@@ -814,6 +818,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> local ns0="global0"
> local ns1="global1"
> local port=12345
>+ local unixdir
> local unixfile
> local dmesg_rc
> local pidfile
>@@ -826,7 +831,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
>
> log_host "Setup socat bridge from ns ${ns0} to ns ${ns1} over port ${port}"
>
>- unixfile=$(mktemp -u /tmp/XXXX.sock)
>+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
>+ unixfile="${unixdir}/sock"
>
> ip netns exec "${ns0}" \
> socat TCP-LISTEN:"${port}" UNIX-CONNECT:"${unixfile}" &
>@@ -845,7 +851,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> if ! vm_start "${pidfile}" "${ns0}"; then
> log_host "failed to start vm (cid=${cid}, ns=${ns0})"
> terminate_pids "${pids[@]}"
>- rm -f "${unixfile}"
>+ rm "${unixfile}"
>+ rmdir "${unixdir}"
> return "${KSFT_FAIL}"
> fi
>
>@@ -862,7 +869,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
>
> terminate_pidfiles "${pidfile}"
> terminate_pids "${pids[@]}"
>- rm -f "${unixfile}"
>+ rm "${unixfile}"
>+ rmdir "${unixdir}"
>
> if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
> return "${KSFT_FAIL}"
>--
>2.39.5 (Apple Git-154)
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] selftests: vsock: avoid races creating Unix socket paths
2026-04-10 8:33 ` Stefano Garzarella
@ 2026-04-10 9:06 ` Stefano Garzarella
0 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2026-04-10 9:06 UTC (permalink / raw)
To: Cao Ruichuang, Bobby Eshleman
Cc: stefano.garzarella, shuah, virtualization, netdev,
linux-kselftest, linux-kernel, horms
On Fri, 10 Apr 2026 at 10:33, Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> On Fri, Apr 10, 2026 at 11:52:37AM +0800, Cao Ruichuang wrote:
>
> No patch description at all?
Also, maybe better to CC Bobby.
Stefano
>
> >Signed-off-by: Cao Ruichuang <create0818@163.com>
> >---
> >v2:
> >- retitle the patch to describe the race being fixed
> >- replace rm -rf with explicit rm and rmdir cleanup
> >
> > tools/testing/selftests/vsock/vmtest.sh | 16 ++++++++++++----
> > 1 file changed, 12 insertions(+), 4 deletions(-)
> >
> >diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh
> >index 86e338886b3..c345fa539d3 100755
> >--- a/tools/testing/selftests/vsock/vmtest.sh
> >+++ b/tools/testing/selftests/vsock/vmtest.sh
> >@@ -718,6 +718,7 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
> > local pids pid pidfile
> > local ns0 ns1 port
> > declare -a pids
> >+ local unixdir
> > local unixfile
> > ns0="global0"
> > ns1="global1"
> >@@ -736,7 +737,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
> > oops_before=$(vm_dmesg_oops_count "${ns0}")
> > warn_before=$(vm_dmesg_warn_count "${ns0}")
> >
> >- unixfile=$(mktemp -u /tmp/XXXX.sock)
> >+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
> >+ unixfile="${unixdir}/sock"
> > ip netns exec "${ns1}" \
> > socat TCP-LISTEN:"${TEST_HOST_PORT}",fork \
> > UNIX-CONNECT:"${unixfile}" &
> >@@ -758,6 +760,8 @@ test_ns_diff_global_host_connect_to_global_vm_ok() {
> >
> > terminate_pids "${pids[@]}"
> > terminate_pidfiles "${pidfile}"
> >+ rm "${unixfile}"
> >+ rmdir "${unixdir}"
> >
> > if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
> > return "${KSFT_FAIL}"
> >@@ -814,6 +818,7 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> > local ns0="global0"
> > local ns1="global1"
> > local port=12345
> >+ local unixdir
> > local unixfile
> > local dmesg_rc
> > local pidfile
> >@@ -826,7 +831,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> >
> > log_host "Setup socat bridge from ns ${ns0} to ns ${ns1} over port ${port}"
> >
> >- unixfile=$(mktemp -u /tmp/XXXX.sock)
> >+ unixdir=$(mktemp -d /tmp/vsock_vmtest_XXXXXX)
> >+ unixfile="${unixdir}/sock"
> >
> > ip netns exec "${ns0}" \
> > socat TCP-LISTEN:"${port}" UNIX-CONNECT:"${unixfile}" &
> >@@ -845,7 +851,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> > if ! vm_start "${pidfile}" "${ns0}"; then
> > log_host "failed to start vm (cid=${cid}, ns=${ns0})"
> > terminate_pids "${pids[@]}"
> >- rm -f "${unixfile}"
> >+ rm "${unixfile}"
> >+ rmdir "${unixdir}"
> > return "${KSFT_FAIL}"
> > fi
> >
> >@@ -862,7 +869,8 @@ test_ns_diff_global_vm_connect_to_global_host_ok() {
> >
> > terminate_pidfiles "${pidfile}"
> > terminate_pids "${pids[@]}"
> >- rm -f "${unixfile}"
> >+ rm "${unixfile}"
> >+ rmdir "${unixdir}"
> >
> > if [[ "${rc}" -ne 0 ]] || [[ "${dmesg_rc}" -ne 0 ]]; then
> > return "${KSFT_FAIL}"
> >--
> >2.39.5 (Apple Git-154)
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-10 9:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-05 19:57 [PATCH 1/1] selftests: vsock: avoid mktemp -u for Unix socket paths CaoRuichuang
2026-04-09 17:00 ` Simon Horman
2026-04-10 3:52 ` [PATCH v2] selftests: vsock: avoid races creating " Cao Ruichuang
2026-04-10 8:33 ` Stefano Garzarella
2026-04-10 9:06 ` Stefano Garzarella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox