There are plenty of bespoke binaries out there with no/lost source code that won’t get the benefit of scrutiny from the kernel dev team. I certainly wouldn’t assume that none of them invoke execve with a NULL or 0-item arg parameter, and merging this patch would break them without recourse.
I would lean towards making it an API error BSD style and taking breakage on a case by case basis. I'm not the person who would be called up however, so it's easy for me to say.
Worst case you can create a sysctl variable to enable/disable the check for those corner cases where it can't be fixed and other precautions can be taken against the security vulnerability.
How much commercial software targets UNIX these days?
And that little one named macOS as well.
Amusingly enough, Apple has had a bug in their `ps` since 10.3 that assumes argc > 0, which actually results in a similar (but not likely harmful, despite ps being setuid) bug.
Sure, the pkexec bug is now fixed, but I expect we'll see another similar one eventually. I know I personally have written a lot of C programs that assume argc>0 and argv!=NULL, and I'm sure there are thousands of such programs.
I think returning EINVAL on exec in this case may be too much. I think the right move is probably for the kernel to just fix things up when exec is called in this way, so argv will always have at least one element, and that element 0 won't be NULL. I think any program that would break with that change is something I'd be able to live with.
I get that the vulnerability could have been prevented if Linux deviated from the spec like some of the BSDs might have, but we shouldn't make it the responsibility of kernel developers to make logic errors in user applications less likely.
We definitely do when safe to do so…
So this would break anything that calls execve() with argc==0. Is such call providing any functionality?
In addition to returning EINVAL being produced by not well written callers, another option would be to force argc==0 and fill up argv[0] with process name. That fix would make everything continue to work.
Edit: just tried on windows 10 WSL, and it had a sad (blue screen).
(also, TIL, thank you)
This is probably the most sympathetic I've been to the Kernel breaking userspace programs that rely on bad behaviour, but Linus has been pretty clear on the matter in the past.
> WE DO NOT BREAK USERSPACE!
1. https://github.com/torvalds/linux/commit/6b99e3569ba17b9fd38... (2017) This changed the userspace hwmon API of the thinkpad-acpi driver from `/sys/devices/platform/thinkpad_hwmon/` to `/sys/class/hwmon/hwmon1/`, which broke the sensor-monitoring software that I wrote for my laptop. It was justified on the basis that libsensors was resilient to this change, but my software didn't use libsensors.
2. https://github.com/torvalds/linux/commit/b02c6857389da66b09e... (2020) This changed the userspace hwmon API of the k10temp hwmon driver, specifically by swapping which temperatures referred to Tctl vs Tdie. For example, my Threadripper reports one real temperature and one fake temperature that's 27degC higher than the real one. (AMD does this because it wants default fan curves to think the CPU is hotter than it really is, because it wants fans to run faster by default.) Since this change swapped the two sensors, it could've had one of two outcomes for fan curve software:
- a) Software that monitored the fake temperature was now reading the real temperature, and thus running the fan slower than it needed to.
- b) Software that monitored the real temperature was now reading the fake temperature, and thus running the fan faster than it needed to.
Luckily my case was (b), so I discovered the change not because of a throttled / smoking CPU but because of an unexpectedly loud CPU fan.
(There was another case in ~2012 when the thinkpad-acpi driver switched from procfs to sysfs, but that one was more "justified" because sysfs was the right place for hwmon anyway.)
^1 which ironically enough was an attempt to avoid racy uid checks on setuid binaries.
https://gitlab.freedesktop.org/polkit/polkit/-/commits/maste...
(I am ... ambivalent, let us say ... about whether I -approve- of people doing so in any given case, but I definitely believe in them having the option)