]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
hfsplus: fix NULL dereference in hfsplus_lookup()
authorErnesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
Fri, 24 Aug 2018 00:00:25 +0000 (17:00 -0700)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:46:24 +0000 (19:46 -0600)
BugLink: https://bugs.launchpad.net/bugs/1835972
[ Upstream commit a7ec7a4193a2eb3b5341243fc0b621c1ac9e4ec4 ]

An HFS+ filesystem can be mounted read-only without having a metadata
directory, which is needed to support hardlinks.  But if the catalog
data is corrupted, a directory lookup may still find dentries claiming
to be hardlinks.

hfsplus_lookup() does check that ->hidden_dir is not NULL in such a
situation, but mistakenly does so after dereferencing it for the first
time.  Reorder this check to prevent a crash.

This happens when looking up corrupted catalog data (dentry) on a
filesystem with no metadata directory (this could only ever happen on a
read-only mount).  Wen Xu sent the replication steps in detail to the
fsdevel list: https://bugzilla.kernel.org/show_bug.cgi?id=200297

Link: http://lkml.kernel.org/r/20180712215344.q44dyrhymm4ajkao@eaf
Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
Reported-by: Wen Xu <wen.xu@gatech.edu>
Cc: Viacheslav Dubeyko <slava@dubeyko.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
fs/hfsplus/dir.c

index e8120a282435d1eac2e4f08ce1451b126c3e5b6d..1a44c4621e74b5ffe4bc44d36b55868ded4315b9 100644 (file)
@@ -78,13 +78,13 @@ again:
                                cpu_to_be32(HFSP_HARDLINK_TYPE) &&
                                entry.file.user_info.fdCreator ==
                                cpu_to_be32(HFSP_HFSPLUS_CREATOR) &&
+                               HFSPLUS_SB(sb)->hidden_dir &&
                                (entry.file.create_date ==
                                        HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)->
                                                create_date ||
                                entry.file.create_date ==
                                        HFSPLUS_I(d_inode(sb->s_root))->
-                                               create_date) &&
-                               HFSPLUS_SB(sb)->hidden_dir) {
+                                               create_date)) {
                        struct qstr str;
                        char name[32];