Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist 1.2.0 compiled against luajit 2.0.5 crashes on incorrect config #6035

Closed
RvdE opened this issue Dec 1, 2017 · 4 comments
Closed

Comments

@RvdE
Copy link
Contributor

RvdE commented Dec 1, 2017

  • Program: dnsdist
  • Issue type: Bug report

Short description

On creating my initial config for dnsdist I copy/pasted a snippet from https://doc.powerdns.com/authoritative/guides/recursion.html. Unfortunately the syntax for the newServer lines is missing 'address=', which causes an error (Fatal Lua error: invalid key to 'next') when compiled against Lua (tested with 5.2 and 5.3), but causes a segfault with LuaJIT.

Environment

  • Operating system: FreeBSD 11.1-RELEASE-p5
  • Software version: 1.2.0
  • Software source: port + local changes to build/link against luajit

Steps to reproduce

  1. Build and install dnsdist linked against luajit
  2. Use a config that contains an error like described above
  3. Start dnsdist

Expected behaviour

I would expect the same error to show as when compiled against Lua

Actual behaviour

[(Fri Dec 01 16:00) root@lan /tmp]# gdb --args dnsdist -C dnsdist.conf
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) go
Undefined command: "go".  Try "help".
(gdb) run
Starting program: /tmp/dnsdist -C dnsdist.conf

Program received signal SIGSEGV, Segmentation fault.
check_action_record (context=0x7fffffffdaa8, lsda=0x7fffffffd7a0, action_record=0x72f2c3 "", ex=<value optimized out>, selector=0x7fffffffd7d8, adjustedPtr=@0x80302d158)
    at /usr/src/contrib/libcxxrt/exception.cc:935
935             bool is_ptr = ex ? ex_type->__is_pointer_p() : false;
(gdb) bt
#0  check_action_record (context=0x7fffffffdaa8, lsda=0x7fffffffd7a0, action_record=0x72f2c3 "", ex=<value optimized out>, selector=0x7fffffffd7d8, adjustedPtr=@0x80302d158)
    at /usr/src/contrib/libcxxrt/exception.cc:935
#1  0x00000008021b8fdc in __gxx_personality_v0 (version=<value optimized out>, actions=<value optimized out>, exceptionClass=<value optimized out>, exceptionObject=<value optimized out>, context=0x7fffffffdaa8)
    at /usr/src/contrib/libcxxrt/exception.cc:1144
#2  0x00000008025f1d47 in _Unwind_RaiseException (exc=0x80302d160) at unwind.inc:117
#3  0x00000008021b89ef in __cxa_rethrow_primary_exception (thrown_exception=<value optimized out>) at /usr/src/contrib/libcxxrt/exception.cc:774
#4  0x0000000801f2c99c in std::rethrow_exception (p=<value optimized out>) at /usr/src/contrib/libc++/src/exception.cpp:318
#5  0x000000000043d0e4 in LuaContext::callRaw (state=0x1378, functionAndArguments=<value optimized out>, outArguments=0) at LuaContext.hpp:1360
#6  0x000000000051f871 in _ZN10LuaContext4callINSt3__15tupleIJEEEJEEET_P9lua_StateNS_12PushedObjectEDpOT0_ (state=0x1378, toCall=<value optimized out>) at LuaContext.hpp:1328
#7  0x000000000051e44a in LuaContext::executeCode (this=0x9bbac8, code=<value optimized out>) at LuaContext.hpp:232
#8  0x0000000000479cb3 in setupLua (client=Unhandled dwarf expression opcode 0x9d
) at dnsdist-lua.cc:1815
#9  0x0000000000423913 in main (argc=<value optimized out>, argv=<value optimized out>) at dnsdist.cc:1936

Other information

Usecase

Description

@Habbie Habbie added this to the dnsdist-1.2.x milestone Dec 5, 2017
@RvdE
Copy link
Contributor Author

RvdE commented Dec 6, 2017

I've tested some more and luajit seems to be the badboy here, since
compiling dnsdist with LLVM 5.0 didn't help and still makes it crash (I found a PR about LLVM doing incorrect unwinds causing luajit to segfault, but the example to reproduce doesn't crash, so that wasn't the culprit).

Also, compiling against Lua 5.1, 5.2 and 5.3 all work fine.

Also noticed dnsdist+luajit crashes when using the console to add an incorrect newServer line. When compiled against Lua (5.1+) it displays a nice error (Error: Parsing function parameters, did you forget parameter name?>).

So it seems LuaWrapper + LuaJIT is unable to process exceptions very well, which might also cause trouble for auth and rec, but I haven't ran into that yet nor received any reports from users.

@RvdE
Copy link
Contributor Author

RvdE commented Dec 7, 2017

I can reproduce the crash on FreeBSD 12.0-CURRENT (which comes with LLVM 5.0, newer libc and libc++). So that unfortunately didn't fix it. ;(

@RvdE
Copy link
Contributor Author

RvdE commented Dec 8, 2017

The patch from ahupowerdns/luawrapper#38 fixes the segfault, although it does report a different error message than standard Lua does, namely:

Fatal Lua error: Exception thrown by a callback function called by Lua
Details: boost::bad_get: failed value get using boost::get

It also no longer crashes when you add the same incorrect newServer command on the console.

@rgacogne rgacogne modified the milestones: dnsdist-1.2.x, dnsdist-1.3.x Jul 16, 2018
@rgacogne rgacogne modified the milestones: dnsdist-1.3.x, dnsdist-1.4.x Aug 9, 2019
@rgacogne
Copy link
Member

rgacogne commented Mar 5, 2020

Closing this since it doesn't seem to crash anymore. We also refactored our exception handling since the last update so it might be fix in recent versions, I will re-open if a new report comes in.

@rgacogne rgacogne closed this as completed Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants