]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commit
readdir: be more conservative with directory entry names
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 23 Jan 2020 18:05:05 +0000 (10:05 -0800)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 6 Mar 2020 07:25:26 +0000 (02:25 -0500)
commitfbb4c9430cf28f4a0854a8bdab7cf1312ae00b32
treef7f04283b9933c1d5262c246bfdf41196a8deb8b
parent14b0ac88aebfb551eb6e6a1bec1f5dfcf9abd329
readdir: be more conservative with directory entry names

BugLink: https://bugs.launchpad.net/bugs/1864710
commit 2c6b7bcd747201441923a0d3062577a8d1fbd8f8 upstream.

Commit 8a23eb804ca4 ("Make filldir[64]() verify the directory entry
filename is valid") added some minimal validity checks on the directory
entries passed to filldir[64]().  But they really were pretty minimal.

This fleshes out at least the name length check: we used to disallow
zero-length names, but really, negative lengths or oevr-long names
aren't ok either.  Both could happen if there is some filesystem
corruption going on.

Now, most filesystems tend to use just an "unsigned char" or similar for
the length of a directory entry name, so even with a corrupt filesystem
you should never see anything odd like that.  But since we then use the
name length to create the directory entry record length, let's make sure
it actually is half-way sensible.

Note how POSIX states that the size of a path component is limited by
NAME_MAX, but we actually use PATH_MAX for the check here.  That's
because while NAME_MAX is generally the correct maximum name length
(it's 255, for the same old "name length is usually just a byte on
disk"), there's nothing in the VFS layer that really cares.

So the real limitation at a VFS layer is the total pathname length you
can pass as a filename: PATH_MAX.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
fs/readdir.c