Fix SXID_ERASE behavior in setuid programs (BZ #27471)
commit2ed18c5b534d9e92fc006202a5af0df6b72e7aca
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Tue, 16 Mar 2021 07:07:55 +0000 (16 12:37 +0530)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 12 Apr 2021 13:33:19 +0000 (12 19:03 +0530)
treedddc17dc530bbdaa1f6fbc3bd781a70fe549aeca
parent061fe3f8add46a89b7453e87eabb9c4695005ced
Fix SXID_ERASE behavior in setuid programs (BZ #27471)

When parse_tunables tries to erase a tunable marked as SXID_ERASE for
setuid programs, it ends up setting the envvar string iterator
incorrectly, because of which it may parse the next tunable
incorrectly.  Given that currently the implementation allows malformed
and unrecognized tunables pass through, it may even allow SXID_ERASE
tunables to go through.

This change revamps the SXID_ERASE implementation so that:

- Only valid tunables are written back to the tunestr string, because
  of which children of SXID programs will only inherit a clean list of
  identified tunables that are not SXID_ERASE.

- Unrecognized tunables get scrubbed off from the environment and
  subsequently from the child environment.

- This has the side-effect that a tunable that is not identified by
  the setxid binary, will not be passed on to a non-setxid child even
  if the child could have identified that tunable.  This may break
  applications that expect this behaviour but expecting such tunables
  to cross the SXID boundary is wrong.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
elf/dl-tunables.c
elf/tst-env-setuid-tunables.c