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

interp: bash runs scripts if kernel returns ENOEXEC #1065

Open
hugelgupf opened this issue Mar 4, 2024 · 1 comment
Open

interp: bash runs scripts if kernel returns ENOEXEC #1065

hugelgupf opened this issue Mar 4, 2024 · 1 comment

Comments

@hugelgupf
Copy link

make a file like such, named foo:

echo "bar"
$ chmod +x foo
$ bash -c "./foo"
hi

when I run this with strace -f bash -c ./foo I see that

execve("./testdata/foo", ["./testdata/foo"], 0x56158959fca0 /* 48 vars */) = -1 ENOEXEC (Exec format error)
...            
openat(AT_FDCWD, "./testdata/foo", O_RDONLY) = 3                                                                                                  
newfstatat(AT_FDCWD, "./testdata/foo", {st_mode=S_IFREG|0750, st_size=11, ...}, 0) = 0                                                            
read(3, "echo \"bar\"\n", 80)           = 11                                                                                                      
lseek(3, 0, SEEK_SET)                   = 0                                                                                                       
dup2(3, 255)                            = 255                                                                                                     
close(3)                                = 0                                                                                                       
read(255, "echo \"bar\"\n", 11)         = 11                                                                                                      
write(1, "bar\n", 4)                    = 4                                    

Looks to me like bash will try to execute as a script files with execute permission that get ENOEXEC from the kernel.

This looks like something that could be implemented as an ExecHandlerFunc.

@mvdan
Copy link
Owner

mvdan commented Mar 4, 2024

Makes sense, or we could just do this by default as part of the default exec handler. Happy to review a patch.

hugelgupf added a commit to hugelgupf/u-root that referenced this issue Mar 4, 2024
Not a good way to figure out how to run something.
Filed mvdan/sh#1065 instead.

Signed-off-by: Chris Koch <[email protected]>
hugelgupf added a commit to hugelgupf/u-root that referenced this issue Mar 4, 2024
Not a good way to figure out how to run something.
Filed mvdan/sh#1065 instead.

Signed-off-by: Chris Koch <[email protected]>
hugelgupf added a commit to hugelgupf/u-root that referenced this issue Mar 4, 2024
Not a good way to figure out how to run something.
Filed mvdan/sh#1065 instead.

Signed-off-by: Chris Koch <[email protected]>
hugelgupf added a commit to u-root/u-root that referenced this issue Mar 4, 2024
Not a good way to figure out how to run something.
Filed mvdan/sh#1065 instead.

Signed-off-by: Chris Koch <[email protected]>
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

No branches or pull requests

2 participants