]> git.itanic.dy.fi Git - linux-stable/commit
ext4: don't leak old mountpoint samples
authorTheodore Ts'o <tytso@mit.edu>
Thu, 17 Dec 2020 18:24:15 +0000 (13:24 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 22 Dec 2020 18:08:46 +0000 (13:08 -0500)
commit5a3b590d4b2db187faa6f06adc9a53d6199fb1f9
treed69f9826e171a7c27172698236e0e76b549407bf
parenta3f5cf14ff917d46a4d491cf86210fd639d1ff38
ext4: don't leak old mountpoint samples

When the first file is opened, ext4 samples the mountpoint of the
filesystem in 64 bytes of the super block.  It does so using
strlcpy(), this means that the remaining bytes in the super block
string buffer are untouched.  If the mount point before had a longer
path than the current one, it can be reconstructed.

Consider the case where the fs was mounted to "/media/johnjdeveloper"
and later to "/".  The super block buffer then contains
"/\x00edia/johnjdeveloper".

This case was seen in the wild and caused confusion how the name
of a developer ands up on the super block of a filesystem used
in production...

Fix this by using strncpy() instead of strlcpy().  The superblock
field is defined to be a fixed-size char array, and it is already
marked using __nonstring in fs/ext4/ext4.h.  The consumer of the field
in e2fsprogs already assumes that in the case of a 64+ byte mount
path, that s_last_mounted will not be NUL terminated.

Link: https://lore.kernel.org/r/X9ujIOJG/HqMr88R@mit.edu
Reported-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
fs/ext4/file.c