All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: selftests: Make guest_snprintf() a macro and use it as appropriate
Date: Wed, 30 Sep 2026 00:22:37 +0000	[thread overview]
Message-ID: <20260930002238.649421F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930001341.3171558-1-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests/kvm: guest_snprintf() macro variables shadow caller arguments
- [Medium] selftests/kvm: guest_snprintf() implicitly captures caller variadic args
--

commit fab1360854d5b8141536eb1f70a7ed77983d6dcd
Author: Sean Christopherson <seanjc@google.com>

KVM: selftests: Make guest_snprintf() a macro and use it as appropriate

This commit turns guest_snprintf() into a macro to allow its use by variadic
functions. It updates the ucall APIs to use this macro instead of open coding
the variable argument handling.

Closes: https://lore.kernel.org/all/20260918113631.634233-4-gokul02k@gmail.com

> diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> index a6a3e16578959..817d4d5ca7cc7 100644
> --- a/tools/testing/selftests/kvm/include/test_util.h
> +++ b/tools/testing/selftests/kvm/include/test_util.h
> @@ -238,7 +238,17 @@ static inline u32 atoi_non_negative(const char *name, const char *num_str)
>  }
>  
>  int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args);
> -__printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...);
> +
> +#define guest_snprintf(__buf, __n, __fmt)		\
> +({							\
> +	va_list va;					\
> +	int len;					\

[Severity: Medium]
Does this macro shadow caller arguments? If a caller passes an argument
named len to guest_snprintf(), it will be shadowed by the uninitialized
local len due to C scoping rules for statement expressions. The inner len
is then passed to guest_vsnprintf(), which could result in a random or
uninitialized buffer size.

> +							\
> +	va_start(va, __fmt);				\

[Severity: Medium]
Does this implicitly capture the caller's variadic arguments? 

The macro internally invokes va_start(va, __fmt), which couples it to the
caller's stack frame. If this macro is used in a non-variadic function,
or if __fmt is not the rightmost named argument of the calling function,
could va_start cause undefined behavior? 

Additionally, this restricts the macro to exactly 3 arguments, preventing
standard snprintf usage like guest_snprintf(buf, size, "%d", 5).

> +	len = guest_vsnprintf(__buf, __n, __fmt, va);	\
> +	va_end(va);					\
> +	len;						\
> +})
>  
>  char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1)));

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260930001341.3171558-1-seanjc@google.com?part=1

  reply	other threads:[~2026-09-30  0:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  0:13 [PATCH] KVM: selftests: Make guest_snprintf() a macro and use it as appropriate Sean Christopherson
2026-09-30  0:22 ` sashiko-bot [this message]
2026-09-30  1:18   ` Sean Christopherson

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=20260930002238.649421F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.