mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	Fix NULL dereference in gfn_to_hva_prot()
gfn_to_memslot() can return NULL or invalid slot. We need to check slot validity before accessing it. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
This commit is contained in:
		
							parent
							
								
									517bf8fc21
								
							
						
					
					
						commit
						a2ac07fe29
					
				
					 1 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
					@ -1064,10 +1064,12 @@ EXPORT_SYMBOL_GPL(gfn_to_hva);
 | 
				
			||||||
unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable)
 | 
					unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
 | 
						struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
 | 
				
			||||||
	if (writable)
 | 
						unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!kvm_is_error_hva(hva) && writable)
 | 
				
			||||||
		*writable = !memslot_is_readonly(slot);
 | 
							*writable = !memslot_is_readonly(slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return __gfn_to_hva_many(gfn_to_memslot(kvm, gfn), gfn, NULL, false);
 | 
						return hva;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int kvm_read_hva(void *data, void __user *hva, int len)
 | 
					static int kvm_read_hva(void *data, void __user *hva, int len)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue