pax_global_header00006660000000000000000000000064151606322130014511gustar00rootroot0000000000000052 comment=a1205ccf98216095623280a2a026e0eee60916af jtsylve-LiME-a1205cc/000077500000000000000000000000001516063221300143755ustar00rootroot00000000000000jtsylve-LiME-a1205cc/.github/000077500000000000000000000000001516063221300157355ustar00rootroot00000000000000jtsylve-LiME-a1205cc/.github/FUNDING.yml000066400000000000000000000015251516063221300175550ustar00rootroot00000000000000# These are supported funding model platforms github: [jtsylve] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry polar: # Replace with a single Polar username buy_me_a_coffee: # Replace with a single Buy Me a Coffee username thanks_dev: # Replace with a single thanks.dev username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] jtsylve-LiME-a1205cc/.github/workflows/000077500000000000000000000000001516063221300177725ustar00rootroot00000000000000jtsylve-LiME-a1205cc/.github/workflows/build-test.yml000066400000000000000000000226131516063221300225750ustar00rootroot00000000000000name: CI on: push: branches: [master] paths: ['src/**', 'test/**', '.github/workflows/build-test.yml'] pull_request: paths: ['src/**', 'test/**', '.github/workflows/build-test.yml'] schedule: - cron: '0 6 * * 1' # weekly — keeps caches alive (7-day eviction) workflow_dispatch: env: # modules_prepare doesn't generate Module.symvers (requires full kernel # build) — let modpost warn instead of error. QEMU smoke tests verify # actual module loading. KBUILD_MODPOST_WARN: "1" jobs: # --------------------------------------------------------------------------- # Tier 1 — Compile testing # # One job per unique kernel tree. Each job runs all applicable build # variants in sequence (~10s each) to avoid redundant cache restores. # Trees are stripped to ~100-180 MB after modules_prepare. # # WERROR is tested via KCFLAGS="-Werror" (no separate kernel tree needed). # # Cache budget: ~1.6 GB compile + ~700 MB QEMU + ~180 MB canary ≈ 2.5 GB # (GitHub limit: 10 GB per repo) # --------------------------------------------------------------------------- build: name: >- Build: ${{ matrix.kernel }} ${{ matrix.config != 'defconfig' && format('[{0}]', matrix.config) || '' }} runs-on: ubuntu-24.04 timeout-minutes: 20 strategy: fail-fast: false matrix: include: # # API breakpoints covered: # 4.6 crypto_ahash 4.14 kernel_write # 5.8 sock_set_reuseaddr 5.10 set_fs() removed # 5.11 kmap_local_page 6.8 -Wmissing-prototypes # 6.12 PREEMPT_RT merged 6.19 sockaddr_unsized # - { kernel: "5.4", config: defconfig, builds: "default" } - { kernel: "5.10", config: defconfig, builds: "default" } - { kernel: "5.15", config: defconfig, builds: "default debug symbols werror" } - { kernel: "6.1", config: defconfig, builds: "default" } - { kernel: "6.6", config: defconfig, builds: "default debug symbols werror" } - { kernel: "6.12", config: defconfig, builds: "default werror" } - { kernel: "6.19", config: defconfig, builds: "default werror" } - { kernel: "5.15", config: no-zlib, builds: "default" } - { kernel: "6.6", config: no-zlib, builds: "default" } - { kernel: "6.12", config: preempt-rt, builds: "default" } steps: - uses: actions/checkout@v6 - name: Install build dependencies run: sudo apt-get update -qq && sudo apt-get install -y -qq libelf-dev libssl-dev dwarves # Read the pinned version for this kernel series. The version goes # into the cache key directly so bumping ONE version in the conf file # invalidates only THAT version's cache entries — not all of them. - name: Resolve pinned version id: pin run: | VER=$(grep "^${{ matrix.kernel }}=" test/kernel-versions.conf | cut -d= -f2) echo "version=${VER:-unknown}" >> "$GITHUB_OUTPUT" - name: Cache kernel tree id: cache uses: actions/cache@v5 with: path: /tmp/linux-build key: kernel-${{ matrix.kernel }}-${{ matrix.config }}-${{ steps.pin.outputs.version }}-${{ hashFiles('test/prepare-kernel.sh') }} - name: Prepare kernel headers if: steps.cache.outputs.cache-hit != 'true' run: bash test/prepare-kernel.sh "${{ matrix.kernel }}" "${{ matrix.config }}" - name: Build and verify run: | builds="${{ matrix.builds }}" for build in $builds; do echo "::group::Build: $build" make -C src clean || true case "$build" in default) make -C src KDIR=/tmp/linux-build ;; debug) make -C src debug KDIR=/tmp/linux-build ;; symbols) make -C src symbols KDIR=/tmp/linux-build ;; werror) KCFLAGS="-Werror" make -C src KDIR=/tmp/linux-build ;; *) echo "::error::Unknown build variant: $build"; exit 1 ;; esac file src/lime-*.ko | grep -q ELF echo "$build: OK ($(ls -lh src/lime-*.ko | awk '{print $5}'))" echo "::endgroup::" done # Latest stable kernel — early warning, allowed to fail build-latest: name: "Build: latest (canary)" runs-on: ubuntu-24.04 timeout-minutes: 20 continue-on-error: true steps: - uses: actions/checkout@v6 - name: Install build dependencies run: sudo apt-get update -qq && sudo apt-get install -y -qq libelf-dev libssl-dev dwarves - name: Resolve latest stable kernel id: latest run: | VER=$(curl -sf https://www.kernel.org/releases.json | python3 -c " import json, sys data = json.load(sys.stdin) for r in data['releases']: v = r['version'] if not r.get('iseol') and 'rc' not in v and '-' not in v: print(v) break ") SERIES="${VER%.*}" echo "version=${VER}" >> "$GITHUB_OUTPUT" echo "series=${SERIES}" >> "$GITHUB_OUTPUT" echo "==> Latest stable: ${VER} (series ${SERIES})" - name: Cache kernel tree id: cache uses: actions/cache@v5 with: path: /tmp/linux-build # Canary uses dynamic resolution — conf file is irrelevant, only hash the script key: kernel-latest-${{ steps.latest.outputs.version }}-${{ hashFiles('test/prepare-kernel.sh') }} - name: Prepare kernel headers if: steps.cache.outputs.cache-hit != 'true' run: bash test/prepare-kernel.sh "${{ steps.latest.outputs.series }}" defconfig - name: Build and verify run: | make -C src KDIR=/tmp/linux-build file src/lime-*.ko | grep -q ELF # --------------------------------------------------------------------------- # Tier 2 — Static analysis # # Waits for build jobs so the 6.6-defconfig cache is guaranteed warm. # Same cache key → free cache hit, zero prep time. # --------------------------------------------------------------------------- analyze: name: Static analysis needs: build if: ${{ !cancelled() }} runs-on: ubuntu-24.04 timeout-minutes: 20 steps: - uses: actions/checkout@v6 - name: Install dependencies run: sudo apt-get update -qq && sudo apt-get install -y -qq libelf-dev libssl-dev dwarves sparse - name: Resolve pinned version id: pin run: | VER=$(grep "^6.6=" test/kernel-versions.conf | cut -d= -f2) echo "version=${VER:-unknown}" >> "$GITHUB_OUTPUT" - name: Cache kernel tree id: cache uses: actions/cache@v5 with: path: /tmp/linux-build key: kernel-6.6-defconfig-${{ steps.pin.outputs.version }}-${{ hashFiles('test/prepare-kernel.sh') }} - name: Prepare kernel headers if: steps.cache.outputs.cache-hit != 'true' run: bash test/prepare-kernel.sh 6.6 defconfig - name: Sparse check run: | make -C /tmp/linux-build M="$(pwd)/src" C=2 modules 2>&1 | \ tee /tmp/sparse.log if grep -E '(error|warning):' /tmp/sparse.log | grep -q "$(pwd)/src/"; then echo "::error::Sparse found issues in LiME source" grep -E '(error|warning):' /tmp/sparse.log | grep "$(pwd)/src/" exit 1 fi - name: Source checks run: bash test/check-source.sh # --------------------------------------------------------------------------- # Tier 3 — Runtime smoke tests # # Boots real kernels in QEMU with a minimal initramfs. Uses separate # cache entries (kernel-qemu-*) since these include the full kernel image. # # Depends on build to avoid wasting the expensive bzImage build when the # code has a fundamental compilation error. Uses !cancelled() so that # an unrelated build failure (e.g., 4.15) doesn't block smoke-testing 6.6. # --------------------------------------------------------------------------- smoke-test: name: "Smoke: Linux ${{ matrix.kernel }}" needs: build if: ${{ !cancelled() }} runs-on: ubuntu-24.04 timeout-minutes: 45 strategy: fail-fast: false matrix: kernel: ["5.15", "6.6"] steps: - uses: actions/checkout@v6 # CI runners are x86_64; local testing (test/local.sh) handles other arches. - name: Install dependencies run: sudo apt-get update -qq && sudo apt-get install -y -qq libelf-dev libssl-dev dwarves qemu-system-x86 busybox-static - name: Resolve pinned version id: pin run: | VER=$(grep "^${{ matrix.kernel }}=" test/kernel-versions.conf | cut -d= -f2) echo "version=${VER:-unknown}" >> "$GITHUB_OUTPUT" - name: Cache full kernel build id: cache uses: actions/cache@v5 with: path: /tmp/linux-build key: kernel-qemu-${{ matrix.kernel }}-${{ steps.pin.outputs.version }}-${{ hashFiles('test/prepare-kernel.sh') }} - name: Prepare and build kernel if: steps.cache.outputs.cache-hit != 'true' run: bash test/prepare-kernel.sh "${{ matrix.kernel }}" qemu - name: Build LiME module run: make -C src KDIR=/tmp/linux-build - name: Run smoke tests run: bash test/qemu-smoke-test.sh /tmp/linux-build src/lime-*.ko jtsylve-LiME-a1205cc/.github/workflows/pre-commit.yml000066400000000000000000000004351516063221300225730ustar00rootroot00000000000000name: pre-commit on: push: branches: [master] pull_request: jobs: pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 with: python-version: "3.x" - uses: pre-commit/action@v3.0.1 jtsylve-LiME-a1205cc/.gitignore000066400000000000000000000002061516063221300163630ustar00rootroot00000000000000# Dumps *.lime *.raw # Objects *.o *.ko Module.symvers modules.order *.mod *.mod.c *.cmd .tmp_versions/ # Claude .claude CLAUDE.md jtsylve-LiME-a1205cc/.pre-commit-config.yaml000066400000000000000000000013361516063221300206610ustar00rootroot00000000000000repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-merge-conflict - repo: https://github.com/DavidAnson/markdownlint-cli2 rev: v0.22.0 hooks: - id: markdownlint-cli2 - repo: local hooks: - id: flawfinder name: flawfinder entry: flawfinder --error-level=4 language: python additional_dependencies: ["flawfinder"] types: [c] - repo: https://github.com/codespell-project/codespell rev: v2.4.2 hooks: - id: codespell - repo: https://github.com/fsfe/reuse-tool rev: v6.2.0 hooks: - id: reuse jtsylve-LiME-a1205cc/LICENSE000077700000000000000000000000001516063221300212412LICENSES/GPL-2.0-only.txtustar00rootroot00000000000000jtsylve-LiME-a1205cc/LICENSES/000077500000000000000000000000001516063221300156025ustar00rootroot00000000000000jtsylve-LiME-a1205cc/LICENSES/GPL-2.0-only.txt000066400000000000000000000416711516063221300202520ustar00rootroot00000000000000GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice jtsylve-LiME-a1205cc/README.md000066400000000000000000000124401516063221300156550ustar00rootroot00000000000000# LiME ~ Linux Memory Extractor A Loadable Kernel Module (LKM) for volatile memory acquisition from Linux and Linux-based devices, such as Android. LiME minimizes its interaction between user and kernel space processes during acquisition, producing memory captures that are more forensically sound than those of other tools designed for Linux memory acquisition. ## Table of Contents * [Features](#features) * [Usage](#usage) * [Examples](#examples) * [Available Digests](#available-digests) * [Compression](#compression) * [Presentation](#presentation) ## Features * Full memory acquisition from Linux (and Android) systems * Acquisition over network interface or to local disk * Multiple output formats (raw, lime, padded) * Optional hashing with sidecar digest file * Optional zlib compression * Minimal process footprint ## Usage Detailed documentation on LiME's usage and internals can be found in the "docs" directory of the project. LiME uses the insmod command to load the module, passing required arguments for its execution. ```text insmod ./lime-$(uname -r).ko "path=> format= [digest=] [dio=<0|1>] [compress=<0|1>] [localhostonly=<0|1>] [timeout=]" path (required): outfile ~ name of file to write to on local system tcp:port ~ network port to communicate over format (required): padded ~ pads all non-System RAM ranges with 0s, starting from physical address 0 lime ~ each range prepended with fixed-size header containing address space info raw ~ concatenates all System RAM ranges (warning: original position of dumped memory is likely to be lost therefore making analysis in most forensics tools impossible. This format is not recommended except for advanced users) digest (optional): Hash the RAM and provide a sidecar file with the sum. The sidecar filename is the output path with the digest algorithm appended (e.g., ram.lime.sha256). Supports kernel version 2.6.11 and up. See below for available digest options. Note: enabling digest increases code complexity during acquisition and will overwrite additional memory. Only use when integrity verification is required. compress (optional): 1 ~ compress output with zlib 0 ~ do not compress (default) Only available when CONFIG_ZLIB_DEFLATE is enabled in the kernel. Note: enabling compression allocates additional kernel memory (~24 KB) and increases code complexity during acquisition, disturbing more of the target system's memory. Only use when the speed or size benefit is required. dio (optional): 1 ~ attempt to enable Direct IO 0 ~ do not attempt Direct IO (default) localhostonly (optional): 1 ~ restricts tcp to only listen on localhost 0 ~ binds on all interfaces (default) timeout (optional): 1000 ~ max milliseconds tolerated to read/write a page (default, 1 second). If a page exceeds the timeout, the rest of that memory range is skipped. 0 ~ disable the timeout so the slow region will be acquired. This feature is only available on kernels >= 2.6.35. ``` ## Examples ### Linux Acquiring memory to a file: ```bash insmod ./lime-$(uname -r).ko "path=/tmp/ram.lime format=lime" ``` Acquiring memory over the network: ```bash insmod ./lime-$(uname -r).ko "path=tcp:4444 format=lime" ``` Then on the receiving machine: ```bash nc 4444 > ram.lime ``` ### Android Use adb to load LiME and acquire memory over the network: ```bash adb push lime.ko /sdcard/lime.ko adb forward tcp:4444 tcp:4444 adb shell su insmod /sdcard/lime.ko "path=tcp:4444 format=lime" ``` On the host machine, capture the memory dump using netcat: ```bash nc localhost 4444 > ram.lime ``` Acquiring to the SD card: ```bash insmod /sdcard/lime.ko "path=/sdcard/ram.lime format=lime" ``` ## Available Digests LiME supports any digest algorithm available in the kernel's crypto library. Collecting a digest file when dumping over TCP requires 2 separate connections. ```bash nc localhost 4444 > ram.lime nc localhost 4444 > ram.sha1 ``` For quick reference, here is a list of supported digests. ### 2.6.11 and up ```text crc32c md4, md5 sha1, sha224, sha256, sha384, sha512 wp512, wp384, wp256 ``` ### 3.0 and up ```text rmd128, rmd160, rmd256, rmd320 ``` ### 4.10 and up ```text sha3-224, sha3-256, sha3-384, sha3-512 ``` ## Compression Compression can significantly reduce the time required to acquire a memory capture. It can achieve a speedup of 4x over uncompressed transfers with minimal memory overhead (~24 KB). The RAM file will be in the zlib format, which is different from the gzip or zip formats. The reason is that the deflate library embedded in the kernel does not support them. To decompress it you can use [pigz](https://zlib.net/pigz/) or any zlib-compatible library. ```bash nc localhost 4444 | unpigz > ram.lime ``` Note that only the RAM file is compressed. The digest file is not compressed, and the hash value will match the uncompressed data. ## Presentation LiME was first presented at Shmoocon 2012 by Joe Sylve. Youtube~ [Android Mind Reading: Memory Acquisition and Analysis with DMD and Volatility][shmoocon-talk] [shmoocon-talk]: https://www.youtube.com/watch?v=oWkOyphlmM8 jtsylve-LiME-a1205cc/REUSE.toml000066400000000000000000000011231516063221300161520ustar00rootroot00000000000000# SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only version = 1 [[annotations]] path = [ "README.md", "docs/README.md", "docs/external_modules.md", ".gitignore", ".github/FUNDING.yml", ".github/workflows/pre-commit.yml", ".pre-commit-config.yaml", ".github/workflows/build-test.yml", "docs/test-architecture.md", "test/Dockerfile", "test/kernel-versions.conf", ] SPDX-FileCopyrightText = "2011-2026 Joe T. Sylve, Ph.D. " SPDX-License-Identifier = "GPL-2.0-only" jtsylve-LiME-a1205cc/docs/000077500000000000000000000000001516063221300153255ustar00rootroot00000000000000jtsylve-LiME-a1205cc/docs/README.md000066400000000000000000000205751516063221300166150ustar00rootroot00000000000000# LiME ~ Linux Memory Extractor ## Contents * [Compiling LiME](#compiling-lime) * [Linux](#linux) * [External](#external) * [Debug](#debug) * [Symbols](#symbols) * [Android](#android) * [Usage](#usage) * [Parameters](#parameters) * [Acquisition of Memory over TCP](#acquisition-of-memory-over-tcp) * [Acquisition of Memory to Disk](#acquisition-of-memory-to-disk) * [LiME Memory Range Header Version 1 Specification](#lime-memory-range-header-version-1-specification) ## Compiling LiME ### Linux LiME is a Loadable Kernel Module (LKM). LiME ships with a default Makefile that should be suitable for compilation on most modern Linux systems. For detailed instructions on using LKMs, see . ### External LiME can be compiled externally from the target in order to provide a more forensically sound and secure method. Follow this [guide](./external_modules.md) to learn how. ### Debug When compiling LiME with the default Makefile, using the command "make debug" will compile a LiME module with extra debug output. The output can be read by using the dmesg command on Linux. ### Symbols When compiling LiME with the default Makefile, using the command "make symbols" will compile a LiME module without stripping symbols. This is useful for tools such as Volatility where one can create a profile without loading a second module. ### Android In order to cross-compile LiME for use on an Android device, additional steps are required. #### Prerequisites Disclaimer: This list may be incomplete. Please let us know if we've missed anything. * Install the general android prerequisites found at * Download and un(zip|tar) the android NDK found at . * Download and un(zip|tar) the android SDK found at . * Download and untar the kernel source for your device. This can usually be found on the website of your device manufacturer or by a quick Google search. * Root your device. In order to run custom kernel modules, you must have a rooted device. * Plug the device into computer via a USB cable. #### Setting Up the Environment In order to simplify the process, we will first set some environment variables. In a terminal, type the following commands: ```bash export SDK_PATH=/path/to/android-sdk-linux/ export NDK_PATH=/path/to/android-ndk/ export KSRC_PATH=/path/to/kernel-source/ export CC_PATH=$NDK_PATH/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ export LIME_SRC=/path/to/lime/src ``` #### Preparing the Kernel Source We must retrieve and copy the kernel config from our device. ```bash cd $SDK_PATH/platform-tools ./adb pull /proc/config.gz gunzip ./config.gz cp config $KSRC_PATH/.config ``` Next we have to prepare our kernel source for our module. ```bash cd $KSRC_PATH make ARCH=arm CROSS_COMPILE=$CC_PATH/arm-eabi- modules_prepare ``` #### Preparing the Module for Compilation We need to create a Makefile to cross-compile our kernel module. A sample Makefile for cross-compiling is shipped with the LiME source. The contents of your Makefile should be similar to the following: ```text obj-m := lime.o lime-objs := tcp.o disk.o main.o hash.o deflate.o KDIR := /path/to/kernel-source PWD := $(shell pwd) CCPATH := /path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ default: $(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-eabi- -C $(KDIR) M=$(PWD) modules ``` #### Compiling the Module ```bash cd $LIME_SRC make ``` ## Usage The following examples demonstrate acquiring memory from a Linux or Android device over TCP and to disk. On standard Linux systems, you do not need adb -- simply use insmod directly. The Android examples below use the Android Debug Bridge (adb) to load the module and tunnel network traffic over USB. ### Parameters LiME supports multiple output formats, including a custom lime format which integrates with Volatility's lime address space. NOTE: On some Android devices there is a bug in insmod where multiple kernel module parameters must be wrapped in quotation marks, otherwise only the first parameter will be parsed. See the TCP and Disk acquisition examples below. ```text path Required. Either a filename to write on the local system or tcp: format Required. One of the following: padded: Pads all non-System RAM ranges with 0s, starting from physical address 0. lime: Each range is prepended with a fixed-size header which contains address space information. raw: Simply concatenates all System RAM ranges. Most memory analysis tools do not support this format, as memory position information is lost (unless System RAM is in one continuous range starting from physical address 0) digest Optional. Hash the RAM and provide a sidecar file with the sum. The sidecar filename is the output path with the digest algorithm appended (e.g., ram.lime.sha256). Supports kernel version 2.6.11 and up. When dumping over TCP, the digest file requires a second connection. Note: enabling digest increases code complexity during acquisition and will overwrite additional memory. Only use when integrity verification is required. compress Optional. 1 to compress output with zlib, 0 to disable (default). Only available when CONFIG_ZLIB_DEFLATE is enabled in the kernel. Note: enabling compression allocates additional kernel memory (~24 KB) and increases code complexity during acquisition, disturbing more of the target system's memory. Only use when the speed or size benefit is required. dio Optional. 1 to enable Direct IO attempt, 0 to disable (default) localhostonly Optional. 1 restricts the tcp to only listen on localhost, 0 binds on all interfaces (default) timeout Optional. If it takes longer than the specified timeout (in milliseconds) to read/write a page of memory, then the rest of that range is skipped. Set timeout to 0 to disable. The default is 1000 (1 second). Only available on kernel versions >= 2.6.35. ``` ### Acquisition of Memory over TCP #### Linux (TCP) On the target system, load the module and listen on a TCP port: ```bash insmod ./lime-$(uname -r).ko "path=tcp:4444 format=lime" ``` On the receiving machine, connect with netcat and redirect the output to a file: ```bash nc 4444 > ram.lime ``` When acquisition is complete, LiME terminates the TCP connection. #### Android (TCP) Copy the kernel module to the device using adb, set up a port-forwarding tunnel, and obtain a root shell: ```bash adb push lime.ko /sdcard/lime.ko adb forward tcp:4444 tcp:4444 adb shell su ``` Load the module on the device: ```bash insmod /sdcard/lime.ko "path=tcp:4444 format=lime" ``` On the host, capture the memory dump through the forwarded port: ```bash nc localhost 4444 > ram.lime ``` ### Acquisition of Memory to Disk Disk-based acquisition may be preferred when the investigator wants to avoid overwriting network buffers. Set the path parameter to a file path to write the memory image directly to disk. #### Linux (Disk) ```bash insmod ./lime-$(uname -r).ko "path=/tmp/ram.lime format=lime" ``` #### Android (Disk) On Android, the SD card is a common destination. If the SD card may contain other evidence, consider imaging it first before writing the memory dump. ```bash insmod /sdcard/lime.ko "path=/sdcard/ram.lime format=lime" ``` Once acquisition is complete, transfer the memory dump to the examination machine using adb or by removing the SD card. ## LiME Memory Range Header Version 1 Specification ```c typedef struct { unsigned int magic; // Always 0x4C694D45 (LiME) unsigned int version; // Header version number unsigned long long s_addr; // Starting address of range unsigned long long e_addr; // Ending address of range unsigned char reserved[8]; // Currently all zeros } __attribute__ ((__packed__)) lime_mem_range_header; ``` jtsylve-LiME-a1205cc/docs/external_modules.md000066400000000000000000000214551516063221300212300ustar00rootroot00000000000000# Building External Modules ## Contents * [Introduction](#introduction) * [How to](#how-to) * [Required tools](#required-tools) * [Downloading the kernel source](#downloading-the-kernel-source) * [Choosing the correct kernel release](#choosing-the-correct-kernel-release) * [Using an old kernel config](#using-an-old-kernel-config) * [Setting the correct version](#setting-the-correct-version) * [Prepare the source and compile](#prepare-the-source-and-compile) * [OS specific resources](#os-specific-resources) * [CentOS](#centos) * [Fedora](#fedora) * [RHEL](#rhel) * [Ubuntu](#ubuntu) ## Introduction Compiling kernel modules outside of the running kernel is known as building **external** or **out of tree** modules. For `LiME`, compiling externally is a more forensically sound and secure method, as the kernel object is not compiled on the target system. This also means administrators do not need to install gcc, kernel headers, or other development tools on production systems. See the [kernel documentation on building external modules][kbuild] for more background. [kbuild]: https://www.kernel.org/doc/Documentation/kbuild/modules.txt **NOTE** This guide does not cover `cross compiling` external modules. If your architecture differs from your host machine you will need to cross compile your module. ## How to The following is a step-by-step guide, using Ubuntu, in order to compile your own external module. The steps will vary by distribution. Some distribution specifics will be covered at the end of this document. ### Required tools You will need the following tools: * git * build-essential package **OS specific** ### Downloading the kernel source The first task is to find and download the correct kernel source for your distribution and version. For this the examples below use the Ubuntu kernel. You can read [Ubuntu's guide for downloading source][ubuntu-kernel]. [ubuntu-kernel]: https://wiki.ubuntu.com/Kernel/Dev/KernelGitGuide Here is the short version: In order to determine the correct OS version of your target machine, you can run `cat /etc/os-release`. ```console $ cat /etc/os-release NAME="Ubuntu" VERSION="16.04.2 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.2 LTS" VERSION_ID="16.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" VERSION_CODENAME=xenial UBUNTU_CODENAME=xenial ``` From the output above we can see that our release is `Xenial 16.04.2 LTS`. Now we must go and clone the source using `git`. For our Ubuntu example the links are in the following format. ```text kernel.ubuntu.com/ubuntu/ubuntu-< release >.git ``` Following our Xenial example, we would clone the source by entering this: ```bash git clone git://kernel.ubuntu.com/ubuntu/ubuntu-xenial.git ``` If the git protocol is blocked by a firewall, you can clone via http instead. ```bash git clone http://kernel.ubuntu.com/git-repos/ubuntu/ubuntu-xenial.git ``` This will be a lot slower and you will not be able to set the history depth, therefore downloading far more data. ### Choosing the correct kernel release Once the repository has finished cloning, we will need to checkout the correct kernel release. To complete this task run `uname -r` on the target machine. ```console $ uname -r 4.10.0-38-generic ``` The most important take-away of the kernel release is the string after the `sublevel` digit. The Linux kernel is versioned in the following format: ```text version.patchlevel.sublevel-localversion ``` From the example above we can see that our local version needs to be `-38-generic`. Once you have determined the version that you need to build, change directory into your kernel source. From this location run: ```bash git tag -l ``` to list all the tags. Find the tag that matches your kernel version *version.patchlevel.sublevel* and checkout that point in history. ```bash git checkout < tag > ``` Following our Ubuntu guide you would run something like the following: ```bash git checkout Ubuntu-lts-4.10.0-9.11_16.04.2 ``` ### Using an old kernel config In order to build an external module that will fit the target running kernel, we need to know how your kernel was built. The kernel build process stores this information in a config file, storing that in `/boot/config-*`. Copy the correct config file to your kernel working directory and then rename it to `.config`. In our Ubuntu example the correct config file is located at: ```text /boot/config-4.10.0-38-generic ``` Once you have renamed the config file `.config`, run the following: ```console $ make olddefconfig HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o SHIPPED scripts/kconfig/zconf.tab.c SHIPPED scripts/kconfig/zconf.lex.c SHIPPED scripts/kconfig/zconf.hash.c HOSTCC scripts/kconfig/zconf.tab.o HOSTLD scripts/kconfig/conf scripts/kconfig/conf --olddefconfig Kconfig # # configuration written to .config # ``` This will use the old kernel config and set any new options (present in the kernel source but missing from the config) to their default values. ### Setting the correct version This is the most important part of the entire process. If the version does not match the running kernel, your module will most likely fail to install. This is due to a kernel safety measure, enabled by default, to prevent incompatible modules from loading. Once the config completes, we need to make sure that all the versions match before we continue. Run the following: ```console $ make kernelrelease 4.10.0+ ``` Did make complete without error? Does that match the version you want? If so continue; else checkout a different tag with git. Did you notice that our kernel release is missing the `localversion` string? Well, let's fix that using your favorite text editor. Find the lines that say the following: ```text # # General setup # CONFIG_INIT_ENV_ARG_LIMIT=32 CONFIG_CROSS_COMPILE="" # CONFIG_COMPILE_TEST is not set CONFIG_LOCALVERSION="" # CONFIG_LOCALVERSION_AUTO is not set CONFIG_HAVE_KERNEL_GZIP=y ``` Change **both** `CONFIG_LOCALVERSION` and `# CONFIG_LOCALVERSION_AUTO is not set` to match the following example: ```text CONFIG_LOCALVERSION="< localversion >" CONFIG_LOCALVERSION_AUTO=n ``` In our Ubuntu example add `-38-generic` and don't forget the hyphen. ```text CONFIG_LOCALVERSION="-38-generic" CONFIG_LOCALVERSION_AUTO=n ``` Now run `make kernelrelease` again: ```console $ make kernelrelease 4.10.0-38-generic+ ``` Is your localversion correct? If so, continue. Note the `+` at the end of the localversion string. We need to remove this: ```bash touch .scmversion ``` to create an empty file. Now run `make kernelrelease` once more, this time the version should be an exact match. ```console $ make kernelrelease 4.10.0-38-generic ``` ### Prepare the source and compile Now run: ```bash make modules_prepare ``` in order to prepare the kernel source tree for building external modules. This skips compiling an entire kernel, saving you some cycles. If this completes without error, one can proceed with compiling the module. We will use LiME as the example module. Change directory into your LiME source and run: ```bash make -C < path-src-tree > KVER=< kernel-version > M=$(pwd) ``` `path-src-tree` is the location where you cloned your kernel source. Again, following our Ubuntu example: ```bash make -C /home/kd8bny/ubuntu-xenial KVER=4.10.0-38-generic M=$(pwd) ``` And there you have it! A successfully compiled **external** kernel module. Now feel free to load this into the running kernel on your target machine. ## OS specific resources ### CentOS CentOS and RHEL package source a little differently. The source is packaged as an RPM. This is a semi-helpful [CentOS kernel source guide][centos-kernel]. [centos-kernel]: https://wiki.centos.org/HowTos/I_need_the_Kernel_Source The source is located at the [CentOS vault](http://vault.centos.org). Browse to the following location and download. ```text http://vault.centos.org/< cent version >/os/Source/ SPackages/kernel-3.10.0-123.el7.src.rpm ``` Once you have downloaded the RPM, extract it using `rpm2cpio` and `cpio`: ```bash rpm2cpio kernel-3.10.0-123.el7.src.rpm | cpio -idmv ``` Inside the extracted contents you will find an archive named `linux-`. Extract it to get the kernel source. You can use the config files already found in this source. Continue as stated in the guide, ignoring the use of `git`. ### Fedora Fedora keeps kernel source off the main linux git tree. Clone it from the following location: ```text git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git ``` Follow the same process in the guide. ### RHEL Follow the CentOS section, as this is where the source is located for non-subscribers. If you are a subscriber, you can download the source from Red Hat. ### Ubuntu Follow as shown in the guide. [Ubuntu kernel source](http://kernel.ubuntu.com/git/) jtsylve-LiME-a1205cc/docs/test-architecture.md000066400000000000000000000235311516063221300213120ustar00rootroot00000000000000# Test Architecture LiME uses a three-tier testing strategy: compile testing across multiple kernel versions, static analysis, and runtime smoke tests in QEMU virtual machines. All tiers run in GitHub Actions CI and can be reproduced locally via Docker. ## Directory Layout ```text test/ kernel-versions.conf # Pinned kernel versions (one per series) prepare-kernel.sh # Downloads, configures, and strips kernel trees check-source.sh # Grep-based static source checks qemu-smoke-test.sh # QEMU boot harness (multi-arch) build-initramfs.sh # Packs busybox + lime.ko into a cpio.gz smoke-init # Init script (PID 1) inside the QEMU VM Dockerfile # Ubuntu 24.04 image for local testing local.sh # Self-dispatching host/container test runner .github/workflows/ build-test.yml # CI workflow definition ``` ## Tier 1 -- Compile Testing Builds the module against eight pinned kernel series spanning the range of supported kernel APIs: | Series | API breakpoints covered | |--------|------------------------------------------------------------| | 4.15 | crypto_ahash (4.6), kernel_write (4.14) | | 5.4 | | | 5.10 | sock_set_reuseaddr (5.8), set_fs() removed (5.10) | | 5.15 | kmap_local_page (5.11) | | 6.1 | | | 6.6 | | | 6.12 | -Wmissing-prototypes (6.8), PREEMPT_RT merged (6.12) | | 6.19 | sockaddr_unsized (6.19) | Each kernel series is tested with one or more build variants: - **default** -- standard `make` (all series) - **debug** -- `make debug`, enables DBG() printk output (5.15, 6.6) - **symbols** -- `make symbols`, preserves debug info (5.15, 6.6) - **werror** -- `KCFLAGS="-Werror"` (5.15, 6.6, 6.12, 6.19) Additional kernel configs: - **no-zlib** -- `CONFIG_ZLIB_DEFLATE` disabled (5.15, 6.6): verifies deflate.c is correctly excluded when compression is unavailable. - **preempt-rt** -- `CONFIG_PREEMPT_RT` enabled (6.12): verifies compatibility with the RT patchset. A **canary job** builds against the latest stable kernel (dynamically resolved from kernel.org). It is allowed to fail and serves as an early warning for upstream API changes. ### Kernel Tree Preparation `prepare-kernel.sh` handles the full lifecycle: 1. Resolves the exact version from `kernel-versions.conf` (pinned) or git ls-remote (canary fallback). 2. Downloads the tarball from cdn.kernel.org. 3. Runs `defconfig`, then applies config-specific overrides via `scripts/config` (e.g., disabling zlib, enabling PREEMPT_RT, or adding QEMU console/virtio/initrd support). 4. Enables LiME requirements: `CONFIG_MODULES`, `CONFIG_CRYPTO`, `CONFIG_CRYPTO_HASH`, `CONFIG_CRYPTO_SHA256`, `CONFIG_INET`, `CONFIG_NET`. 5. Runs `modules_prepare` (lightweight, no full kernel build). 6. For `qemu` config only, builds the full kernel image (bzImage/Image/zImage). 7. Strips the tree to ~100-180 MB by removing source files, object files, and large directories (drivers, fs, mm, net, etc.), keeping only headers, scripts, Makefiles, and generated build artifacts. `KBUILD_MODPOST_WARN=1` is set globally because `modules_prepare` does not generate `Module.symvers`. Unresolved symbol warnings are acceptable at compile time; actual module loading is verified in Tier 3. ## Tier 2 -- Static Analysis Runs after Tier 1 completes. Reuses the cached 6.6-defconfig kernel tree (same cache key = free cache hit). ### Sparse Runs the kernel's sparse static analyzer in `C=2` mode (check all files, not just recompiled ones): ```bash make -C M= C=2 modules ``` Fails if sparse reports any errors or warnings in LiME source files. ### Source Checks `check-source.sh` runs grep-based validation (portable across macOS and Linux, no dependencies beyond coreutils): 1. **Extern declarations** -- Non-static functions in tcp.c, disk.c, hash.c, and deflate.c must have matching `extern` declarations in lime.h. 2. **Format string safety** -- `resource_size_t` values must use `(unsigned long long)` cast with `%llx`, not bare `%lx` (truncates on 32-bit PAE). 3. **SPDX headers** -- All .c and .h files must contain an `SPDX-License-Identifier` line. 4. **Pointer arithmetic** -- Warns on `void*` arithmetic without `(u8 *)` cast (GNU extension, not portable). 5. **Version guard consistency** -- `LINUX_VERSION_CODE >` without `=` is flagged (should usually be `>=` for "introduced in" checks). 6. **ERR_PTR cleanup** -- disk.c must have at least two `f = NULL` sites (success path and error path in dio_write_test) to prevent closing an error pointer. ## Tier 3 -- Runtime Smoke Tests Boots real kernels in QEMU with a minimal initramfs containing busybox and the compiled lime.ko. Runs against two kernel series in CI (5.15, 6.6). Depends on Tier 1 to avoid wasting the expensive full kernel build when the code has a compilation error. ### QEMU Configuration `qemu-smoke-test.sh` selects architecture-specific settings based on `uname -m`: | Architecture | QEMU binary | Kernel image | Console | |-----------------|------------------------|-----------------------|---------| | x86_64 | qemu-system-x86_64 | arch/x86/boot/bzImage | ttyS0 | | aarch64 | qemu-system-aarch64 | arch/arm64/boot/Image | ttyAMA0 | | armv7l / armhf | qemu-system-arm | arch/arm/boot/zImage | ttyAMA0 | | riscv64 | qemu-system-riscv64 | arch/riscv/boot/Image | ttyS0 | CI runs x86_64 only (GitHub Actions runners). Local testing via Docker supports all four architectures. The VM is configured with 256 MB RAM, 2 vCPUs, no reboot on panic, and a 180-second timeout. All I/O goes through the serial console (`-nographic`). ### Initramfs `build-initramfs.sh` creates a minimal cpio.gz archive containing: - `/bin/busybox` with symlinks for sh, mount, insmod, rmmod, od, wc, etc. - `/lib/modules/lime.ko` (the compiled module) - `/init` (copy of `smoke-init`) ### Test Cases `smoke-init` runs as PID 1 inside the VM. Each test loads the module with specific parameters, verifies the output, then unloads and cleans up (the VM has only 256 MB of RAM, so tmpfs space is tight). | Test | Parameters | Verification | |------|-----------------|-------------------------------------------| | t1 | `format=lime` | File exists, magic = `0x4C694D45` | | t2 | `format=raw` | File exists, size saved as baseline | | t3 | `format=padded` | Output size >= RAW size (zero-fill) | | t4 | SHA-256 digest | `.sha256` sidecar has 64 hex chars | | t5 | `compress=1` | Compressed output < RAW baseline | Tests are independent; a failure in one does not block others. t4 is skipped if the kernel's crypto subsystem lacks SHA-256. t5 is skipped if compression is unavailable or if t2 failed (no baseline). Results are reported as PASS/FAIL/SKIP counters. The final line `SMOKE_TEST_RESULT=PASS` or `SMOKE_TEST_RESULT=FAIL` is parsed by the harness to determine the exit code. ### What Is Not Tested - TCP transport (network streaming) - Direct I/O (`dio=1`) - `localhostonly` parameter - Memory edge cases (sparse RAM layouts, large gaps) - Performance or stress testing - Android devices ## CI Workflow Defined in `.github/workflows/build-test.yml`. **Triggers:** push to master, pull requests (filtered to src/test/workflow paths), weekly schedule (Monday 06:00 UTC to keep caches alive), and manual dispatch. **Job dependency graph:** ```text build (11 matrix entries) | +---> analyze (sparse + source checks) | +---> smoke-test (5.15, 6.6) build-latest (canary, independent, allowed to fail) ``` `analyze` and `smoke-test` use `if: !cancelled()` so an unrelated build failure (e.g., 4.15) does not block testing on 6.6. **Timeouts:** 20 minutes for build/analyze jobs, 45 minutes for smoke tests. ### Caching Strategy Each kernel tree is cached independently. Cache keys incorporate the kernel series, config variant, pinned version, and a hash of `prepare-kernel.sh`: ```text kernel-{series}-{config}-{pinned_version}-{script_hash} ``` Bumping one version in `kernel-versions.conf` invalidates only that series' cache entries. Smoke tests use separate `kernel-qemu-*` keys since they include the full kernel image. **Budget:** ~2.5 GB total (1.6 GB compile trees + 700 MB QEMU trees + 180 MB canary). GitHub Actions allows 10 GB per repo. ## Local Testing `test/local.sh` is a self-dispatching script: on the host it manages Docker, inside the container it runs the tests. ### Setup A Docker image (`lime-test`) is built from `test/Dockerfile` (Ubuntu 24.04 with build-essential, kernel toolchain, sparse, busybox-static, and QEMU for x86, ARM, and RISC-V). A persistent Docker volume (`lime-kernel-cache`) stores prepared kernel trees across runs. ### Commands ```bash ./test/local.sh build [kernel] [config] [builds] # Compile test (default: 6.6) ./test/local.sh analyze # Sparse + source checks ./test/local.sh smoke [kernel] # QEMU runtime test ./test/local.sh all # Full CI matrix ./test/local.sh clean # Remove Docker image and cache ./test/local.sh shell # Interactive shell in container ``` The source directory is mounted read-only (`-v $ROOT:/src:ro`); builds happen in `/tmp/build` (a writable copy). KVM passthrough (`--device /dev/kvm`) is enabled automatically when `/dev/kvm` exists on the host. **Performance:** ~5 minutes per kernel on first run (full download + build), ~10 seconds per kernel on subsequent runs (cache hit). A full `all` run takes ~30 minutes cold, ~5 minutes warm. jtsylve-LiME-a1205cc/src/000077500000000000000000000000001516063221300151645ustar00rootroot00000000000000jtsylve-LiME-a1205cc/src/Makefile000066400000000000000000000035451516063221300166330ustar00rootroot00000000000000# LiME - Linux Memory Extractor # Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. # # Author: # Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve # # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA obj-m := lime.o lime-objs := tcp.o disk.o main.o hash.o deflate.o KVER ?= $(shell uname -r) KDIR ?= /lib/modules/$(KVER)/build PWD := $(shell pwd) .PHONY: modules modules_install clean distclean debug default: $(MAKE) -C $(KDIR) M="$(PWD)" modules strip --strip-unneeded lime.ko mv lime.ko lime-$(KVER).ko debug: KCFLAGS="-DLIME_DEBUG" $(MAKE) CONFIG_DEBUG_SG=y -C $(KDIR) M="$(PWD)" modules strip --strip-unneeded lime.ko mv lime.ko lime-$(KVER).ko symbols: $(MAKE) -C $(KDIR) M="$(PWD)" modules mv lime.ko lime-$(KVER).ko modules: main.c disk.c tcp.c hash.c deflate.c lime.h $(MAKE) -C $(KDIR) M="$(PWD)" $@ strip --strip-unneeded lime.ko modules_install: modules $(MAKE) -C $(KDIR) M="$(PWD)" $@ clean: rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d rm -rf \.tmp_versions distclean: mrproper mrproper: clean rm -f *.ko jtsylve-LiME-a1205cc/src/Makefile.sample000066400000000000000000000035321516063221300201070ustar00rootroot00000000000000# LiME - Linux Memory Extractor # Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. # # Author: # Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve # # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # This is a sample Makefile for cross-compiling the LiME LKM obj-m := lime.o lime-objs := tcp.o disk.o main.o hash.o deflate.o KDIR_GOLD := /usr/local/kernels/goldfish/ KVER := $(shell uname -r) PWD := $(shell pwd) CCPATH := /usr/local/bin/google/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin default: # cross-compile for Android emulator $(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR_GOLD) M="$(PWD)" modules $(CCPATH)/arm-linux-androideabi-strip --strip-unneeded lime.ko mv lime.ko lime-goldfish.ko # compile for local system $(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" modules strip --strip-unneeded lime.ko mv lime.ko lime-$(KVER).ko $(MAKE) tidy tidy: rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d rm -rf \.tmp_versions clean: $(MAKE) tidy rm -f *.ko jtsylve-LiME-a1205cc/src/deflate.c000066400000000000000000000051341516063221300167370ustar00rootroot00000000000000/* * LiME - Linux Memory Extractor * Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. * * Author: * Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve * * SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef CONFIG_ZLIB_DEFLATE #include #include "lime.h" /* Balance high compression level and memory footprint. */ #define DEFLATE_WBITS 11 /* 8KB */ #define DEFLATE_MEMLEVEL 5 /* 12KB */ static struct z_stream_s zstream; static void *next_out; static size_t avail_out; int deflate_begin_stream(void *out, size_t outlen) { int size; size = zlib_deflate_workspacesize(DEFLATE_WBITS, DEFLATE_MEMLEVEL); zstream.workspace = kzalloc(size, GFP_NOIO); if (!zstream.workspace) { return -ENOMEM; } if (zlib_deflateInit2(&zstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, DEFLATE_WBITS, DEFLATE_MEMLEVEL, Z_DEFAULT_STRATEGY) != Z_OK) { kfree(zstream.workspace); return -EINVAL; } next_out = out; avail_out = outlen; zstream.next_out = next_out; zstream.avail_out = avail_out; return 0; } int deflate_end_stream(void) { zlib_deflateEnd(&zstream); kfree(zstream.workspace); return 0; } ssize_t deflate(const void *in, size_t inlen) { int flush, ret; if (in && inlen > 0) flush = Z_NO_FLUSH; else flush = Z_FINISH; if (zstream.avail_out != 0) { zstream.next_in = in; zstream.avail_in = inlen; } zstream.next_out = next_out; zstream.avail_out = avail_out; ret = zlib_deflate(&zstream, flush); if (ret != Z_OK && !(flush == Z_FINISH && ret == Z_STREAM_END)) { DBG("Deflate error: %d", ret); return -EIO; } return avail_out - zstream.avail_out; } #endif jtsylve-LiME-a1205cc/src/disk.c000066400000000000000000000053071516063221300162670ustar00rootroot00000000000000/* * LiME - Linux Memory Extractor * Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. * * Author: * Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve * * SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "lime.h" static struct file * f = NULL; static int dio_write_test(char *path, int oflags) { int ok; f = filp_open(path, oflags | O_DIRECT | O_SYNC, 0444); if (f && !IS_ERR(f)) { ok = write_vaddr_disk("DIO", 3) == 3; filp_close(f, NULL); f = NULL; } else { f = NULL; ok = 0; } return ok; } int setup_disk(char *path, int dio) { int oflags = O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC; int err = 0; #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) mm_segment_t fs; fs = get_fs(); set_fs(KERNEL_DS); #endif if (dio && dio_write_test(path, oflags)) { oflags |= O_DIRECT | O_SYNC; } else { DBG("Direct IO Disabled"); } f = filp_open(path, oflags, 0444); if (!f || IS_ERR(f)) { DBG("Error opening file %ld", PTR_ERR(f)); err = (f) ? PTR_ERR(f) : -EIO; f = NULL; } #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) set_fs(fs); #endif return err; } void cleanup_disk(void) { #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) mm_segment_t fs; fs = get_fs(); set_fs(KERNEL_DS); #endif if(f) { filp_close(f, NULL); f = NULL; } #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) set_fs(fs); #endif } ssize_t write_vaddr_disk(void * v, size_t is) { ssize_t s; loff_t pos; #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) mm_segment_t fs; #endif pos = f->f_pos; #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) fs = get_fs(); set_fs(KERNEL_DS); s = vfs_write(f, v, is, &pos); set_fs(fs); #else s = kernel_write(f, v, is, &pos); #endif if (s == is) { f->f_pos = pos; } return s; } jtsylve-LiME-a1205cc/src/hash.c000066400000000000000000000137711516063221300162640ustar00rootroot00000000000000/* * LiME - Linux Memory Extractor * Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. * * Author: * Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve * * SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "lime.h" static u8 *output; static int digestsize; static char *digest_value; #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) static struct crypto_ahash *tfm; static struct ahash_request *req; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) static struct crypto_hash *tfm; static struct hash_desc desc; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) static struct crypto_tfm *tfm; #endif int ldigest_init(void) { DBG("Initializing Digest Transformation."); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) tfm = crypto_alloc_ahash(digest, 0, CRYPTO_ALG_ASYNC); if (unlikely(IS_ERR(tfm))) { tfm = NULL; goto init_fail; } req = ahash_request_alloc(tfm, GFP_ATOMIC); if (unlikely(!req)) goto init_fail; digestsize = crypto_ahash_digestsize(tfm); ahash_request_set_callback(req, 0, NULL, NULL); crypto_ahash_init(req); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) tfm = crypto_alloc_hash(digest, 0, CRYPTO_ALG_ASYNC); if (unlikely(IS_ERR(tfm))) { tfm = NULL; goto init_fail; } desc.tfm = tfm; desc.flags = 0; digestsize = crypto_hash_digestsize(tfm); crypto_hash_init(&desc); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) tfm = crypto_alloc_tfm(digest, 0); if (unlikely(tfm == NULL)) goto init_fail; digestsize = crypto_tfm_alg_digestsize(tfm); crypto_digest_init(tfm); #else DBG("Digest not supported for this kernel version."); goto init_fail; #endif output = kzalloc(digestsize, GFP_ATOMIC); if (!output) goto init_fail; return LIME_DIGEST_COMPUTE; init_fail: DBG("Digest Initialization Failed."); return LIME_DIGEST_FAILED; } static int ldigest_update_sg(struct scatterlist *sg, size_t len) { int ret = 0; #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) ahash_request_set_crypt(req, sg, output, len); ret = crypto_ahash_update(req); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) ret = crypto_hash_update(&desc, sg, len); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) crypto_digest_update(tfm, sg, 1); #endif return ret; } int ldigest_update(void *v, size_t is) { int ret; struct scatterlist sg; if (likely(virt_addr_valid(v))) { sg_init_one(&sg, (u8 *) v, is); ret = ldigest_update_sg(&sg, is); if (ret < 0) goto update_fail; } else { int nbytes = is; DBG("Invalid Virtual Address, Manually Scanning Page."); while (nbytes > 0) { int len = nbytes; int off = offset_in_page(v); if (off + len > (int)PAGE_SIZE) len = PAGE_SIZE - off; sg_init_table(&sg, 1); sg_set_page(&sg, vmalloc_to_page((u8 *) v), len, off); ret = ldigest_update_sg(&sg, len); if (ret < 0) goto update_fail; v = (u8 *)v + len; nbytes -= len; } } return LIME_DIGEST_COMPUTE; update_fail: DBG("Digest Update Failed."); return LIME_DIGEST_FAILED; } int ldigest_final(void) { int ret, i; DBG("Finalizing the digest."); digest_value = kmalloc(digestsize * 2 + 1, GFP_KERNEL); if (!digest_value) goto final_fail; #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) ret = crypto_ahash_final(req); if (ret < 0) goto final_fail; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) ret = crypto_hash_final(&desc, output); if (ret < 0) goto final_fail; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) crypto_digest_final(tfm, output); #endif for (i = 0; i= KERNEL_VERSION(4, 6, 0) if (tfm) crypto_free_ahash(tfm); ahash_request_free(req); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) if (tfm) crypto_free_hash(tfm); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) if (tfm) crypto_free_tfm(tfm); #endif } jtsylve-LiME-a1205cc/src/lime.h000066400000000000000000000072401516063221300162660ustar00rootroot00000000000000/* * LiME - Linux Memory Extractor * Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. * * Author: * Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve * * SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __LIME_H_ #define __LIME_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) #include #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) #include #endif #define LIME_RAMSTR "System RAM" #define LIME_MAX_FILENAME_SIZE 256 #define LIME_MAGIC 0x4C694D45 //LiME #define LIME_MODE_RAW 0 #define LIME_MODE_LIME 1 #define LIME_MODE_PADDED 2 #define LIME_METHOD_UNKNOWN 0 #define LIME_METHOD_TCP 1 #define LIME_METHOD_DISK 2 #define LIME_DIGEST_FAILED -1 #define LIME_DIGEST_COMPLETE 0 #define LIME_DIGEST_COMPUTE 1 #ifdef LIME_DEBUG #define DBG(fmt, args...) do { printk("[LiME] "fmt"\n", ## args); } while (0) #else #define DBG(fmt, args...) do {} while(0) #endif #define RETRY_IF_INTERRUPTED(f) ({ \ ssize_t err; \ do { err = f; } while(err == -EAGAIN || err == -EINTR); \ err; \ }) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35) #define LIME_SUPPORTS_TIMING #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) #define lime_map_page(page) kmap_local_page(page) #define lime_unmap_page(v, page) kunmap_local(v) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) #define lime_map_page(page) kmap_atomic(page) #define lime_unmap_page(v, page) kunmap_atomic(v) #else #define lime_map_page(page) kmap(page) #define lime_unmap_page(v, page) kunmap(page) #endif #ifdef CONFIG_ZLIB_DEFLATE #define LIME_SUPPORTS_DEFLATE #endif // main.c globals extern char *path; extern char *digest; extern int port; extern int localhostonly; // tcp.c extern ssize_t write_vaddr_tcp(void *, size_t); extern int setup_tcp(void); extern void cleanup_tcp(void); // disk.c extern ssize_t write_vaddr_disk(void *, size_t); extern int setup_disk(char *, int); extern void cleanup_disk(void); // hash.c extern int ldigest_init(void); extern int ldigest_update(void *, size_t); extern int ldigest_final(void); extern int ldigest_write_tcp(void); extern int ldigest_write_disk(void); extern void ldigest_clean(void); // deflate.c #ifdef LIME_SUPPORTS_DEFLATE extern int deflate_begin_stream(void *, size_t); extern int deflate_end_stream(void); extern ssize_t deflate(const void *, size_t); #endif // structures typedef struct { unsigned int magic; unsigned int version; unsigned long long s_addr; unsigned long long e_addr; unsigned char reserved[8]; } __attribute__ ((__packed__)) lime_mem_range_header; #endif //__LIME_H_ jtsylve-LiME-a1205cc/src/main.c000066400000000000000000000274431516063221300162660ustar00rootroot00000000000000/* * LiME - Linux Memory Extractor * Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. * * Author: * Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve * * SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "lime.h" static ssize_t write_lime_header(struct resource *); static ssize_t write_padding(size_t); static void write_range(struct resource *); static int init(void); static ssize_t write_vaddr(void *, size_t); static ssize_t write_flush(void); static ssize_t try_write(void *, ssize_t); static int setup(void); static void cleanup(void); /* * Helpers for walking the iomem_resource tree depth-first. * * Since kernel 5.8, drivers like virtio-mem and dax/kmem create * "System RAM" entries nested inside non-busy parent resources. * A sibling-only walk misses all such memory, so we must descend * into children when searching for RAM ranges. * * However, once we find a matching range, we must NOT descend into * its children — sub-resources like "Kernel code" and "Kernel data" * also carry IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY flags but are * sub-ranges already covered by the parent dump. */ /* Advance past p and all its descendants to the next unrelated node. */ static struct resource *lime_skip_subtree(struct resource *p) { while (!p->sibling && p->parent) p = p->parent; return p->sibling; } /* Depth-first: try child first, then sibling/ancestor's sibling. */ static struct resource *lime_next_resource(struct resource *p) { if (p->child) return p->child; return lime_skip_subtree(p); } /* * Check whether a resource represents busy System RAM. * Since 4.6 we use the IORESOURCE_SYSTEM_RAM flag which matches all * variants ("System RAM", "System RAM (virtio_mem)", "System RAM (kmem)"). * On older kernels fall back to exact string comparison, which is fine * because nested System RAM entries did not exist before 5.8. */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) static inline int lime_is_ram(struct resource *r) { return (r->flags & (IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY)) == (IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY); } #else static inline int lime_is_ram(struct resource *r) { return r->name && strcmp(r->name, LIME_RAMSTR) == 0; } #endif static char * format = NULL; static int mode = 0; static int method = 0; static void * vpage; #ifdef LIME_SUPPORTS_DEFLATE static void *deflate_page_buf; #endif char * path = NULL; static int dio = 0; int port = 0; int localhostonly = 0; char * digest = NULL; static int compute_digest = 0; module_param(path, charp, S_IRUGO); module_param(dio, int, S_IRUGO); module_param(format, charp, S_IRUGO); module_param(localhostonly, int, S_IRUGO); module_param(digest, charp, S_IRUGO); #ifdef LIME_SUPPORTS_TIMING static long timeout = 1000; module_param(timeout, long, S_IRUGO); #endif #ifdef LIME_SUPPORTS_DEFLATE static int compress = 0; module_param(compress, int, S_IRUGO); #endif static int __init lime_init_module (void) { if(!path) { DBG("No path parameter specified"); return -EINVAL; } if(!format) { DBG("No format parameter specified"); return -EINVAL; } DBG("Parameters"); DBG(" PATH: %s", path); DBG(" DIO: %u", dio); DBG(" FORMAT: %s", format); DBG(" LOCALHOSTONLY: %u", localhostonly); DBG(" DIGEST: %s", digest); #ifdef LIME_SUPPORTS_TIMING DBG(" TIMEOUT: %lu", timeout); #endif #ifdef LIME_SUPPORTS_DEFLATE DBG(" COMPRESS: %u", compress); #endif if (!strcmp(format, "raw")) mode = LIME_MODE_RAW; else if (!strcmp(format, "lime")) mode = LIME_MODE_LIME; else if (!strcmp(format, "padded")) mode = LIME_MODE_PADDED; else { DBG("Invalid format parameter specified."); return -EINVAL; } method = (sscanf(path, "tcp:%d", &port) == 1) ? LIME_METHOD_TCP : LIME_METHOD_DISK; return init(); } static int init(void) { struct resource *p; int err = 0; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) resource_size_t p_last = -1; #else __PTRDIFF_TYPE__ p_last = -1; #endif DBG("Initializing Dump..."); if ((err = setup())) { DBG("Setup Error"); cleanup(); return err; } if (digest) compute_digest = ldigest_init(); vpage = (void *) __get_free_page(GFP_NOIO); if (!vpage) { DBG("Failed to allocate page"); err = -ENOMEM; goto err_digest; } #ifdef LIME_SUPPORTS_DEFLATE if (compress) { deflate_page_buf = kmalloc(PAGE_SIZE, GFP_NOIO); if (!deflate_page_buf) { DBG("Failed to allocate deflate buffer"); err = -ENOMEM; goto err_vpage; } err = deflate_begin_stream(deflate_page_buf, PAGE_SIZE); if (err < 0) { DBG("ZLIB begin stream failed"); goto err_deflate_buf; } } #endif for (p = iomem_resource.child; p; ) { if (!lime_is_ram(p)) { /* Not RAM — descend into children to find nested RAM. */ p = lime_next_resource(p); continue; } if (mode == LIME_MODE_LIME && write_lime_header(p) < 0) { DBG("Error writing header 0x%llx - 0x%llx", (unsigned long long) p->start, (unsigned long long) p->end); break; } else if (mode == LIME_MODE_PADDED && write_padding((size_t) ((p->start - 1) - p_last)) < 0) { DBG("Error writing padding 0x%llx - 0x%llx", (unsigned long long) p_last, (unsigned long long) (p->start - 1)); break; } write_range(p); p_last = p->end; /* Children are sub-ranges already covered — skip them. */ p = lime_skip_subtree(p); } write_flush(); DBG("Memory Dump Complete..."); cleanup(); if (compute_digest == LIME_DIGEST_COMPUTE) { DBG("Writing Out Digest."); compute_digest = ldigest_final(); if (compute_digest == LIME_DIGEST_COMPLETE) { if (method == LIME_METHOD_TCP) err = ldigest_write_tcp(); else err = ldigest_write_disk(); DBG("Digest Write %s.", (err == 0) ? "Complete" : "Failed"); } } if (digest) ldigest_clean(); #ifdef LIME_SUPPORTS_DEFLATE if (compress) { deflate_end_stream(); kfree(deflate_page_buf); } #endif free_page((unsigned long) vpage); return 0; #ifdef LIME_SUPPORTS_DEFLATE err_deflate_buf: kfree(deflate_page_buf); err_vpage: #endif free_page((unsigned long) vpage); err_digest: if (digest) ldigest_clean(); cleanup(); return err; } static ssize_t write_lime_header(struct resource * res) { lime_mem_range_header header; memset(&header, 0, sizeof(lime_mem_range_header)); header.magic = LIME_MAGIC; header.version = 1; header.s_addr = res->start; header.e_addr = res->end; return write_vaddr(&header, sizeof(lime_mem_range_header)); } static ssize_t write_padding(size_t s) { size_t i = 0; ssize_t r; memset(vpage, 0, PAGE_SIZE); while(s -= i) { i = min((size_t) PAGE_SIZE, s); r = write_vaddr(vpage, i); if (r != i) { DBG("Error sending zero page: %zd", r); return r; } } return 0; } static void write_range(struct resource * res) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) resource_size_t i, is; #else __PTRDIFF_TYPE__ i, is; #endif struct page * p; void * v; ssize_t s; #ifdef LIME_SUPPORTS_TIMING ktime_t start,end; #endif DBG("Writing range %llx - %llx.", (unsigned long long) res->start, (unsigned long long) res->end); for (i = res->start; i <= res->end; i += is) { #ifdef LIME_SUPPORTS_TIMING start = ktime_get_real(); #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) is = min((resource_size_t) PAGE_SIZE, (resource_size_t) (res->end - i + 1)); #else is = min((size_t) PAGE_SIZE, (size_t) (res->end - i + 1)); #endif if (is < PAGE_SIZE) { // We can't map partial pages and // the linux kernel doesn't use them anyway DBG("Padding partial page: addr 0x%llx size: %lu", (unsigned long long) i, (unsigned long) is); write_padding(is); } else if (unlikely(!pfn_valid(i >> PAGE_SHIFT))) { // Guard against invalid PFNs which can occur on SPARSEMEM // configs, during memory hotremove, or on unusual NUMA layouts DBG("Invalid PFN 0x%llx, writing padding", (unsigned long long)(i >> PAGE_SHIFT)); write_padding(is); } else { p = pfn_to_page(i >> PAGE_SHIFT); v = lime_map_page(p); #ifdef copy_mc_to_kernel { unsigned long mc_err; mc_err = copy_mc_to_kernel(vpage, v, PAGE_SIZE); if (mc_err) { DBG("Hardware memory error at PFN 0x%llx (%lu bytes unreadable)", (unsigned long long)(i >> PAGE_SHIFT), mc_err); memset((char *)vpage + PAGE_SIZE - mc_err, 0, mc_err); } } #else copy_page(vpage, v); #endif lime_unmap_page(v, p); s = write_vaddr(vpage, is); if (s < 0) { DBG("Failed to write page: addr 0x%llx. Skipping Range...", (unsigned long long) i); break; } } #ifdef LIME_SUPPORTS_TIMING end = ktime_get_real(); if (timeout > 0 && ktime_to_ms(ktime_sub(end, start)) > timeout) { DBG("Reading is too slow. Skipping Range..."); write_padding(res->end - i + 1 - is); break; } #endif } } static ssize_t write_vaddr(void * v, size_t is) { ssize_t ret; if (compute_digest == LIME_DIGEST_COMPUTE) compute_digest = ldigest_update(v, is); #ifdef LIME_SUPPORTS_DEFLATE if (compress) { /* Run deflate() on input until output buffer is not full. */ do { ret = try_write(deflate_page_buf, deflate(v, is)); if (ret < 0) return ret; } while (ret == PAGE_SIZE); return is; } #endif return try_write(v, is); } static ssize_t write_flush(void) { #ifdef LIME_SUPPORTS_DEFLATE if (compress) { try_write(deflate_page_buf, deflate(NULL, 0)); } #endif return 0; } static ssize_t try_write(void * v, ssize_t is) { ssize_t ret; if (is <= 0) return is; ret = RETRY_IF_INTERRUPTED( (method == LIME_METHOD_TCP) ? write_vaddr_tcp(v, is) : write_vaddr_disk(v, is) ); if (ret < 0) { DBG("Write error: %zd", ret); } else if (ret != is) { DBG("Short write %zd instead of %zd.", ret, is); ret = -1; } return ret; } static int setup(void) { return (method == LIME_METHOD_TCP) ? setup_tcp() : setup_disk(path, dio); } static void cleanup(void) { if (method == LIME_METHOD_TCP) cleanup_tcp(); else cleanup_disk(); } static void __exit lime_cleanup_module(void) { } module_init(lime_init_module); module_exit(lime_cleanup_module); MODULE_LICENSE("GPL"); jtsylve-LiME-a1205cc/src/tcp.c000066400000000000000000000064711516063221300161260ustar00rootroot00000000000000/* * LiME - Linux Memory Extractor * Copyright (c) 2011-2026 Joe T. Sylve, Ph.D. * * Author: * Joe T. Sylve, Ph.D. - joe.sylve@gmail.com, @jtsylve * * SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "lime.h" static struct socket *control; static struct socket *accept; static int create_tcp_sock(struct socket **sock, int family) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) return sock_create_kern(&init_net, family, SOCK_STREAM, IPPROTO_TCP, sock); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,6) return sock_create_kern(family, SOCK_STREAM, IPPROTO_TCP, sock); #else return sock_create(family, SOCK_STREAM, IPPROTO_TCP, sock); #endif } int setup_tcp(void) { struct sockaddr_in saddr; int r; #if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) int opt = 1; #endif r = create_tcp_sock(&control, AF_INET); if (r < 0) { DBG("Error creating control socket"); return r; } memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_port = htons(port); if (localhostonly) { saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); } else { saddr.sin_addr.s_addr = htonl(INADDR_ANY); } #if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) r = kernel_setsockopt(control, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof (opt)); if (r < 0) { DBG("Error setting socket options"); return r; } #else sock_set_reuseaddr(control->sk); #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(6,19,0) r = kernel_bind(control,(struct sockaddr*) &saddr,sizeof(saddr)); #else r = kernel_bind(control,(struct sockaddr_unsized *) &saddr,sizeof(saddr)); #endif if (r < 0) { DBG("Error binding control socket"); return r; } r = kernel_listen(control,1); if (r) { DBG("Error listening on socket"); return r; } r = kernel_accept(control, &accept, 0); if (r < 0) { DBG("Error accepting socket"); return r; } return 0; } void cleanup_tcp(void) { if (accept) { kernel_sock_shutdown(accept, SHUT_RDWR); sock_release(accept); accept = NULL; } if (control) { kernel_sock_shutdown(control, SHUT_RDWR); sock_release(control); control = NULL; } } ssize_t write_vaddr_tcp(void * v, size_t is) { ssize_t s; struct kvec iov; struct msghdr msg; memset(&msg, 0, sizeof(msg)); iov.iov_base = v; iov.iov_len = is; s = kernel_sendmsg(accept, &msg, &iov, 1, is); return s; } jtsylve-LiME-a1205cc/test/000077500000000000000000000000001516063221300153545ustar00rootroot00000000000000jtsylve-LiME-a1205cc/test/Dockerfile000066400000000000000000000005351516063221300173510ustar00rootroot00000000000000FROM ubuntu:24.04 RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential bc flex bison libelf-dev libssl-dev dwarves \ sparse busybox-static cpio curl git python3 \ ca-certificates file \ qemu-system-x86 qemu-system-arm qemu-system-misc \ && rm -rf /var/lib/apt/lists/* WORKDIR /src jtsylve-LiME-a1205cc/test/build-initramfs.sh000077500000000000000000000021061516063221300210030ustar00rootroot00000000000000#!/bin/bash # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # build-initramfs.sh — Create a minimal initramfs for QEMU smoke testing. # Usage: ./test/build-initramfs.sh set -euo pipefail LIME_KO="${1:?Usage: $0 }" OUTPUT="${2:?Usage: $0 }" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" BUSYBOX=$(command -v busybox 2>/dev/null || echo /usr/bin/busybox) if [ ! -x "$BUSYBOX" ]; then echo "ERROR: busybox not found (install busybox-static)" >&2 exit 1 fi WORK=$(mktemp -d) trap "rm -rf $WORK" EXIT mkdir -p "$WORK"/{bin,dev,proc,sys,tmp,lib/modules} cp "$BUSYBOX" "$WORK/bin/busybox" for cmd in sh mount umount ls cat wc od awk tr grep insmod rmmod poweroff; do ln -s busybox "$WORK/bin/$cmd" done cp "$LIME_KO" "$WORK/lib/modules/lime.ko" cp "$SCRIPT_DIR/smoke-init" "$WORK/init" chmod +x "$WORK/init" (cd "$WORK" && find . | cpio -o -H newc --quiet) | gzip > "$OUTPUT" echo "Initramfs: $OUTPUT ($(wc -c < "$OUTPUT") bytes)" jtsylve-LiME-a1205cc/test/check-source.sh000077500000000000000000000066671516063221300203050ustar00rootroot00000000000000#!/bin/bash # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # check-source.sh — Static source checks for LiME. # Catches common mistakes that compile testing alone misses. # Runs on both macOS (dev) and Linux (CI) — avoids grep -P. set -euo pipefail SRC="$(cd "$(dirname "$0")/../src" && pwd)" ERRORS=0 WARNINGS=0 err() { ERRORS=$((ERRORS+1)); echo " ERROR: $1"; } warn() { WARNINGS=$((WARNINGS+1)); echo " WARN: $1"; } echo "=== LiME Source Checks ===" ## ## 1. Non-static functions in the transport/hash/deflate files must ## have matching extern declarations in lime.h. ## echo "--- Extern declarations ---" for f in "$SRC"/tcp.c "$SRC"/disk.c "$SRC"/hash.c "$SRC"/deflate.c; do [ -f "$f" ] || continue base=$(basename "$f") # Find function definitions at column 0 that aren't static or preprocessor grep -n '^[a-zA-Z]' "$f" | grep -v '^[0-9]*:static ' | grep -v '^[0-9]*:#' | grep '(' | while IFS=: read -r line content; do # Extract the word immediately before the first ( func=$(echo "$content" | sed 's/(.*//' | awk '{print $NF}' | tr -d '* ') [ -z "$func" ] && continue # Skip obvious non-functions case "$func" in if|while|for|switch|return|sizeof) continue ;; esac # Check lime.h if ! grep -q "extern.*${func} *(" "$SRC/lime.h"; then err "$base:$line: '$func' missing extern in lime.h" fi done done ## ## 2. resource_size_t in format strings must use %llx with cast ## (bare %lx truncates on 32-bit PAE; bare %llx is UB on 32-bit non-PAE) ## echo "--- Format string safety ---" if grep -n 'DBG.*%l[dux]' "$SRC"/*.c | grep -E '(p|res)->(start|end)'; then err "resource_size_t printed with %lx — use (unsigned long long) cast + %llx" fi if grep -n 'DBG.*%p.*(void' "$SRC"/*.c | grep -v '%pa'; then err "%p with (void*) cast — use %llx for physical addresses" fi ## ## 3. SPDX license headers ## echo "--- SPDX headers ---" for f in "$SRC"/*.c "$SRC"/*.h; do # Skip kbuild-generated files (e.g. lime.mod.c) case "$(basename "$f")" in *.mod.c) continue ;; esac if ! grep -q 'SPDX-License-Identifier' "$f"; then err "$(basename "$f"): missing SPDX header" fi done ## ## 4. Void pointer arithmetic (GNU extension, -Wpointer-arith) ## echo "--- Pointer arithmetic ---" if grep -n 'v +=' "$SRC"/*.c | grep -v '(u8 \*)' | grep -v '//'; then warn "void* arithmetic — prefer (u8 *) cast for portability" fi ## ## 5. Version guard consistency ## > KERNEL_VERSION is almost always a bug — should be >= ## echo "--- Version guards ---" if grep -n 'LINUX_VERSION_CODE *>' "$SRC"/*.c "$SRC"/*.h | grep -v '>='; then warn "> KERNEL_VERSION without = (should usually be >= for 'introduced in' checks)" fi ## ## 6. ERR_PTR hygiene in disk.c ## After a failed filp_open, f must be set to NULL so that cleanup_disk's ## if(f) check doesn't try to close an error pointer. ## echo "--- ERR_PTR cleanup ---" if grep -c 'f = NULL' "$SRC/disk.c" | grep -q '^[01]$'; then err "disk.c: expected at least 2 'f = NULL' sites (success + error paths in dio_write_test)" fi echo "" if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then echo "=== All checks passed ===" elif [ $ERRORS -eq 0 ]; then echo "=== $WARNINGS warning(s), no errors ===" else echo "=== $ERRORS error(s), $WARNINGS warning(s) ===" fi exit $ERRORS jtsylve-LiME-a1205cc/test/kernel-versions.conf000066400000000000000000000005231516063221300213510ustar00rootroot00000000000000# Pinned kernel versions for CI testing. # Update these when bumping to newer patch releases. # CI cache keys extract the per-series version directly from this file, # so bumping one version invalidates only that version's cache entries. 4.15=4.15.18 5.4=5.4.291 5.10=5.10.235 5.15=5.15.179 6.1=6.1.131 6.6=6.6.83 6.12=6.12.20 6.19=6.19.9 jtsylve-LiME-a1205cc/test/local.sh000077500000000000000000000153171516063221300170140ustar00rootroot00000000000000#!/bin/bash # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # local.sh — Run LiME CI tests locally in Docker. # # This script self-dispatches: on the host it launches Docker, inside # the container it runs the actual tests. One file, two modes. # # Usage: # ./test/local.sh build [kernel] [config] [builds] # ./test/local.sh analyze # ./test/local.sh smoke [kernel] # ./test/local.sh all # ./test/local.sh clean # ./test/local.sh shell # # Kernel trees are cached in a Docker volume and reused across runs. # First run per kernel: ~5 min. Subsequent runs: ~10 sec. set -euo pipefail # ========================================================================= # CONTAINER MODE — runs inside Docker # ========================================================================= if [ -n "${LIME_IN_DOCKER:-}" ]; then # Prepare a kernel tree, skipping if already cached. # Sets KDIR as a side effect. prepare_cached() { local kernel="$1" config="$2" local hash hash=$(cat /src/test/prepare-kernel.sh /src/test/kernel-versions.conf | sha256sum | cut -c1-12) KDIR="/cache/kernel-${kernel}-${config}-${hash}" if [ -d "$KDIR" ]; then echo "==> Cached: $KDIR" else echo "==> Preparing linux-${kernel} [${config}]..." LIME_KDIR="$KDIR" bash /src/test/prepare-kernel.sh "$kernel" "$config" fi } # Copy source to a writable directory (source is mounted read-only). setup_build() { rm -rf /tmp/build cp -r /src/src /tmp/build } # modules_prepare does not generate Module.symvers (requires full # kernel build). KBUILD_MODPOST_WARN=1 lets modpost warn instead # of error on unresolved symbols — the QEMU smoke tests verify # actual module loading. export KBUILD_MODPOST_WARN=1 cmd="${1:?}"; shift case "$cmd" in build) kernel="${1:-6.6}"; config="${2:-defconfig}"; builds="${3:-default}" prepare_cached "$kernel" "$config" setup_build cd /tmp/build for b in $builds; do echo "==> Build: $b" make clean 2>/dev/null || true case "$b" in default) make KDIR="$KDIR" ;; debug) make debug KDIR="$KDIR" ;; symbols) make symbols KDIR="$KDIR" ;; werror) KCFLAGS="-Werror" make KDIR="$KDIR" ;; esac file lime-*.ko | grep -q ELF echo " $b: OK ($(ls -lh lime-*.ko | awk '{print $5}'))" done echo "==> All builds passed" ;; analyze) prepare_cached 6.6 defconfig setup_build echo "==> Sparse" make -C "$KDIR" M=/tmp/build C=2 modules 2>&1 | tee /tmp/sparse.log if grep -E '(error|warning):' /tmp/sparse.log | grep -q 'build/'; then echo "Sparse issues:" grep -E '(error|warning):' /tmp/sparse.log | grep 'build/' exit 1 fi echo "==> Source checks" bash /src/test/check-source.sh ;; smoke) kernel="${1:-6.6}" prepare_cached "$kernel" qemu setup_build make -C /tmp/build KDIR="$KDIR" bash /src/test/qemu-smoke-test.sh "$KDIR" /tmp/build/lime-*.ko ;; *) echo "Unknown container command: $cmd"; exit 1 ;; esac exit 0 fi # ========================================================================= # HOST MODE — launches Docker # ========================================================================= IMAGE="lime-test" VOLUME="lime-kernel-cache" ROOT="$(cd "$(dirname "$0")/.." && pwd)" ensure_image() { if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then echo "==> Building Docker image (one-time)..." docker build -q -t "$IMAGE" "$ROOT/test" fi } ensure_volume() { docker volume inspect "$VOLUME" >/dev/null 2>&1 || docker volume create "$VOLUME" >/dev/null } # Launch this same script inside Docker. drun() { local kvm_flag="" [ -e /dev/kvm ] && kvm_flag="--device /dev/kvm" docker run --rm \ -v "$ROOT:/src:ro" \ -v "$VOLUME:/cache" \ -e LIME_IN_DOCKER=1 \ $kvm_flag \ "$IMAGE" bash /src/test/local.sh "$@" } case "${1:-help}" in build|analyze|smoke) ensure_image; ensure_volume drun "$@" ;; all) ensure_image; ensure_volume echo "=== Tier 1: Compile tests ===" for k in 4.15 5.4 5.10 6.1; do drun build "$k" done drun build 5.15 defconfig "default debug symbols werror" drun build 6.6 defconfig "default debug symbols werror" drun build 6.12 defconfig "default werror" drun build 6.19 defconfig "default werror" drun build 5.15 no-zlib drun build 6.6 no-zlib drun build 6.12 preempt-rt echo "" echo "=== Tier 2: Static analysis ===" drun analyze echo "" echo "=== Tier 3: Smoke tests ===" drun smoke 5.15 drun smoke 6.6 echo "" echo "=== All tests passed ===" ;; clean) echo "Removing cache volume and image..." docker volume rm "$VOLUME" 2>/dev/null || true docker rmi "$IMAGE" 2>/dev/null || true echo "Done." ;; shell) ensure_image; ensure_volume local kvm_flag="" [ -e /dev/kvm ] && kvm_flag="--device /dev/kvm" docker run --rm -it \ -v "$ROOT:/src:ro" \ -v "$VOLUME:/cache" \ -e LIME_IN_DOCKER=1 \ $kvm_flag \ "$IMAGE" bash ;; *) cat <<'EOF' Usage: ./test/local.sh [args...] Commands: build [kernel] [config] [builds] Compile test analyze Sparse + source checks smoke [kernel] QEMU runtime test all Full CI matrix clean Remove Docker image and cache shell Interactive shell in container Kernels: 4.15 5.4 5.10 5.15 6.1 6.6 6.12 6.19 Configs: defconfig no-zlib preempt-rt Builds: default debug symbols werror (space-separated in quotes) Examples: ./test/local.sh build Quick build against 6.6 ./test/local.sh build 5.15 defconfig "default debug symbols werror" ./test/local.sh smoke 6.6 QEMU runtime test ./test/local.sh all Full CI (~30 min first run, ~5 min cached) ./test/local.sh clean Free disk space EOF exit 1 ;; esac jtsylve-LiME-a1205cc/test/prepare-kernel.sh000077500000000000000000000134401516063221300206310ustar00rootroot00000000000000#!/bin/bash # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # prepare-kernel.sh - Download and prepare a kernel source tree for # out-of-tree module compilation testing. # # Usage: ./test/prepare-kernel.sh [config] # series - Kernel version series, e.g. "6.6" or "5.15" # config - "defconfig" (default), "no-zlib", "preempt-rt", or "qemu" # # Output: A prepared kernel tree at /tmp/linux-build/ # # The tree is stripped of source files after preparation to minimize cache # size (~100 MB vs ~1 GB). Only headers, scripts, and build infrastructure # are kept — everything needed for out-of-tree module compilation. set -euo pipefail SERIES="${1:?Usage: $0 [config]}" CONFIG="${2:-defconfig}" DEST="${LIME_KDIR:-/tmp/linux-build}" MAJOR="${SERIES%%.*}" ## ## Resolve kernel version. ## Pinned versions live in kernel-versions.conf (separate file so that ## edits to this script don't invalidate every cache entry). ## Falls back to dynamic resolution for unknown series (canary job). ## SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" resolve_version() { # Check the pin file first local pin pin=$(grep "^${SERIES}=" "$SCRIPT_DIR/kernel-versions.conf" 2>/dev/null | cut -d= -f2) if [ -n "$pin" ]; then echo "$pin" return fi # Dynamic resolution for canary / unknown series local ver ver=$(git ls-remote --tags \ "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git" | grep -oP "refs/tags/v\K${SERIES//./\\.}\.[0-9]+$" | sort -V | tail -1) || true echo "${ver:-$SERIES}" } FULL_VER=$(resolve_version) echo "==> linux-${FULL_VER} (series ${SERIES}, config ${CONFIG})" ## ## Download ## URL="https://cdn.kernel.org/pub/linux/kernel/v${MAJOR}.x/linux-${FULL_VER}.tar.xz" TARBALL="/tmp/linux-${FULL_VER}.tar.xz" echo "==> Downloading ${URL}..." curl -fL --retry 3 --progress-bar -o "$TARBALL" "$URL" echo "==> Extracting..." tar xf "$TARBALL" -C /tmp rm -f "$TARBALL" SRCDIR="/tmp/linux-${FULL_VER}" cd "$SRCDIR" ## ## Configure ## echo "==> Configuring..." make -s defconfig case "$CONFIG" in defconfig) ;; no-zlib) scripts/config --disable CONFIG_ZLIB_DEFLATE scripts/config --disable CONFIG_ZLIB_INFLATE ;; preempt-rt) scripts/config --enable CONFIG_PREEMPT_RT ;; qemu) # Console — enable for all supported archs (non-existent options # are silently ignored by scripts/config) scripts/config --enable CONFIG_SERIAL_8250 scripts/config --enable CONFIG_SERIAL_8250_CONSOLE scripts/config --enable CONFIG_SERIAL_AMBA_PL011 scripts/config --enable CONFIG_SERIAL_AMBA_PL011_CONSOLE # Common scripts/config --enable CONFIG_VIRTIO scripts/config --enable CONFIG_DEVTMPFS scripts/config --enable CONFIG_DEVTMPFS_MOUNT scripts/config --enable CONFIG_TMPFS scripts/config --enable CONFIG_BLK_DEV_INITRD scripts/config --enable CONFIG_RD_GZIP scripts/config --enable CONFIG_ZLIB_DEFLATE scripts/config --enable CONFIG_ZLIB_INFLATE ;; *) echo "ERROR: Unknown config '${CONFIG}'" >&2 exit 1 ;; esac # Options LiME needs scripts/config --enable CONFIG_MODULES scripts/config --enable CONFIG_CRYPTO scripts/config --enable CONFIG_CRYPTO_HASH scripts/config --enable CONFIG_CRYPTO_SHA256 scripts/config --enable CONFIG_INET scripts/config --enable CONFIG_NET scripts/config --disable CONFIG_GCC_PLUGINS make -s olddefconfig ## ## Build ## echo "==> modules_prepare ($(nproc) jobs)..." if ! make -j"$(nproc)" modules_prepare > /tmp/modules_prepare.log 2>&1; then echo "::error::modules_prepare failed:" cat /tmp/modules_prepare.log exit 1 fi tail -5 /tmp/modules_prepare.log if [ "$CONFIG" = "qemu" ]; then # Each arch has a different kernel image target case "$(uname -m)" in x86_64) KERNEL_TARGET=bzImage ;; aarch64) KERNEL_TARGET=Image ;; armv7l|armhf) KERNEL_TARGET=zImage ;; riscv64) KERNEL_TARGET=Image ;; *) KERNEL_TARGET=bzImage ;; esac echo "==> ${KERNEL_TARGET} ($(nproc) jobs — this takes a while on first run)..." if ! make -j"$(nproc)" "$KERNEL_TARGET" > /tmp/kernel_build.log 2>&1; then echo "::error::kernel build failed:" cat /tmp/kernel_build.log exit 1 fi tail -5 /tmp/kernel_build.log fi ## ## Strip the source tree to minimize cache size. ## Keep only what out-of-tree module compilation needs: ## include/, arch/*/include/, scripts/, Makefiles, .config, generated headers. ## For qemu config, also keep the kernel image (bzImage/Image/zImage). ## echo "==> Stripping tree for caching..." # Remove large directories that are never needed for module builds rm -rf Documentation samples firmware sound usr certs virt \ drivers fs mm net block crypto ipc security lib init kernel # Clean tools/ but keep objtool (needed by kbuild for module linking) if [ -d tools/objtool ]; then find tools -mindepth 1 -maxdepth 1 -not -name objtool \ -exec rm -rf {} + 2>/dev/null || true else rm -rf tools fi # Remove source files (keep headers, makefiles, build scripts, linker scripts) find . -type f \( -name "*.c" -o -name "*.S" \) \ -not -path "./scripts/*" -delete 2>/dev/null || true # Remove object files from the kernel build (keep scripts/*.o — host tools) find . -path ./scripts -prune -o -name "*.o" -type f -print | xargs rm -f 2>/dev/null || true TREE_SIZE=$(du -sh . | cut -f1) echo "==> Trimmed tree: ${TREE_SIZE}" ## ## Move to destination ## rm -rf "$DEST" mv "$SRCDIR" "$DEST" KREL=$(make -s -C "$DEST" kernelrelease 2>/dev/null || echo "$FULL_VER") echo "==> Ready: ${DEST} (${KREL}, ${CONFIG}, ${TREE_SIZE})" jtsylve-LiME-a1205cc/test/qemu-smoke-test.sh000077500000000000000000000047501516063221300207610ustar00rootroot00000000000000#!/bin/bash # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # qemu-smoke-test.sh — Boot a kernel in QEMU and run LiME smoke tests. # Supports x86_64, aarch64, arm, and riscv64. # # Usage: ./test/qemu-smoke-test.sh set -euo pipefail KDIR="${1:?Usage: $0 }" LIME_KO="${2:?Usage: $0 }" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Architecture-specific QEMU configuration case "$(uname -m)" in x86_64) QEMU_BIN=qemu-system-x86_64 QEMU_MACHINE="-cpu max" KERNEL_IMAGE="$KDIR/arch/x86/boot/bzImage" CONSOLE=ttyS0 ;; aarch64) QEMU_BIN=qemu-system-aarch64 QEMU_MACHINE="-M virt -cpu max" KERNEL_IMAGE="$KDIR/arch/arm64/boot/Image" CONSOLE=ttyAMA0 ;; armv7l|armhf) QEMU_BIN=qemu-system-arm QEMU_MACHINE="-M virt" KERNEL_IMAGE="$KDIR/arch/arm/boot/zImage" CONSOLE=ttyAMA0 ;; riscv64) QEMU_BIN=qemu-system-riscv64 QEMU_MACHINE="-M virt -bios none" KERNEL_IMAGE="$KDIR/arch/riscv/boot/Image" CONSOLE=ttyS0 ;; *) echo "ERROR: Unsupported architecture $(uname -m)" >&2 exit 1 ;; esac if [ ! -f "$KERNEL_IMAGE" ]; then echo "ERROR: $KERNEL_IMAGE not found" >&2 exit 1 fi if ! command -v "$QEMU_BIN" >/dev/null 2>&1; then echo "ERROR: $QEMU_BIN not found (install the appropriate qemu-system package)" >&2 exit 1 fi INITRAMFS=$(mktemp --suffix=.cpio.gz) LOG=$(mktemp) trap "rm -f $INITRAMFS $LOG" EXIT bash "$SCRIPT_DIR/build-initramfs.sh" "$LIME_KO" "$INITRAMFS" echo "==> Booting QEMU ($(uname -m))..." echo " Binary: $QEMU_BIN" echo " Kernel: $KERNEL_IMAGE" echo " Console: $CONSOLE" echo "" timeout 180 $QEMU_BIN \ $QEMU_MACHINE \ -kernel "$KERNEL_IMAGE" \ -initrd "$INITRAMFS" \ -append "console=$CONSOLE panic=-1 quiet loglevel=4" \ -nographic \ -no-reboot \ -m 256M \ -smp 2 \ > "$LOG" 2>&1 || true # Show the test output (skip kernel boot messages) sed -n '/=== LiME Smoke Test ===/,/=== TEST_COMPLETE ===/p' "$LOG" if grep -q "SMOKE_TEST_RESULT=PASS" "$LOG"; then echo "" echo "==> Smoke test PASSED" exit 0 elif grep -q "TEST_COMPLETE" "$LOG"; then echo "" echo "==> Smoke test FAILED" exit 1 else echo "" echo "==> VM did not complete — full log:" tail -40 "$LOG" exit 2 fi jtsylve-LiME-a1205cc/test/smoke-init000077500000000000000000000073541516063221300173720ustar00rootroot00000000000000#!/bin/sh # SPDX-FileCopyrightText: 2011-2026 Joe T. Sylve, Ph.D. # SPDX-License-Identifier: GPL-2.0-only # smoke-init — Init script for LiME QEMU smoke tests. # Runs inside a minimal VM, exercises all output formats, digest, # and compression, then reports results via serial console. mount -t proc proc /proc mount -t sysfs sys /sys mount -t devtmpfs dev /dev mount -t tmpfs tmp /tmp PASS=0 FAIL=0 SKIP=0 pass() { PASS=$((PASS+1)); echo " PASS: $1"; } fail() { FAIL=$((FAIL+1)); echo " FAIL: $1"; } skip() { SKIP=$((SKIP+1)); echo " SKIP: $1"; } echo "=== LiME Smoke Test ===" echo "Kernel: $(uname -r)" echo "RAM: $(awk '/MemTotal/{print $2}' /proc/meminfo) kB" # Helper — load LiME, check output, record size, unload, then delete # the output to free tmpfs space (the VM has limited RAM). # Sets LAST_SIZE on success. LAST_SIZE=0 run_lime() { local tag="$1"; shift local out="/tmp/${tag}" echo "--- $tag ---" # Free tmpfs space from previous test (VM has limited RAM) rm -f /tmp/t[0-9]* 2>/dev/null insmod /lib/modules/lime.ko "path=${out}" "$@" 2>&1 local r=$? rmmod lime 2>&1 || true if [ $r -ne 0 ]; then fail "$tag: insmod returned $r" LAST_SIZE=0 return 1 fi if [ ! -s "$out" ]; then fail "$tag: output empty or missing" LAST_SIZE=0 return 1 fi LAST_SIZE=$(wc -c < "$out") pass "$tag: $LAST_SIZE bytes" return 0 } ## ## Test 1 — LIME format: verify magic bytes ## run_lime "t1" "format=lime" if [ $? -eq 0 ]; then MAGIC=$(od -A n -t x1 -N 4 /tmp/t1 | tr -d ' ') if [ "$MAGIC" = "454d694c" ]; then pass "lime magic 0x4C694D45" else fail "lime magic: expected 454d694c, got $MAGIC" fi fi ## ## Test 2 — RAW format: remember size for compression comparison ## run_lime "t2" "format=raw" RAW_SIZE=$LAST_SIZE ## ## Test 3 — PADDED format: output should be >= total RAM ## run_lime "t3" "format=padded" if [ $? -eq 0 ]; then # Padded output should be at least as large as raw (it adds zero-fill # for gaps). On VMs where System RAM starts at a high physical address, # the gap padding may exceed tmpfs capacity — so we only assert >= raw, # not >= total physical memory. if [ "$LAST_SIZE" -ge "$RAW_SIZE" ]; then pass "padded size >= raw ($LAST_SIZE >= $RAW_SIZE)" else fail "padded size < raw ($LAST_SIZE < $RAW_SIZE)" fi fi ## ## Test 4 — Digest: SHA-256 sidecar file should be created ## run_lime "t4" "format=lime" "digest=sha256" if [ -s /tmp/t4.sha256 ]; then DIGEST=$(cat /tmp/t4.sha256) LEN=$(echo -n "$DIGEST" | wc -c) if [ "$LEN" -eq 64 ]; then pass "sha256 sidecar: $DIGEST" else fail "sha256 sidecar wrong length ($LEN, expected 64)" fi else # Sidecar missing means the kernel's crypto subsystem didn't have # sha256 available (common in minimal/embedded kernels). The dump # itself still succeeds — digest is best-effort. skip "sha256 (algorithm not available in this kernel)" fi ## ## Test 5 — Compression: output should be smaller than raw ## if [ "$RAW_SIZE" -gt 0 ]; then run_lime "t5" "format=lime" "compress=1" if [ $? -eq 0 ]; then if [ "$LAST_SIZE" -lt "$RAW_SIZE" ]; then pass "compressed $LAST_SIZE < raw $RAW_SIZE" else fail "compressed not smaller ($LAST_SIZE >= $RAW_SIZE)" fi else skip "compression (not available)" fi else skip "compression (raw test failed, no baseline)" fi ## ## Results ## echo "" echo "=== Results: $PASS passed, $FAIL failed, $SKIP skipped ===" if [ $FAIL -eq 0 ]; then echo "SMOKE_TEST_RESULT=PASS" else echo "SMOKE_TEST_RESULT=FAIL" fi echo "=== TEST_COMPLETE ===" exec poweroff -f