1 From ede885ecb2cdf8a8dd5367702e3d964ec846a2d5 Mon Sep 17 00:00:00 2001
2 From: David Rientjes <rientjes@google.com>
3 Date: Tue, 19 Mar 2019 15:19:56 -0700
4 Subject: kvm: svm: fix potential get_num_contig_pages overflow
6 From: David Rientjes <rientjes@google.com>
8 commit ede885ecb2cdf8a8dd5367702e3d964ec846a2d5 upstream.
10 get_num_contig_pages() could potentially overflow int so make its type
11 consistent with its usage.
13 Reported-by: Cfir Cohen <cfir@google.com>
14 Cc: stable@vger.kernel.org
15 Signed-off-by: David Rientjes <rientjes@google.com>
16 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 arch/x86/kvm/svm.c | 10 +++++-----
21 1 file changed, 5 insertions(+), 5 deletions(-)
23 --- a/arch/x86/kvm/svm.c
24 +++ b/arch/x86/kvm/svm.c
25 @@ -6398,11 +6398,11 @@ e_free:
29 -static int get_num_contig_pages(int idx, struct page **inpages,
30 - unsigned long npages)
31 +static unsigned long get_num_contig_pages(unsigned long idx,
32 + struct page **inpages, unsigned long npages)
34 unsigned long paddr, next_paddr;
35 - int i = idx + 1, pages = 1;
36 + unsigned long i = idx + 1, pages = 1;
38 /* find the number of contiguous pages starting from idx */
39 paddr = __sme_page_pa(inpages[idx]);
40 @@ -6421,12 +6421,12 @@ static int get_num_contig_pages(int idx,
42 static int sev_launch_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)
44 - unsigned long vaddr, vaddr_end, next_vaddr, npages, size;
45 + unsigned long vaddr, vaddr_end, next_vaddr, npages, pages, size, i;
46 struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
47 struct kvm_sev_launch_update_data params;
48 struct sev_data_launch_update_data *data;
49 struct page **inpages;