Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Jan 28, 2022 16:26 UTC (Fri) by matthias (subscriber, #94967)In reply to: Handling argc==0 in the kernel by larkey
Parent article: Handling argc==0 in the kernel
Probably the confusion is for a simple reason. The two things are more or less the same. If the execve() function is called with argv == NULL, the kernel actually constructs a NULL-terminated array argv with argv[0] == NULL and calls main(argv,0). Thus for the called application, these two things are indistinguishable.
> I agree that Linux should not allow argv == NULL, that's definitely against the spec.
From the examples in the discussions it seems that the "lazily written tests" do exactly this: call execve() with argv == NULL. If Linux disallows this, these tests will break due to an ABI/API change.
> argv[0] == NULL is a different matter although I think it is a reasonable demand, from a security stand point.
Yeah, but disallowing the former and allowing the latter does not make any sense, as the two cases cannot be distinguished by the called application. There would be no advantage from just disallowing argv == NULL.
The problematic case from the security persepctive is allowing argv[0] == NULL (or more precisely argc==0). The problematic case from the compatibility perspective is disallowing argv == NULL in the execve() call. Thus only disallowing argv == NULL in the call gives us the worst from both perspectives. We get all compatibility problems with no increase in security.
