Skip to content

Commit

Permalink
Add Nginx static PIE ELF
Browse files Browse the repository at this point in the history
Add Nginx static PIE ELF together with root file system. Add
instructions and helper scripts to build Nginx as a static PIE ELF.

Signed-off-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
  • Loading branch information
razvand committed Jul 9, 2022
1 parent e5a35a9 commit f6bb2f7
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/nginx-1.22.0/
/nginx-1.22.0.tar.gz
28 changes: 28 additions & 0 deletions nginx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Build nginx as static PIE

Build the [nginx](https://www.nginx.com/) web server as a static PIE ELF running on Linux.

## Requirements

Make sure the following packages are installed:
* gcc >= 8 (required for the `-static-pie` linking option)
* autotools
* GNU Make
* libpcre development files
* zlib development files
* OpenSSL development files

For Ubuntu, run the command below to install all requirements:

```
$ sudo apt install build-essential libpcre2-dev zlib1g-dev libssl-dev
```

## Build

The `nginx` static PIE ELF is located in the current folder.
If you want to rebuild it, run:

```
$ ./build.sh
```
30 changes: 30 additions & 0 deletions nginx/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Clean up.
rm -fr nginx-*

echo -n "Downloading nginx ... "
wget -q http://nginx.org/download/nginx-1.22.0.tar.gz
echo ""

echo -n "Unpacking nginx ... "
tar xzf nginx-1.22.0.tar.gz
echo ""

pushd nginx-1.22.0 > /dev/null 2>&1 || exit

echo "Configuring nginx ... "

# Add PIC/PIE compile/link flags.
# Remove libpcre to fix static library dependency issue with libphtreads.
./configure --with-cc-opt="-fPIC" --with-ld-opt="-static-pie" --without-pcre --without-http_rewrite_module

# Remove linker flag to export dynamic symbols.
# This causes a static PIE ELF to crash.
sed -i '/\-Wl,\-E/d' objs/Makefile

echo -n "Building nginx ... "
make -j "$(nproc)"
popd > /dev/null 2>&1 || exit

ln -fn nginx-1.22.0/objs/nginx .
Binary file added nginx/nginx
Binary file not shown.
96 changes: 96 additions & 0 deletions nginx/rootfs/usr/local/nginx/conf/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;

text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;

image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;

font/woff woff;
font/woff2 woff2;

application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;

application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;

audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;

video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
26 changes: 26 additions & 0 deletions nginx/rootfs/usr/local/nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
worker_processes 1;
daemon off;
master_process off;

error_log logs/error.log debug;

events {
worker_connections 32;
}

http {
include mime.types;
default_type application/octet-stream;

keepalive_timeout 65;

server {
listen 80;
server_name localhost;

location / {
root /nginx/html;
index index.html index.htm;
}
}
}
10 changes: 10 additions & 0 deletions nginx/rootfs/usr/local/nginx/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>Powered by <a href="http://unikraft.org">Unikraft</a>.</p>
</body>
</html>
Empty file.
Empty file.

0 comments on commit f6bb2f7

Please sign in to comment.