4 ms·
I completely agree with your idea; I've long believed that the OS kernel should reject dubious filenames.
by kazinator 8y ago
I completely agree with your idea; I've long believed that the OS kernel should reject dubious filenames.
- kazinator 8y agoHowever, from past thoughts and discussions, there are issues. (1) We have to be able to mount filesystems which have bad filenames and allow users to work with them. In that situation, that means the kernel cannot reject all requests for bad file names, only creation requests. And perhaps not even that. It can be a mount option with three values: off; reject all dubious names in all filesystem syscalls; or just in creating syscalls: open with O_CREAT, mknod, link, ... It could also be a capability. Superuser could work with the dubious filenames and set up capabilities for non-privileged child processes to do same, so people needing to work with a filesystem full of these names can get into an environment where they can do that. (2) Enforcement at the kernel level is too late in some situations. It doesn't entirely compensate for broken programs. Here is a trivial example of what this means. Suppose that some program receives an argument "foo bar" and decides to split that into "foo" and "bar", treating this as two file names to create or process. Those filenames look fine to the kernel, so it is allowed. In shell scripts, not all name-related issues arise from files that are already in the system. In fact, shell scripts are often robust in the face of existing files with poor names. For instance names generated with globbing expansion are safe, even if they contain spaces and shell meta-characters. The one danger is that the prefix of the expanded list looks like command line options to the program. The issues that arise in shell programming from failing to quote variable expansions cannot be fixed outside of the shell. The OS cannot fix the lack of quoting in command $VAR; it can't prevent a shell internal variable VAR from containing spaces.