casaroli opened a new pull request, #21454: URL: https://github.com/apache/nuttx/pull/21454
## Summary `load_absmodule()` returned the error of the last binary format handler that it tried. This hid two errors. When the ELF loader recognized a program and failed with ENOMEM, the script handler said "not my format" and `exec()` failed with ENOEXEC. When a file was not a program and the builtin handler was the last one, `exec()` failed with ENOENT, as for a missing file. `load_absmodule()` now keeps the first error that is not ENOEXEC. The builtin handler now says "not my format" with ENOEXEC for a file that exists, and gives the error of `stat()` for a file that does not. ## Impact `exec()` and `posix_spawn()` change their errno, also in flat builds: a file that exists and no handler takes gives ENOEXEC, not ENOENT, with `CONFIG_BUILTIN` and without `CONFIG_BINFMT_SCRIPT`. A program that the ELF loader cannot load gives the loader's error, not ENOEXEC, with `CONFIG_BINFMT_SCRIPT`. A missing file still gives ENOENT, a script with a missing interpreter still gives ENOENT, and EACCES still stops the search. A directory is not fixed by this PR. With the ELF loader it now gives EINVAL in all configurations (before: EINVAL, ENOEXEC or ENOENT by configuration). POSIX wants EACCES. Documentation: no change needed. ## Testing The tests ran on base 39a1f27900c; the branch is rebased on 3d57048f1e1 (no change in the touched files). Test program: a missing file, a text file, a short file, an empty file, a script with a missing interpreter, a script with a text file as interpreter, a file with no x bit (with `FS_PERMISSION`), a program with a 256 MiB .bss (kernel builds), a builtin (with `CONFIG_BUILTIN`). "Failed" is the number of failed cases. | Config | Handlers | master failed | this PR failed | ostest master / this PR | |---|---|---|---|---| | qemu-armv8a:knsh + BINFMT_SCRIPT | ELF, script | 1 (big: ENOEXEC) | 0 (big: ENOMEM) | 0 / 0 | | qemu-armv8a:knsh | ELF | 0 | 0 | 0 / 0 | | qemu-armv8a:nsh | builtin | 5 (ENOENT) | 0 | 0 / 0 | | qemu-armv8a:nsh + ELF | ELF, builtin | 5 (ENOENT) | 0 | 0 / 0 | | qemu-armv8a:nsh + ELF + BINFMT_SCRIPT | ELF, builtin, script | 0 | 0 | 0 / 0 | | same + FS_PERMISSION + BINFMT_CHECKEXEC | ELF, builtin, script | 0 | 0 | 0 / 0 | | mps2-an500:knsh (protected) | builtin | 5 (ENOENT) | 0 | not run | The big case runs only in kernel builds. In flat and protected builds the ELF error path was only read, not run. Build only, with `EXTRAFLAGS="-Wno-cpp -Werror"`, no compiler warnings: qemu-armv8a:nsh, qemu-armv8a:knsh, mps2-an500:knsh, rv-virt:citest, rv-virt:knsh64, sim:nsh; qemu-armv8a:nsh and rv-virt:citest also with `FS_PERMISSION`. The change has no arch code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
