Drivers: vmbus: Check for channel allocation before looking up relids
Subsystems (2)
PATCH v3 1/1 Drivers: vmbus: Check for channel allocation before looking up relids
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.
---
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(+)
drivers/hv/connection.c +4 -0
@@ -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]);
Signature · 1 line
2.38.1
drivers/hv/connection.c void vmbus_disconnect(void) · line 414
Quoted 12 lines
From: Mohammed Gamal <[email protected]>
Sent: Friday, February 17, 2023 12:44 PM
...drivers/hv/connection.c +2
-0@@ -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);
Looks good to me except that the line exceeds 80 characters. Please run "scripts/checkpatch.pl" to detect that. For this patch, I guess Wei may be willing to help fix it.
Quoted 6 lines
drivers/hv/connection.c +2
-0+return NULL ; + }if (WARN_ON (relid >=MAX_CHANNEL_RELIDS ))return NULL ;return
READ_ONCE(vmbus_connection.channels[relid]);
--
Wei Liu
maintainerQuoted 7 lines · Dexuan Cui
Quoted 7 lines
From: Mohammed Gamal <[email protected]>
Sent: Friday, February 17, 2023 12:44 PM
...drivers/hv/connection.c +0
-0@@ -409,6 +409,10 @@ void vmbus_disconnect(void)*/
Quoted 8 lines
drivers/hv/connection.c void vmbus_disconnect(void)
Quoted 5 lines
drivers/hv/connection.c +2
-0struct vmbus_channel *relid2channel (u32 relid) { +if (vmbus_connection.channels ==NULL ) { +pr_warn_once ("relid2channel: relid=%d: No channels mapped!\n" , relid);Looks good to me except that the line exceeds 80 characters. Please run "
scripts/checkpatch.pl" to detect that.
FWIW the max line length has been bumped to 100 in checkpatch.pl.
Quoted 10 lines
For this patch, I guess Wei may be willing to help fix it.
Quoted 6 lines
drivers/hv/connection.c +2
-0+return NULL ; + }if (WARN_ON (relid >=MAX_CHANNEL_RELIDS ))return NULL ;return
READ_ONCE(vmbus_connection.channels[relid]);
--Reviewed-by Dexuan Cui <[email protected]>
Wei Liu
maintainerQuoted 17 lines · Dexuan Cui
drivers/hv/connection.c void vmbus_disconnect(void) · line 414
Quoted 12 lines
From: Mohammed Gamal <[email protected]>
Sent: Friday, February 17, 2023 12:44 PM
...drivers/hv/connection.c +2
-0@@ -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);Looks good to me except that the line exceeds 80 characters. Please run "
scripts/checkpatch.pl" to detect that. For this patch, I guess Wei may be willing to help fix it.
Quoted 8 lines
Quoted 6 lines
drivers/hv/connection.c +2
-0+return NULL ; + }if (WARN_ON (relid >=MAX_CHANNEL_RELIDS ))return NULL ;return
READ_ONCE(vmbus_connection.channels[relid]);
--Reviewed-by Dexuan Cui <[email protected]>
I will pick this up via hyperv-fixes.
Wei Liu
maintainerQuoted 27 lines · Wei Liu
Quoted 17 lines · Dexuan Cui
drivers/hv/connection.c void vmbus_disconnect(void) · line 414
Quoted 12 lines
From: Mohammed Gamal <[email protected]>
Sent: Friday, February 17, 2023 12:44 PM
...drivers/hv/connection.c +2
-0@@ -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);Looks good to me except that the line exceeds 80 characters. Please run "
scripts/checkpatch.pl" to detect that. For this patch, I guess Wei may be willing to help fix it.Quoted 8 lines
Quoted 6 lines
drivers/hv/connection.c +2
-0+return NULL ; + }if (WARN_ON (relid >=MAX_CHANNEL_RELIDS ))return NULL ;return
READ_ONCE(vmbus_connection.channels[relid]);
--Reviewed-by Dexuan Cui <[email protected]>
Quoted 1 line
I will pick this up via hyperv-fixes.
Now applied to hyperv-fixes.
Thanks,
Wei.