]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Correctly handle illegal system file in tz
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 27 Jan 2023 11:57:51 +0000 (11:57 +0000)
committerSerge Hallyn <serge@hallyn.com>
Wed, 1 Feb 2023 21:47:35 +0000 (15:47 -0600)
If the file referenced by ENV_TZ has a zero length string, then an out
of boundary write occurs. Also the result can be wrong because it is
assumed that the file will always end with a newline.

Only override a newline character with '\0' to avoid these cases.

This cannot be considered to be security relevant because login.defs
and its contained references to system files should be trusted to begin
with.

Proof of Concept:

1. Compile shadow's su with address sanitizer and --without-libpam

2. Setup your /etc/login.defs to contain ENV_TZ=/etc/tzname

3. Prepare /etc/tzname to contain a '\0' byte at the beginning

`python -c "print('\x00')" > /etc/tzname`

4. Use su

`su -l`

You can see the following output:

`tz.c:45:8: runtime error: index 18446744073709551615 out of bounds for type 'char [8192]'`

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
libmisc/tz.c

index f3f5733e3810c50f7858ae3ca046a01c13eb384c..9f3a41f2893ce14c933c0e07dcc66da82644f772 100644 (file)
@@ -42,7 +42,8 @@
 
                strcpy (tzbuf, def_tz);
        } else {
-               tzbuf[strlen (tzbuf) - 1] = '\0';
+               /* Remove optional trailing '\n'. */
+               tzbuf[strcspn (tzbuf, "\n")] = '\0';
        }
 
        if (NULL != fp) {