jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.43k stars 637 forks source link

(possible) bug: pledging (v1.9) non-cosmo '/usr/bin/ls' (9.5) on linux displays permission errors and lists files #1314

Open davidhaley opened 1 month ago

davidhaley commented 1 month ago

What happened?

Hello,

This may or may not be a bug, depending on whether or not pledging non-cosmopolitan binaries (i.e. /usr/bin/ls) is supported. The cosmopolitan ls works as expected.


I was testing out pledge with ls and I noticed the following.

./pledge -v r:$HOME/Downloads/bin -p 'stdio rpath' ls -lah displays permission errors and lists files.

./pledge -k -v r:$HOME/Downloads/bin -p 'stdio rpath' ls -lah fails with a 'Bad system call' (-k flag) (it kills on EPERM, which makes sense)

The permissions in the directory are r-x, and contain the cosmopolitan binaries. The output of both commands with --ftrace look identical (other than additional output including the permission errors and list of files)


Additional info:

The coredump with -k shows:

Program terminated with signal SIGSYS, Bad system call.
#0  ... in tcgetattr () from /usr/lib/libc.so.6

Adding tty to the pledge list, and rerunning, produces a coredump with:

Program terminated with signal SIGSYS, Bad system call.
#0  ... in listxattr () from /usr/lib/libc.so.6

Finally, adding fattr to the pledge list still produces the bad system call error when listxattr is called.


Version

Cosompolitan Pledge v1.9

/usr/bin/ls --version ls (GNU coreutils) 9.5

What operating system are you seeing the problem on?

Linux

Relevant log output

https://gist.github.com/davidhaley/c48cb5fbf6967305ad82eec343bbc506