kvm: Fix warning in__kvm_gpc_refresh
Subsystems (4)
PATCH v2 1/1 kvm: Fix warning in__kvm_gpc_refresh
Check for invalid hva address stored in data and return -EINVAL before calling into __kvm_gpc_activate().
---
Syzbot reports a warning message in __kvm_gpc_refresh(). This warning requires at least one of gpa and uhva to be valid.
WARNING: CPU: 0 PID: 5090 at arch/x86/kvm/../../../virt/kvm/pfncache.c:259 __kvm_gpc_refresh+0xf17/0x1090 arch/x86/kvm/../../../virt/kvm/pfncache.c:259
We are calling it from kvm_gpc_activate_hva(). This function always calls __kvm_gpc_activate() with INVALID_GPA. Thus, uhva must be valid to disable this warning.
This patch checks for invalid hva address and return -EINVAL before calling __kvm_gpc_activate().
syzbot has tested the proposed patch and the reproducer did not trigger any issue.
Tested on:
commit: afcd4813 Merge tag 'mm-hotfixes-stable-2024-06-26-17-2.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=1427e301980000 kernel config: https://syzkaller.appspot.com/x/.config?x=e40800950091403a dashboard link: https://syzkaller.appspot.com/bug?extid=fd555292a1da3180fc82 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=13838f3e980000
Note: testing is done by a robot and is best-effort only.
---
Changes in v2:
- Adapted Sean's suggestion to check for valid address before calling into __kvm_gpc_activate().
- Link to v1: https://lore.kernel.org/r/[email protected]
--- arch/x86/kvm/xen.c | 2 +- virt/kvm/pfncache.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/kvm/xen.c +1 -1
@@ -741,7 +741,7 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) }else {void __user * hva =u64_to_user_ptr (data->u.shared_info.hva); -if (!PAGE_ALIGNED (hva) || !access_ok (hva,PAGE_SIZE )) { +if (!PAGE_ALIGNED (hva)) { r = -EINVAL ; }else if (!hva) {kvm_gpc_deactivate (&kvm->arch.xen.shinfo_cache);
virt/kvm/pfncache.c +3 -0
@@ -430,6 +430,9 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)int kvm_gpc_activate_hva (struct gfn_to_pfn_cache *gpc,unsigned long uhva,unsigned long len) { +if (!access_ok ((void __user *)uhva, len)) +return -EINVAL ; +return __kvm_gpc_activate (gpc,INVALID_GPA , uhva, len); }
---
base-commit: 2bfcfd584ff5ccc8bb7acde19b42570414bf880b
change-id: 20240625-bug5-5d332b5e5161
Best regards,
Signature · 1 line
Pei Li <[email protected]>
Quoted 38 lines · Pei Li
Check for invalid hva address stored in data and return
-EINVALbefore calling into__kvm_gpc_activate().---
Syzbot reports a warning message in__kvm_gpc_refresh(). This warning requires at least one of gpa and uhva to be valid.WARNING: CPU: 0 PID: 5090 at arch/x86/kvm/../../../virt/kvm/pfncache.c:259 __kvm_gpc_refresh+0xf17/0x1090 arch/x86/kvm/../../../virt/kvm/pfncache.c:259We are calling it from
kvm_gpc_activate_hva(). This function always calls__kvm_gpc_activate()withINVALID_GPA. Thus, uhva must be valid to disable this warning.This patch checks for invalid hva address and return
-EINVALbefore calling__kvm_gpc_activate().syzbot has tested the proposed patch and the reproducer did not trigger any issue.
Tested on:
commit: afcd4813 Merge tag 'mm-hotfixes-stable-2024-06-26-17-2.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=1427e301980000 kernel config: https://syzkaller.appspot.com/x/.config?x=e40800950091403a dashboard link: https://syzkaller.appspot.com/bug?extid=fd555292a1da3180fc82 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=13838f3e980000Note: testing is done by a robot and is best-effort only.
---
Changes in v2:
- Adapted Sean's suggestion to check for valid address before calling into__kvm_gpc_activate().
- Link to v1: https://lore.kernel.org/r/[email protected]
Quoted 5 lines
--- arch/x86/kvm/xen.c | 2 +- virt/kvm/pfncache.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
Quoted 45 lines · Paul Durrant
Quoted 41 lines · Pei Li
Check for invalid hva address stored in data and return
-EINVALbefore calling into__kvm_gpc_activate().---
Syzbot reports a warning message in__kvm_gpc_refresh(). This warning requires at least one of gpa and uhva to be valid.WARNING: CPU: 0 PID: 5090 at arch/x86/kvm/../../../virt/kvm/pfncache.c:259 __kvm_gpc_refresh+0xf17/0x1090 arch/x86/kvm/../../../virt/kvm/pfncache.c:259We are calling it from
kvm_gpc_activate_hva(). This function always calls__kvm_gpc_activate()withINVALID_GPA. Thus, uhva must be valid to disable this warning.This patch checks for invalid hva address and return
-EINVALbefore calling__kvm_gpc_activate().syzbot has tested the proposed patch and the reproducer did not trigger any issue.
Tested on:
commit:
afcd4813Merge tag 'mm-hotfixes-stable-2024-06-26-17-2.. git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1427e301980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e40800950091403a
dashboard link: https://syzkaller.appspot.com/bug?extid=fd555292a1da3180fc82
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=13838f3e980000Note: testing is done by a robot and is best-effort only.
---
Changes in v2:
- Adapted Sean's suggestion to check for valid address before calling into__kvm_gpc_activate().
- Link to v1: https://lore.kernel.org/r/[email protected]
---
arch/x86/kvm/xen.c | 2 +-
virt/kvm/pfncache.c| 3 +++Quoted 2 lines
2 files changed, 4 insertions(+), 1 deletion(-)
Quoted 1 line
Reviewed-by Paul Durrant <[email protected]>
Thanks.
Quoted 2 lines · Pei Li
Check for invalid hva address stored in data and return
-EINVALbefore calling into__kvm_gpc_activate().
Applied to kvm-x86 fixes, thanks!
[1/1] kvm: Fix warning in__kvm_gpc_refresh
https://github.com/kvm-x86/linux/commit/ebbdf37ce9ab