forked from mirrors/linux
		
	usercopy: Cast pointer to an integer once
Get rid of a lot of annoying casts by setting 'addr' once at the top of the function. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Tested-by: Zorro Lang <zlang@redhat.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220612213227.3881769-3-willy@infradead.org
This commit is contained in:
		
							parent
							
								
									993d0b287e
								
							
						
					
					
						commit
						35fb9ae4aa
					
				
					 1 changed files with 6 additions and 5 deletions
				
			
		| 
						 | 
					@ -161,26 +161,27 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n,
 | 
				
			||||||
static inline void check_heap_object(const void *ptr, unsigned long n,
 | 
					static inline void check_heap_object(const void *ptr, unsigned long n,
 | 
				
			||||||
				     bool to_user)
 | 
									     bool to_user)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						uintptr_t addr = (uintptr_t)ptr;
 | 
				
			||||||
	struct folio *folio;
 | 
						struct folio *folio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (is_kmap_addr(ptr)) {
 | 
						if (is_kmap_addr(ptr)) {
 | 
				
			||||||
		unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1);
 | 
							unsigned long page_end = addr | (PAGE_SIZE - 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((unsigned long)ptr + n - 1 > page_end)
 | 
							if (addr + n - 1 > page_end)
 | 
				
			||||||
			usercopy_abort("kmap", NULL, to_user,
 | 
								usercopy_abort("kmap", NULL, to_user,
 | 
				
			||||||
					offset_in_page(ptr), n);
 | 
										offset_in_page(ptr), n);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (is_vmalloc_addr(ptr)) {
 | 
						if (is_vmalloc_addr(ptr)) {
 | 
				
			||||||
		struct vmap_area *area = find_vmap_area((unsigned long)ptr);
 | 
							struct vmap_area *area = find_vmap_area(addr);
 | 
				
			||||||
		unsigned long offset;
 | 
							unsigned long offset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!area)
 | 
							if (!area)
 | 
				
			||||||
			usercopy_abort("vmalloc", "no area", to_user, 0, n);
 | 
								usercopy_abort("vmalloc", "no area", to_user, 0, n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		offset = (unsigned long)ptr - area->va_start;
 | 
							offset = addr - area->va_start;
 | 
				
			||||||
		if ((unsigned long)ptr + n > area->va_end)
 | 
							if (addr + n > area->va_end)
 | 
				
			||||||
			usercopy_abort("vmalloc", NULL, to_user, offset, n);
 | 
								usercopy_abort("vmalloc", NULL, to_user, offset, n);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue