Skip to content

Clang Static Analyzer plugin which detects the Y2K38 bug in 64bit enviroment

License

Notifications You must be signed in to change notification settings

cysec-lab/y2k38-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

y2k38-checker

Paper

y2k38-checker is a tool that identifies and reports code with potential Year 2038 problem issues in C language source code.

Check List

Check list ID Description
read-fs-timestamp Since the file timestamp attributes of ext2/3, XFS (versions prior to Linux 5.10), ReiserFS are 32-bit signed integers, programs that read file timestamps in these environments may be affected by the Y2K38.
write-fs-timestamp Since the file timestamp attributes of ext2/3, XFS (versions prior to Linux 5.10), ReiserFS are 32-bit signed integers, programs that write file timestamps in these environments may be affected by the Y2K38.
timet-to-int-downcast Since in many environments the int type is a 32-bit signed integer, there is a possibility that downcasting from time_t type to int may be affected by the Y2K38.
timet-to-long-downcast Since in many environments the int type is a 32-bit signed integer, there is a possibility that downcasting from time_t to long may be affected by the Y2K38.

How to use

Requirements:

  • Docker / Docker Compose
  • OS: Ubuntu

Setup

  1. Download the releases.
  2. Unzip the downloaded file.
unzip y2k38-checker-<version>.zip

Then, the following directory structure is created.

y2k38-checker/
├─┬ checker/
│  ├── build/lib/liby2k38-plugin.so  # detection tool as a Clang plugin
│  ├── scripts/           # scripts for running the detection tool
│  └── clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04
├── dataset/             # example for C source code
├── volumes/             # target source code
└┬─ .devcontainer/
  ├── Dockerfile
  ├── docker-compose.yml
  └── devcontainer.json
  1. Add the path of the created the directory in .devcontainer/docker-compose.yml
services:
   y2k38-checker-app:
      build:
         context: ..
         dockerfile: .devcontainer/Dockerfile
      tty: true
      volumes:
         - ..:/root/y2k38-checker/volumes/
         - type: bind
-          source: /home/cysec/develop/.y2k38-checker/analysis-objects/
+          source: <path/to/dir>
         target: /root/analysis-objects
  1. Build & Run the docker container with CLI or DevContainer
cd y2k38-checker
docker-compose build # only first time
docker-compose run y2k38-checker

Alternatively, start it in the devcontainer of VSCode.

  1. Run the detection tool with the following command.

Run as script

Check the source code in the volumes/ directory with the detection tool.

python3 ./checker/script/analyze/main.py file.c
# python3 ./checker/scripts/analyze/main.py ./dataset/blacklist/read-fs-timestamp.c

Run as a Clang plugin

clang -w -fplugin=/root/y2k38-checker/checker/build/lib/liby2k38-plugin.so -c file.c
# clang -w -fplugin=/root/y2k38-checker/checker/build/lib/liby2k38-plugin.so -c /root/y2k38-checker/dataset/blacklist/read-fs-timestamp.c

Development

Setup

  1. Clone the repository
git clone https://github.com/cysec-lab/y2k38-checker.git
  1. Create the directory for the detecting target source code, and add files to be analyzed.
mkdir <path/to/dir>
cp -r <files/to/be/analyzed> <path/to/dir>
  1. Download LLVM library
cd ./checker/
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz | tar -Jxf -
  1. Add the path of the created the directory in .devcontainer/docker-compose.yml
services:
   y2k38-checker-app:
      build:
         context: ..
         dockerfile: .devcontainer/Dockerfile
      tty: true
      volumes:
         - ..:/root/y2k38-checker/volumes/
         - type: bind
-          source: /home/cysec/develop/.y2k38-checker/analysis-objects/
+          source: <path/to/dir>
         target: /root/analysis-objects
  1. Build & Run the docker container with CLI or DevContainer
cd y2k38-checker
docker-compose build # only first time
docker-compose run y2k38-checker

Alternatively, start it in the devcontainer of VSCode.

Build

  1. Move to the checker/ directory
cd ./checker
  1. Build with CMake
cd ../checker/build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=True \
   -DLLVM_DIR=../clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/lib/cmake/llvm/ \
   ../clang-analyzer
make

Then, the plugin library is created in the build/lib directory.

Test

For Python scripts, run the following command.

cd ./checker/script/analyze/
PYTHONPATH=$(pwd) python3 -m unittest discover