mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:42:44 +00:00 
			
		
		
		
	Kernel: mmap() should fail with ENODEV for directories
This commit is contained in:
		
							parent
							
								
									3f35cd2f7d
								
							
						
					
					
						commit
						50056d1d84
					
				
					 2 changed files with 19 additions and 0 deletions
				
			
		|  | @ -339,6 +339,8 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* user_params) | |||
|         auto description = file_description(fd); | ||||
|         if (!description) | ||||
|             return (void*)-EBADF; | ||||
|         if (description->is_directory()) | ||||
|             return (void*)-ENODEV; | ||||
|         if ((prot & PROT_READ) && !description->is_readable()) | ||||
|             return (void*)-EACCES; | ||||
|         if ((prot & PROT_WRITE) && !description->is_writable()) | ||||
|  |  | |||
|  | @ -105,6 +105,22 @@ void test_ftruncate_negative() | |||
|     close(fd); | ||||
| } | ||||
| 
 | ||||
| void test_mmap_directory() | ||||
| { | ||||
|     int fd = open("/tmp", O_RDONLY | O_DIRECTORY); | ||||
|     ASSERT(fd >= 0); | ||||
|     auto* ptr = mmap(nullptr, 4096, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); | ||||
|     if (ptr != MAP_FAILED) { | ||||
|         fprintf(stderr, "Boo! mmap() of a directory succeeded!\n"); | ||||
|         return; | ||||
|     } | ||||
|     if (errno != ENODEV) { | ||||
|         fprintf(stderr, "Boo! mmap() of a directory gave errno=%d instead of ENODEV!\n", errno); | ||||
|         return; | ||||
|     } | ||||
|     close(fd); | ||||
| } | ||||
| 
 | ||||
| int main(int, char**) | ||||
| { | ||||
|     int rc; | ||||
|  | @ -123,6 +139,7 @@ int main(int, char**) | |||
|     test_read_past_eof(); | ||||
|     test_ftruncate_readonly(); | ||||
|     test_ftruncate_negative(); | ||||
|     test_mmap_directory(); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling