Linux-HyperV List
 help / color / mirror / Atom feed
From: vdso@mailbox.org
To: mhklinux@outlook.com, mhkelley58@gmail.com
Cc: "haiyangz@microsoft.com" <haiyangz@microsoft.com>,
	"wei.liu@kernel.org" <wei.liu@kernel.org>,
	"decui@microsoft.com" <decui@microsoft.com>,
	"kys@microsoft.com" <kys@microsoft.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
	"dan.carpenter@linaro.org" <dan.carpenter@linaro.org>
Subject: Re: [PATCH 1/1] Drivers: hv: Fix uninit'ed variable in hv_msg_dump() if CONFIG_PRINTK not set
Date: Sun, 28 Dec 2025 20:11:56 -0800 (PST)	[thread overview]
Message-ID: <21281086.36492.1766981516854@app.mailbox.org> (raw)
In-Reply-To: <20251219160832.1628-1-mhklinux@outlook.com>


> On 12/19/2025 8:08 AM  mhkelley58@gmail.com wrote:
> 
>  
> From: Michael Kelley <mhklinux@outlook.com>
> 
> When CONFIG_PRINTK is not set, kmsg_dump_get_buffer() returns 'false'
> without setting the bytes_written argument. In such case, bytes_written
> is uninitialized when it is tested for zero.
> 
> This is admittedly an unlikely scenario, but in the interest of correctness
> and avoiding tool noise about uninitialized variables, fix this by testing
> the return value before testing bytes_written.
> 
> Fixes: 9c318a1d9b50 ("Drivers: hv: move panic report code from vmbus to hv early init code")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/all/202512172102.OcUspn1Z-lkp@intel.com/
> Signed-off-by: Michael Kelley <mhklinux@outlook.com>
> ---
>  drivers/hv/hv_common.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index f466a6099eff..de9e069c5a0c 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -188,6 +188,7 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
>  {
>  	struct kmsg_dump_iter iter;
>  	size_t bytes_written;
> +	bool ret;
>  
>  	/* We are only interested in panics. */
>  	if (detail->reason != KMSG_DUMP_PANIC || !sysctl_record_panic_msg)
> @@ -198,9 +199,9 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
>  	 * be single-threaded.
>  	 */
>  	kmsg_dump_rewind(&iter);
> -	kmsg_dump_get_buffer(&iter, false, hv_panic_page, HV_HYP_PAGE_SIZE,
> -			     &bytes_written);
> -	if (!bytes_written)
> +	ret = kmsg_dump_get_buffer(&iter, false, hv_panic_page, HV_HYP_PAGE_SIZE,
> +				   &bytes_written);
> +	if (!ret || !bytes_written)
>  		return;
>  	/*
>  	 * P3 to contain the physical address of the panic page & P4 to

The existing code

1. doesn't care about the return value from kmsg_dump_get_buffer.
   The return value wouldn't make the function return before, why does that
   need to change? 

2. returns early when there are no bytes written.
   I think it shouldn't as otherwise the crash control register isn't written to,
   and the panic isn't signalled to the host. Is there another path maybe that
   I'm not noticing?

That said, would it make sense to you the patch be something similar to:

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 0a3ab7efed46..20e4a9a13b32 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -188,6 +188,7 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
 {
        struct kmsg_dump_iter iter;
        size_t bytes_written;
+       bool ret;
 
        /* We are only interested in panics. */
        if (detail->reason != KMSG_DUMP_PANIC || !sysctl_record_panic_msg)
@@ -197,11 +198,16 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
         * Write dump contents to the page. No need to synchronize; panic should
         * be single-threaded.
         */
+       bytes_written = 0;
        kmsg_dump_rewind(&iter);
-       kmsg_dump_get_buffer(&iter, false, hv_panic_page, HV_HYP_PAGE_SIZE,
+       ret = kmsg_dump_get_buffer(&iter, false, hv_panic_page, HV_HYP_PAGE_SIZE,
                             &bytes_written);
-       if (!bytes_written)
-               return;
+       /*
+        * Whether there is more data available or not, send what has been captured
+        * to the host. Ignore the return value.
+        */
+       (void) ret;
+
        /*
         * P3 to contain the physical address of the panic page & P4 to
         * contain the size of the panic data in that page. Rest of the
@@ -210,7 +216,7 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
        hv_set_msr(HV_MSR_CRASH_P0, 0);
        hv_set_msr(HV_MSR_CRASH_P1, 0);
        hv_set_msr(HV_MSR_CRASH_P2, 0);
-       hv_set_msr(HV_MSR_CRASH_P3, virt_to_phys(hv_panic_page));
+       hv_set_msr(HV_MSR_CRASH_P3, bytes_written ? virt_to_phys(hv_panic_page) : NULL);
        hv_set_msr(HV_MSR_CRASH_P4, bytes_written);
 
        /*

--
Cheers,
Roman

> -- 
> 2.25.1

  reply	other threads:[~2025-12-29  4:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19 16:08 [PATCH 1/1] Drivers: hv: Fix uninit'ed variable in hv_msg_dump() if CONFIG_PRINTK not set mhkelley58
2025-12-29  4:11 ` vdso [this message]
2025-12-30  3:04   ` Michael Kelley
2025-12-31 17:52     ` Michael Kelley

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=21281086.36492.1766981516854@app.mailbox.org \
    --to=vdso@mailbox.org \
    --cc=dan.carpenter@linaro.org \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhkelley58@gmail.com \
    --cc=mhklinux@outlook.com \
    --cc=wei.liu@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