Skip to content

Conversation

@ligurio
Copy link
Contributor

@ligurio ligurio commented Sep 4, 2025

The patch enables using luzer for fuzzing Lua projects in OSS-Fuzz.

Usage:

sudo python infra/helper.py build_fuzzers lua-example
sudo python infra/helper.py check_build lua-example fuzz_basic
sudo python infra/helper.py run_fuzzer lua-example fuzz_basic

Closes #13782
Depends on ligurio/luzer#74

@github-actions
Copy link

github-actions bot commented Sep 4, 2025

ligurio is integrating a new project:
- Main repo: https://github.com/ligurio/luzer
- Criticality score: 0.23250

@ligurio ligurio force-pushed the ligurio/gh-13782-enable-support-lua-luzer branch from bc8fb48 to e62118b Compare October 10, 2025 11:59
@ligurio
Copy link
Contributor Author

ligurio commented Dec 16, 2025

@jonathanmetzman could you please review?

@jonathanmetzman
Copy link
Contributor

I can take a look at this but to be honest we're concerned about the maintenance burden supporting Lua will impose and somewhat doubtful of the impact. Could you maybe help us with the latter? Is the electrical grid, or something else very important running on Lua?

@ligurio
Copy link
Contributor Author

ligurio commented Dec 17, 2025

I can take a look at this but to be honest we're concerned about the maintenance burden supporting Lua will impose and somewhat doubtful of the impact.

Yeah, I remember this concern and took it into account when developing the patch. Hence, I avoid introducing the support for yet another language toolchain. Instead, my patch adds a wrapper generator for Lua tests and modifies the code to run these wrappers. The runtime itself will be compiled by the project. The patch with implementation is about 70 LOC, other changes is an example and documentation. I also want to say that I want to make this contribution on my own behalf, not on behalf of any company, so I'll be here; I won't run away immediately after the merge :)

Could you maybe help us with the latter?

There are two main scenarios for using Lua:

  • First one is projects, where Lua is used as a standalone programming language. In this scenario, of course, you'd also want to test applications using fuzzing, but I agree with you, the impact is doubtful. Moreover, there are not so much projects written in Lua (but they exist: Kong API Gateway 1, Prosody IM 2, etc.).
  • The second one scenario is projects, where Lua is embedded into C/C++ applications with C extensions, and I'm most concerned about this one, because there's a high risk of presence of the issues specific for C/C++. Testing Lua's API with LibFuzzer/AFL isn't very practical, so I suggest integrating a specialized fuzzing engine for Lua API. Like you did with Atheris, that supports fuzzing of native extensions written for CPython.

Is the electrical grid, or something else very important running on Lua?

Physicists at CERN use LuaJIT (the Just-In-Time compiler) for computing physics accelerator beams 34.

Network infrastructure (applications and known Lua-related CVE's):

  • Cloudflare uses Lua for programming LuaJIT-based WAF, latest outage was happen due to untested the second branch in a Lua condition 56
  • PowerDNS, CVE-2019-3806 78
  • OpenResty (web platform based on NGINX and LuaJIT): CVE-2024-33452, CVE-2024-39702, CVE-2024-25178, CVE-2020-36309, CVE-2020-11724, CVE-2022-24834
  • Redis: CVE-2025-49844 (RCE) 9, CVE-2025-46817 (RCE), CVE-2025-46818 (privilege escalation)
  • HAProxy (HAProxy is used by a number of high-profile websites including GoDaddy, GitHub, Bitbucket, Stack Overflow, Reddit, Slack, Speedtest.net, Tumblr, Twitter and Tuenti and is used in the OpsWorks product from Amazon Web Services.)
  • VoIP: FreeSWITCH and Asterisk 10
  • Snort (IDS/IPS): CVE-2013-4863 / CVE-2016-6255, CVE-2024-20359, CVE-2023-20198
  • Suricata (IDS/IPS): CVE-2025-64344 11
  • Cisco (Cisco IOS SSL VPN 12): CVE-2025-41688
  • NetBSD embedded Lua into the kernel (lua.4 13, Scriptable Operating Systems with Lua 14)

Industrial cases:

  • Volvo (Volvo cars like the V40 Cross Country embed Lua in their combined instrument panel)
  • Fairino Robots 15, 16
  • Automation using NodeMCU (This open-source hardware platform allows users to run Lua directly on the ESP8266 Wi-Fi chip.)
  • Schneider Electric (SpaceLogic Room Controllers) 17, 18
  • Samsung SmartThings 19

Footnotes

  1. https://github.com/Kong/kong

  2. https://github.com/bjc/prosody/tree/master

  3. https://indico.cern.ch/event/487416/contributions/2174904/

  4. https://videos.cern.ch/record/3016478

  5. https://blog.cloudflare.com/5-december-2025-outage/

  6. https://blog.cloudflare.com/tag/lua/

  7. https://docs.powerdns.com/recursor/security-advisories/powerdns-advisory-2019-01.html

  8. https://doc.powerdns.com/recursor/lua-scripting/index.html

  9. https://redis.io/blog/security-advisory-cve-2025-49844/

  10. https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Databases/Lua-FreeSWITCH-Dbh_3965358/

  11. https://github.com/OISF/suricata/security/advisories/GHSA-93fh-cgmc-w3rx

  12. https://www.cisco.com/c/en/us/support/docs/security/ios-ssl-vpn/224470-configure-lua-script-for-dap.html

  13. https://man.netbsd.org/lua.4

  14. https://netbsd.org/~lneto/dls14.pdf

  15. https://www.fairino.be/tips/hands-on-with-lua-programming-fairino-cobots-made-simple

  16. https://fairino-doc-en.readthedocs.io/latest/LuaProgram/lua_intro.html

  17. https://www.se.com/uk/en/download/document/AN046/

  18. https://www.se.com/ca/en/download/document/028-6163/

  19. https://developer.smartthings.com/docs/devices/hub-connected/first-lua-driver

@@ -0,0 +1,36 @@
#!/bin/bash -eu
# Copyright 2023-2025 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Just do 2025

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed:

--- a/projects/lua-example/build.sh
+++ b/projects/lua-example/build.sh
@@ -1,5 +1,5 @@
 #!/bin/bash -eu
-# Copyright 2023-2025 Google LLC
+# Copyright 2025 Google LLC
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.

@@ -0,0 +1,23 @@
local luzer = require("luzer")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a license header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed:

--- a/projects/lua-example/example_basic.lua
+++ b/projects/lua-example/example_basic.lua
@@ -1,3 +1,19 @@
+-- Copyright 2023-2025 Google LLC
+
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the
+-- License.
+-- You may obtain a copy of the License at
+
+--      http://www.apache.org/licenses/LICENSE-2.0
+
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+-- either express or implied.
+-- See the License for the specific language governing permissions
+-- and limitations under the License.
+
 local luzer = require("luzer")
 
 local function TestOneInput(buf)

@ligurio ligurio force-pushed the ligurio/gh-13782-enable-support-lua-luzer branch from e62118b to 27cbbac Compare December 19, 2025 12:45
# luarocks install --tree=lua_modules --server=https://luarocks.org/dev luzer
# XXX: A custom rockspec is used because custom branch is required,
# see https://github.com/ligurio/luzer/issues/63.
export OSS_FUZZ=1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanmetzman The OSS Fuzz environment has some differences 1 in comparison to usual Linux environment (for example, a name of sanitizers libraries and libclang_rt.fuzzer_no_main). What is a proper way to detect OSS Fuzz environment? There is no env like OSS_FUZZ among other env variables 2.

Footnotes

  1. https://github.com/ligurio/luzer/pull/74

  2. https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/README.md#provided-environment-variables

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to add one to base-images/base

@@ -0,0 +1,37 @@
#!/bin/bash -eu
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanmetzman this file will be used in every project for building wrappers for Lua tests. Where should we place it: in infra/base-images/base-builder/ (with other compile_*_fuzzer scripts), or in the project dirs (there will be some code duplication)?

@jonathanmetzman
Copy link
Contributor

I'm going to double check that others internally don't think this is a bad idea before proceeding.

@@ -0,0 +1,39 @@
-- Copyright 2023-2025 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 2025 for copyright.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed:

--- a/projects/lua-example/example_basic.lua
+++ b/projects/lua-example/example_basic.lua
@@ -1,12 +1,12 @@
--- Copyright 2023-2025 Google LLC
+-- Copyright 2025 Google LLC
 
 -- Licensed under the Apache License, Version 2.0 (the "License");
 -- you may not use this file except in compliance with the
 -- License.

@ligurio ligurio force-pushed the ligurio/gh-13782-enable-support-lua-luzer branch from 27cbbac to 57847c8 Compare December 19, 2025 15:55
ligurio added a commit to ligurio/oss-fuzz that referenced this pull request Dec 23, 2025
cd infra/base-images/base-runner/
sudo docker build -f ubuntu-24-04.Dockerfile -t gcr.io/oss-fuzz-base/base-runner:ubuntu-24-04 .

sudo python infra/helper.py build_fuzzers tarantool
sudo python infra/helper.py check_build tarantool decimal_new_test
sudo python infra/helper.py run_fuzzer tarantool decimal_new_test

/tmp/not-out/tmpl_6fepn3/tarantool: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or directory

Depends on google#13929
Depends on ligurio/luzer#74
jonathanmetzman added a commit to google/clusterfuzz that referenced this pull request Dec 23, 2025
This adds luarocks to the apt-get install list in:
- docker/oss-fuzz/base/Dockerfile
- docker/oss-fuzz/base/ubuntu-20-04.Dockerfile
- docker/oss-fuzz/base/ubuntu-24-04.Dockerfile

Unblocks: google/oss-fuzz#13929
@jonathanmetzman
Copy link
Contributor

/gcbrun trial_build.py lua

ligurio added a commit to ligurio/oss-fuzz that referenced this pull request Dec 24, 2025
cd infra/base-images/base-runner/
sudo docker build -f ubuntu-24-04.Dockerfile -t gcr.io/oss-fuzz-base/base-runner:ubuntu-24-04 .

sudo python infra/helper.py build_fuzzers tarantool
sudo python infra/helper.py check_build tarantool decimal_new_test
sudo python infra/helper.py run_fuzzer tarantool decimal_new_test

/tmp/not-out/tmpl_6fepn3/tarantool: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or directory

Depends on google#13929
Depends on ligurio/luzer#74
The patch enables using luzer for fuzzing Lua projects in OSS-Fuzz.

sudo docker build infra/base-images/base-runner
sudo docker tag 12a7301c37b0 gcr.io/oss-fuzz-base/base-runner:latest

cd infra/base-images/base-runner/
sudo docker build -f ubuntu-24-04.Dockerfile -t gcr.io/oss-fuzz-base/base-runner:ubuntu-24-04 .

Usage:

sudo python infra/helper.py build_fuzzers lua-example
sudo python infra/helper.py check_build lua-example fuzz_basic
sudo python infra/helper.py run_fuzzer lua-example fuzz_basic

TODO

- Fix compile_lua_fuzzer-related text in documentation
- Move projects/lua-example/compile_lua_fuzzer to infra?
- Describe using luzer for testing builtin Lua C modules

Closes google#13782
@ligurio ligurio force-pushed the ligurio/gh-13782-enable-support-lua-luzer branch from 57847c8 to 32f9e6e Compare December 25, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Introducing Lua support to OSS-Fuzz via luzer

2 participants