Skip to content

Commit

Permalink
Create a rudimentary symbol scanning script
Browse files Browse the repository at this point in the history
We would like to be able to log and audit the symbols we use in openssl
so that we might catch when a new platform symbols is referecned

Add such a script (just on unix platforms for now) that gathers the used
symbols not belonging to libcrypto or libssl, and compare it to a prior
known set of used symbols.  Error out if a new symbol is found

Add this script to the ci workflow in CI to capture newly
introduced platform symbols

Fixes openssl#22330

Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#22478)
  • Loading branch information
nhorman authored and t8m committed Nov 1, 2023
1 parent bdcaa80 commit 796e5f9
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/run-checker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ jobs:
run: |
cat /proc/cpuinfo
./util/opensslwrap.sh version -c
- name: Check platform symbol usage
run: ./util/checkplatformsyms.pl ./util/platform_symbols/unix-symbols.txt ./libcrypto.so ./libssl.so
- name: make test
run: make test HARNESS_JOBS=${HARNESS_JOBS:-4}
3 changes: 3 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
7z.exe x coreinfo/Coreinfo.zip
./Coreinfo64.exe -accepteula -f
./apps/openssl.exe version -c
- name: Check platform symbol usage
working-directory: _build
run: perl ../util/checkplatformsyms.pl ../util/platform_symbols/windows-symbols.txt libcrypto-3-x64.dll ./libssl-3-x64.dll
- name: test
working-directory: _build
run: nmake test VERBOSE_FAILURE=yes TESTS=-test_fuzz* HARNESS_JOBS=4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/windows_comp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
7z.exe x coreinfo/Coreinfo.zip
./Coreinfo64.exe -accepteula -f
./apps/openssl.exe version -c
- name: Check platform symbol usage
run: |
perl ./util/checkplatformsyms.pl ./util/platform_symbols/windows-symbols.txt libcrypto-3-x64.dll ./libssl-3-x64.dll
- name: test
working-directory: _build
run: |
Expand Down
84 changes: 84 additions & 0 deletions util/checkplatformsyms.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#! /usr/bin/env perl
# Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

use warnings;
use strict;
use Config;

my $expectedsyms=$ARGV[0];

shift(@ARGV);

my $objlist;
my $objfilelist = join(" ", @ARGV);
my $expsyms;
my $exps;
my $OBJFH;
my $cmd;

if ($Config{osname} eq "MSWin32") {
my $currentdll = "";
$cmd = "dumpbin /imports " . $objfilelist;
my @symlist;
open $expsyms, '<', $expectedsyms or die;
{
local $/;
$exps=<$expsyms>;
}
close($expsyms);
open($OBJFH, "$cmd|") or die "Cannot open process: $!";
while (<$OBJFH>)
{
chomp;
my $dllfile = $_;
$dllfile =~ s/( +)(.*)(\.dll)(.*)/DLLFILE \2/;
if (index($dllfile, "DLLFILE") >= 0) {
$currentdll = substr($dllfile, 8);
$currentdll =~ s/^\s+|s+$//g;
}
# filter imports from our own library
if ("$currentdll" ne "libcrypto-3-x64") {
my $line = $_;
$line =~ s/ [0-9a-fA-F]{1,2} /SYMBOL /;
if (index($line, "SYMBOL") != -1) {
$line =~ s/.*SYMBOL //;
push(@symlist, $line);
}
}
}
foreach (@symlist) {
if (index($exps, $_) < 0) {
print "Symbol $_ not in the allowed platform symbols list\n";
exit 1;
}
}
exit 0;
}
else {
$cmd = "objdump -t " . $objfilelist . " | grep UND | grep -v \@OPENSSL";
$cmd = $cmd . " | awk '{print \$NF}' |";
$cmd = $cmd . " sed -e\"s/@.*\$//\" | sort | uniq";

open $expsyms, '<', $expectedsyms or die;
{
local $/;
$exps=<$expsyms>;
}
close($expsyms);

open($OBJFH, "$cmd|") or die "Cannot open process: $!";
while (<$OBJFH>)
{
if (index($exps, $_) < 0) {
print "Symbol $_ not in the allowed platform symbols list\n";
exit 1;
}
}
close($OBJFH);
exit 0;
}
156 changes: 156 additions & 0 deletions util/platform_symbols/unix-symbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
abort
accept
bcmp
bind
calloc
chmod
clearerr
clock_gettime
close
closedir
closelog
connect
__ctype_b_loc
__ctype_tolower_loc
__cxa_atexit
__cxa_finalize
dladdr
dlclose
dlerror
dlopen
dlsym
__errno_location
fclose
fdopen
feof
ferror
fflush
fgets
fileno
fopen
fopen64
fprintf
fputc
fputs
fread
free
freeaddrinfo
fseek
fstat
ftell
fwrite
gai_strerror
getaddrinfo
getauxval
getcontext
getentropy
getenv
gethostbyname
getnameinfo
getpeername
getpid
getsockname
getsockopt
gettimeofday
__gmon_start__
gmtime_r
gmtime
ioctl
__isoc99_sscanf
_ITM_deregisterTMCloneTable
_ITM_registerTMCloneTable
listen
_longjmp
lseek
madvise
makecontext
malloc
memchr
memcmp
memcpy
memmove
memset
mktime
mlock
mmap
mprotect
munmap
opendir
openlog
poll
pthread_attr_destroy
pthread_attr_init
pthread_attr_setdetachstate
pthread_cond_broadcast
pthread_cond_destroy
pthread_cond_init
pthread_cond_signal
pthread_cond_timedwait
pthread_cond_wait
pthread_create
pthread_exit
pthread_getspecific
pthread_join
pthread_key_create
pthread_key_delete
pthread_mutex_destroy
pthread_mutex_init
pthread_mutex_lock
pthread_mutex_trylock
pthread_mutex_unlock
pthread_once
pthread_rwlock_destroy
pthread_rwlock_init
pthread_rwlock_rdlock
pthread_rwlock_unlock
pthread_rwlock_wrlock
pthread_self
pthread_setspecific
qsort
readdir
realloc
recvfrom
recvmmsg
secure_getenv
select
sendmmsg
sendto
setbuf
setcontext
_setjmp
setsockopt
shmat
shmdt
shmget
shutdown
sigaction
sleep
socket
sprintf
stderr
stdin
stdout
strcat
strchr
strcmp
strcpy
strcspn
strdup
strlen
strncmp
strncpy
strrchr
strspn
strstr
strtol
strtoul
syscall
sysconf
syslog
tcgetattr
tcsetattr
__timezone
uname
usleep
vfprintf
__xpg_strerror_r
Loading

0 comments on commit 796e5f9

Please sign in to comment.