linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mohammed Gamal <mgamal@redhat.com>
To: decui@microsoft.com, linux-hyperv@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, mikelley@microsoft.com,
	parri.andrea@gmail.com, haiyangz@microsoft.com,
	wei.liu@kernel.org, vkuznets@redhat.com, xxiong@redhat.com,
	Mohammed Gamal <mgamal@redhat.com>
Subject: [PATCH v3] Drivers: vmbus: Check for channel allocation before looking up relids
Date: Fri, 17 Feb 2023 22:44:11 +0200	[thread overview]
Message-ID: <20230217204411.212709-1-mgamal@redhat.com> (raw)

relid2channel() assumes vmbus channel array to be allocated when called.
However, in cases such as kdump/kexec, not all relids will be reset by the host.
When the second kernel boots and if the guest receives a vmbus interrupt during
vmbus driver initialization before vmbus_connect() is called, before it finishes,
or if it fails, the vmbus interrupt service routine is called which in turn calls
relid2channel() and can cause a null pointer dereference.

Print a warning and error out in relid2channel() for a channel id that's invalid
in the second kernel.

Fixes: 8b6a877c060e ("Drivers: hv: vmbus: Replace the per-CPU channel lists with a global array of channels")

Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
---
Changes from v2:
	* Changed commit message
	* Use pr_warn_once() instead of WARN() with a shorter message
	  for less overall noise
---
 drivers/hv/connection.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 9dc27e5d367a..da51b50787df 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -409,6 +409,10 @@ void vmbus_disconnect(void)
  */
 struct vmbus_channel *relid2channel(u32 relid)
 {
+	if (vmbus_connection.channels == NULL) {
+		pr_warn_once("relid2channel: relid=%d: No channels mapped!\n", relid);
+		return NULL;
+	}
 	if (WARN_ON(relid >= MAX_CHANNEL_RELIDS))
 		return NULL;
 	return READ_ONCE(vmbus_connection.channels[relid]);
-- 
2.38.1


             reply	other threads:[~2023-02-17 20:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 20:44 Mohammed Gamal [this message]
2023-02-17 23:17 ` [PATCH v3] Drivers: vmbus: Check for channel allocation before looking up relids Dexuan Cui
2023-02-20 11:39   ` Wei Liu
2023-02-20 14:23   ` Wei Liu
2023-03-06 15:28     ` Wei Liu

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=20230217204411.212709-1-mgamal@redhat.com \
    --to=mgamal@redhat.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=parri.andrea@gmail.com \
    --cc=vkuznets@redhat.com \
    --cc=wei.liu@kernel.org \
    --cc=xxiong@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).