diff mbox series

[v2,3/6] kvm: s390: Reject KVM_SET_GSI_ROUTING on ucontrol VMs

Message ID 20241216092140.329196-4-schlameuss@linux.ibm.com (mailing list archive)
State New
Headers show
Series selftests: kvm: s390: Reject invalid ioctls on ucontrol VMs | expand

Commit Message

Christoph Schlameuss Dec. 16, 2024, 9:21 a.m. UTC
Prevent null pointer dereference when processing
KVM_IRQ_ROUTING_S390_ADAPTER routing entries.
The ioctl cannot be processed for ucontrol VMs.

Fixes: f65470661f36 ("KVM: s390/interrupt: do not pin adapter interrupt pages")
Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
---
 Documentation/virt/kvm/api.rst | 3 +++
 arch/s390/kvm/interrupt.c      | 2 ++
 2 files changed, 5 insertions(+)

Comments

Hariharan Mari Dec. 18, 2024, 3:08 p.m. UTC | #1
On 2024-12-16 10:21, Christoph Schlameuss wrote:
> Prevent null pointer dereference when processing
> KVM_IRQ_ROUTING_S390_ADAPTER routing entries.
> The ioctl cannot be processed for ucontrol VMs.
> 
> Fixes: f65470661f36 ("KVM: s390/interrupt: do not pin adapter interrupt 
> pages")
> Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

Tested-by: Hariharan Mari <hari55@linux.ibm.com>
> ---
>  Documentation/virt/kvm/api.rst | 3 +++
>  arch/s390/kvm/interrupt.c      | 2 ++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/Documentation/virt/kvm/api.rst 
> b/Documentation/virt/kvm/api.rst
> index 454c2aaa155e..f15b61317aad 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -1914,6 +1914,9 @@ No flags are specified so far, the corresponding
> field must be set to zero.
>    #define KVM_IRQ_ROUTING_HV_SINT 4
>    #define KVM_IRQ_ROUTING_XEN_EVTCHN 5
> 
> +On s390, adding a KVM_IRQ_ROUTING_S390_ADAPTER is rejected on ucontrol 
> VMs with
> +error -EINVAL.
> +
>  flags:
> 
>  - KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing 
> entry
> diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
> index 22d73c13e555..d4f031e086fc 100644
> --- a/arch/s390/kvm/interrupt.c
> +++ b/arch/s390/kvm/interrupt.c
> @@ -2898,6 +2898,8 @@ int kvm_set_routing_entry(struct kvm *kvm,
>  	switch (ue->type) {
>  	/* we store the userspace addresses instead of the guest addresses */
>  	case KVM_IRQ_ROUTING_S390_ADAPTER:
> +		if (kvm_is_ucontrol(kvm))
> +			return -EINVAL;
>  		e->set = set_adapter_int;
>  		uaddr =  gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr);
>  		if (uaddr == -EFAULT)
Hariharan Mari Dec. 19, 2024, 3:53 p.m. UTC | #2
On 2024-12-16 10:21, Christoph Schlameuss wrote:
> Prevent null pointer dereference when processing
> KVM_IRQ_ROUTING_S390_ADAPTER routing entries.
> The ioctl cannot be processed for ucontrol VMs.
> 
> Fixes: f65470661f36 ("KVM: s390/interrupt: do not pin adapter interrupt 
> pages")
> Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

Reviewed-by: Hariharan Mari <hari55@linux.ibm.com>
> ---
>  Documentation/virt/kvm/api.rst | 3 +++
>  arch/s390/kvm/interrupt.c      | 2 ++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/Documentation/virt/kvm/api.rst 
> b/Documentation/virt/kvm/api.rst
> index 454c2aaa155e..f15b61317aad 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -1914,6 +1914,9 @@ No flags are specified so far, the corresponding
> field must be set to zero.
>    #define KVM_IRQ_ROUTING_HV_SINT 4
>    #define KVM_IRQ_ROUTING_XEN_EVTCHN 5
> 
> +On s390, adding a KVM_IRQ_ROUTING_S390_ADAPTER is rejected on ucontrol 
> VMs with
> +error -EINVAL.
> +
>  flags:
> 
>  - KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing 
> entry
> diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
> index 22d73c13e555..d4f031e086fc 100644
> --- a/arch/s390/kvm/interrupt.c
> +++ b/arch/s390/kvm/interrupt.c
> @@ -2898,6 +2898,8 @@ int kvm_set_routing_entry(struct kvm *kvm,
>  	switch (ue->type) {
>  	/* we store the userspace addresses instead of the guest addresses */
>  	case KVM_IRQ_ROUTING_S390_ADAPTER:
> +		if (kvm_is_ucontrol(kvm))
> +			return -EINVAL;
>  		e->set = set_adapter_int;
>  		uaddr =  gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr);
>  		if (uaddr == -EFAULT)
diff mbox series

Patch

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 454c2aaa155e..f15b61317aad 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -1914,6 +1914,9 @@  No flags are specified so far, the corresponding field must be set to zero.
   #define KVM_IRQ_ROUTING_HV_SINT 4
   #define KVM_IRQ_ROUTING_XEN_EVTCHN 5
 
+On s390, adding a KVM_IRQ_ROUTING_S390_ADAPTER is rejected on ucontrol VMs with
+error -EINVAL.
+
 flags:
 
 - KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 22d73c13e555..d4f031e086fc 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -2898,6 +2898,8 @@  int kvm_set_routing_entry(struct kvm *kvm,
 	switch (ue->type) {
 	/* we store the userspace addresses instead of the guest addresses */
 	case KVM_IRQ_ROUTING_S390_ADAPTER:
+		if (kvm_is_ucontrol(kvm))
+			return -EINVAL;
 		e->set = set_adapter_int;
 		uaddr =  gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr);
 		if (uaddr == -EFAULT)