jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.36k stars 630 forks source link

access("/zip/") crashes in libc #1098

Open sleirsgoevy opened 9 months ago

sleirsgoevy commented 9 months ago

To reproduce, run unix.access("/zip/", unix.R_OK) in the Redbean REPL.

I'm using the latest Redbean binary from the official website, the crash log is as follows:

error: Uncaught SIGSEGV (SEGV_MAPERR) on sergey128 pid 29630 tid 29630
  ./redbean-2.2.elf
  EUNKNOWN/0/No error information
  Linux #1-NixOS SMP PREEMPT_DYNAMIC Wed Dec 13 17:39:30 UTC 2023 sergey128 6.1.68

RAX 0000100080200000 RBX 0000000000650a50 RDI 0000100080200000 ST(0) 0.0
RCX 0000000000000008 RDX 0000000000650a50 RSI 000070000003f950 ST(1) 0.0
RBP 000070000003f900 RSP 000070000003f900 RIP 000000000059534a ST(2) 0.0
 R8 00000000ffffffff  R9 0000000000000000 R10 000010008008ecd8 ST(3) 0.0
R11 0000000001030045 R12 0000000000000004 R13 000070000003f950 ST(4) 0.0
R14 0000000000000000 R15 0000000000000004

XMM0  ffffff0000000000ffffffffffffffff XMM8  00000001c6e415960000000154442bd4
XMM1  000000008000000000000000004df230 XMM9  7558677a4529087f7480dfde3c5b6903
XMM2  000000000000000000000000005ae9e0 XMM10 ffffffffffffffff0b0a090803020100
XMM3  00000000000000000000000000000000 XMM11 8c0b08a3afe19c070000000000000000
XMM4  000000000000000000001000800aca40 XMM12 0b0a090803020100ffffffffffffffff
XMM5  00000000000000000000000000000000 XMM13 0c0d0e0f08090a0b0405060700010203
XMM6  0054524f505055534f4e4f544f525045 XMM14 79afc85033df8c9f4ec2ed807ed2f90a
XMM7  00001000800acaf000001000800acab0 XMM15 a044474e213e9121a3859fd573a58f4d

10008007f120 59534a GetZipCfileMode+9
70000003f900 56184b __zipos_access+91
70000003f930 5862ee faccessat+126
70000003f990 4f4876 LuaUnixAccess+118
70000003f9d0 4d24a5 luaD_precall+405
70000003fa30 4ec649 luaV_execute+1289
70000003fb00 4d263b ccall+75
70000003fb30 4d2763 luaD_callnoyield+19
70000003fb40 4cb584 f_call+20
70000003fb50 4d1834 luaD_rawrunprotected+84
70000003fbd0 4d2a38 luaD_pcall+56
70000003fc20 4ccd3c lua_pcallk+108
70000003fc60 4dfdc4 lua_runchunk+148
70000003fcf0 4216ef HandleReadline+191
70000003fd10 42c905 EventLoop+1925
70000003fe20 42fd52 RedBean+6802
70000003ffc0 402acd main+45
70000003ffe0 4030c9 cosmo+77
7ffc5afb3790 402504 _start+130

10008004-10008008 rw-pa-  5x automap 320kB
10008009-10008009 rw-sa-  1x automap 64kB
1000800a-10008011 rw-pa-  8x automap 512kB w/ 128kB hole
10008014-10008017 rw-pa-  4x automap 256kB w/ 2496kB hole
1000803f-10008043 r--s--  5x automap 282kB w/ 1792kB hole
10008060-10008083 r--p-- 36x automap 2266kB w/ 96tB hole
6fc00004-6fc00014 rw-paF 17x kmalloc 1088kB w/ 64gB hole
6fd00004-6fd00004 rw-paF  1x zipos 64kB w/ 64gB hole
6fe00004-6fe00004 rw-paF  1x g_fds 64kB
70000000-70000003 rw-Sa-  4x stack 256kB
# 5248kB total mapped memory
./redbean-2.2.elf
xet7 commented 8 months ago

@sleirsgoevy

With Redbean nightly, I'm able to run SQL from /zip/. Does it help?

https://cosmo.zip/pub/cosmos/bin/redbean

https://github.com/wekan/wekanstudio/blob/main/Makefile#L24

https://github.com/wekan/wekanstudio/blob/main/srv/.lua/wekan.lua#L258

mrdomino commented 6 months ago

Interesting, https://redbean.dev/redbean-latest.com behaves as you describe, but if I do make MODE=x86_64 o/x86_64/tool/net/redbean, calling that function on the resultant binary returns true.

@jart is the build on redbean.dev out of date or something by any chance?

pkulchenko commented 6 months ago

I wonder if this could have been fixed in 9ff65cff...