File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 4242#include <mntent.h>
4343
4444#include "file.h"
45+ #include "database.h"
4546#include "message.h"
4647#include "process.h" // For elf info bit mask
4748#include "string-util.h"
@@ -1283,6 +1284,36 @@ static Elf64_Ehdr *read_header64(int fd, Elf64_Ehdr *ptr)
12831284}
12841285
12851286
1287+ /*
1288+ * interpreter_is_trusted - verify interpreter exists, is executable, trusted.
1289+ * @interp: absolute interpreter path from PT_INTERP.
1290+ * Returns 1 if interpreter exists, is executable, and trusted; 0 otherwise.
1291+ */
1292+ static int interpreter_is_trusted (const char * interp )
1293+ {
1294+ struct file_info * info ;
1295+ int fd ;
1296+ int trusted = 0 ;
1297+
1298+ if (interp == NULL || interp [0 ] == 0 )
1299+ return 0 ;
1300+
1301+ fd = open (interp , O_RDONLY |O_CLOEXEC );
1302+ if (fd < 0 )
1303+ return 0 ;
1304+
1305+ info = stat_file_entry (fd );
1306+ if (info && S_ISREG (info -> mode ) &&
1307+ (info -> mode & (S_IXUSR |S_IXGRP |S_IXOTH ))) {
1308+ if (check_trust_database (interp , info , fd ) == 1 )
1309+ trusted = 1 ;
1310+ }
1311+ free (info );
1312+
1313+ close (fd );
1314+ return trusted ;
1315+ }
1316+
12861317/**
12871318 * Check interpreter provided as an argument obtained from the ELF against
12881319 * known fixed locations in the file hierarchy.
@@ -1296,6 +1327,11 @@ static int check_interpreter(const char *interp)
12961327 return 0 ;
12971328 }
12981329
1330+ // We fell through the list that we know about.
1331+ // If it is trusted, allow it.
1332+ if (interpreter_is_trusted (interp ))
1333+ return 0 ;
1334+
12991335 return 1 ;
13001336}
13011337
You can’t perform that action at this time.
0 commit comments