Re: [PATCH] tools/nolibc: mark arg1 operand in __nolibc_syscall0() as write-only

From: Willy Tarreau

Date: Fri Jul 03 2026 - 13:42:35 EST


Hi Thomas!

On Fri, Jul 03, 2026 at 07:30:16PM +0200, Thomas Weißschuh wrote:
> __nolibc_syscall0() does not set the arg1 variable before passing it to
> the asm block. This uninitialized variable read is undefined behavior.
> Clang can miscompile this.

Interesting. I don't know how we ended up like this, most likely just
due to reusing the same code blocks for the different variants. I'm
noting that m68k is affected as well then. I'm CCing Daniel for a
double-check.

> Mark the asm operand as write-only to fix this.
>
> Fixes: 8e1930296f92 ("tools/nolibc: Add support for SPARC")
> Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> ---
> tools/include/nolibc/arch-sparc.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/include/nolibc/arch-sparc.h b/tools/include/nolibc/arch-sparc.h
> index ddae9bc10dfe..23fab40accfa 100644
> --- a/tools/include/nolibc/arch-sparc.h
> +++ b/tools/include/nolibc/arch-sparc.h
> @@ -45,7 +45,7 @@
> \
> __asm__ volatile ( \
> _NOLIBC_SYSCALL \
> - : "+r"(_arg1) \
> + : "=r"(_arg1) \
> : "r"(_num) \
> : "memory", "cc" \
> ); \

Agreed, this totally makes sense.

Acked-by: Willy Tarreau <w@xxxxxx>

Thanks!
Willy