From: Andrew Jones <ajones@ventanamicro.com>
To: "Björn Töpel" <bjorn@kernel.org>
Cc: "Will Deacon" <will@kernel.org>,
"Julien Thierry" <julien.thierry.kdev@gmail.com>,
"Anup Patel" <anup@brainfault.org>,
kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
"Björn Töpel" <bjorn@rivosinc.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH kvmtool] riscv: Pass correct size to snprintf()
Date: Tue, 5 Nov 2024 10:14:48 +0100 [thread overview]
Message-ID: <20241105-546ce4236046e9742cf081e7@orel> (raw)
In-Reply-To: <20241104192120.75841-1-bjorn@kernel.org>
On Mon, Nov 04, 2024 at 08:21:19PM +0100, Björn Töpel wrote:
> From: Björn Töpel <bjorn@rivosinc.com>
>
> The snprintf() function does not get the correct size argument passed,
> when the FDT ISA string is built. Instead of adjusting the size for
> each extension, the full size is passed for every iteration. Doing so
> will make __snprinf_chk() bail out on glibc.
>
> Adjust size for each iteration.
>
> Fixes: 8aff29e1dafe ("riscv: Append ISA extensions to the device tree")
> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
> ---
> riscv/fdt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/riscv/fdt.c b/riscv/fdt.c
> index 8189601f46de..85c8f95604f6 100644
> --- a/riscv/fdt.c
> +++ b/riscv/fdt.c
> @@ -157,7 +157,7 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
> isa_info_arr[i].name);
> break;
> }
> - pos += snprintf(cpu_isa + pos, CPU_ISA_MAX_LEN, "_%s",
> + pos += snprintf(cpu_isa + pos, CPU_ISA_MAX_LEN - pos, "_%s",
Just above this we confirm strlen(isa_info_arr[i].name) + pos + 1 is less
than CPU_ISA_MAX_LEN, which means we should be able to use anything for
size which is greater than or equal to strlen(isa_info_arr[i].name) + 1,
as snprintf won't write more anyway. But, it's understandable that
__snprinf_chk doesn't know that.
> isa_info_arr[i].name);
> }
> cpu_isa[pos] = '\0';
Not part of this patch, but part of the context, so I'll comment on it
anyway, this '\0' assignment could be removed. It looks like it's a left
over from commit 7c9aac003925 ("riscv: Generate FDT at runtime for
Guest/VM") which could have been removed with commit 8aff29e1dafe ("riscv:
Append ISA extensions to the device tree")
Anyway,
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Thanks,
drew
next prev parent reply other threads:[~2024-11-05 9:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-04 19:21 [PATCH kvmtool] riscv: Pass correct size to snprintf() Björn Töpel
2024-11-05 9:14 ` Andrew Jones [this message]
2024-11-11 17:10 ` Will Deacon
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=20241105-546ce4236046e9742cf081e7@orel \
--to=ajones@ventanamicro.com \
--cc=anup@brainfault.org \
--cc=bjorn@kernel.org \
--cc=bjorn@rivosinc.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=will@kernel.org \
/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