mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	tee: shm: don't put_page on null shm->pages
In the case that shm->pages fails to allocate, the current exit
error path will try to put_page on a null shm->pages and cause
a null pointer dereference when accessing shm->pages[n]. Fix this
by only performing the put_page and kfree on shm->pages if it
is not null.
Detected by CoverityScan, CID#1463283 ("Dereference after null check")
Fixes: 033ddf12bc ("tee: add register user memory")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
			
			
This commit is contained in:
		
							parent
							
								
									80ec6f5de6
								
							
						
					
					
						commit
						c94f31b526
					
				
					 1 changed files with 5 additions and 3 deletions
				
			
		| 
						 | 
					@ -335,10 +335,12 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
 | 
				
			||||||
			idr_remove(&teedev->idr, shm->id);
 | 
								idr_remove(&teedev->idr, shm->id);
 | 
				
			||||||
			mutex_unlock(&teedev->mutex);
 | 
								mutex_unlock(&teedev->mutex);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (shm->pages) {
 | 
				
			||||||
			for (n = 0; n < shm->num_pages; n++)
 | 
								for (n = 0; n < shm->num_pages; n++)
 | 
				
			||||||
				put_page(shm->pages[n]);
 | 
									put_page(shm->pages[n]);
 | 
				
			||||||
			kfree(shm->pages);
 | 
								kfree(shm->pages);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	kfree(shm);
 | 
						kfree(shm);
 | 
				
			||||||
	teedev_ctx_put(ctx);
 | 
						teedev_ctx_put(ctx);
 | 
				
			||||||
	tee_device_put(teedev);
 | 
						tee_device_put(teedev);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue