servers/rs: Add sanity check on executable size
RS used to do a stat, and check that the stat was successful, but it didn't check that the executable was not actually empty. This patch adds a check to detect file which are smaller than the minimum ELF size possible. Change-Id: I22b004084f17e7d395e2c1377add7bc8b51c3d5e
This commit is contained in:
		
							parent
							
								
									f1778d4cdd
								
							
						
					
					
						commit
						37f29f557a
					
				@ -58,6 +58,8 @@ static int elf_ph_sane(Elf_Phdr *phdr)
 | 
				
			|||||||
static int elf_unpack(char *exec_hdr,
 | 
					static int elf_unpack(char *exec_hdr,
 | 
				
			||||||
	int hdr_len, Elf_Ehdr **hdr, Elf_Phdr **phdr)
 | 
						int hdr_len, Elf_Ehdr **hdr, Elf_Phdr **phdr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  assert(hdr_len >= sizeof(Elf_Ehdr));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  *hdr = (Elf_Ehdr *) exec_hdr;
 | 
					  *hdr = (Elf_Ehdr *) exec_hdr;
 | 
				
			||||||
  if(!elf_sane(*hdr)) {
 | 
					  if(!elf_sane(*hdr)) {
 | 
				
			||||||
  	return ENOEXEC;
 | 
					  	return ENOEXEC;
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <paths.h>
 | 
					#include <paths.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/exec_elf.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "inc.h"
 | 
					#include "inc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "kernel/proc.h"
 | 
					#include "kernel/proc.h"
 | 
				
			||||||
@ -1272,6 +1274,9 @@ struct rproc *rp;
 | 
				
			|||||||
  if (r != 0) 
 | 
					  if (r != 0) 
 | 
				
			||||||
      return -errno;
 | 
					      return -errno;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (sb.st_size < sizeof(Elf_Ehdr))
 | 
				
			||||||
 | 
					      return ENOEXEC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fd= open(e_name, O_RDONLY);
 | 
					  fd= open(e_name, O_RDONLY);
 | 
				
			||||||
  if (fd == -1)
 | 
					  if (fd == -1)
 | 
				
			||||||
      return -errno;
 | 
					      return -errno;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user