Skip to content

Commit b9b8bbd

Browse files
committed
Fix bad ELF classification logic
Added interpreter trust validation so unknown PT_INTERP paths are accepted when the interpreter exists, is executable, and trusted via the trust database checks.
1 parent d6ab2b7 commit b9b8bbd

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/library/file.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
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

0 commit comments

Comments
 (0)