Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp29394imm; Fri, 21 Sep 2018 17:25:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Fp3zDiiRoABMCTXsnrabRoW5N6Zj8pkvizOOcgLd3jF0oVUnD8fO30fA0+BGg0IiQPp6f X-Received: by 2002:a63:7e1c:: with SMTP id z28-v6mr133014pgc.246.1537575921576; Fri, 21 Sep 2018 17:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575921; cv=none; d=google.com; s=arc-20160816; b=CoicOgc3l6v1whA+Y3f6wYsHwbQji8NQcB5ss9ML3ZFtBBrPJMErydSbN38EuFVYMM oZhs13p9RS6IIkh79m1acX29ByH+Hpf8NIkfVwfDRZZBv9jOdulQC9iEaSvYTCF9Wd8q 6wbIh4fDXeG5wHrfQ0yGbfCPHkIusMX/4R3lvK2ar7nGLShKHC61XQASbsGjIV9VHpBB fnh0PjaoZsx8Jn1V+fbV8to1UOSCQqaJ2sP/qeISqmsrRQ89l71ojshlRqaFGjs60SRR Nf3ghygjdotI/6ae8FcqqTHJ36e8AQI7uwl7JOXmguTDiJu0zTEidAvApBrz1hG+ldys +nfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Yk6m2UkEehavfCnjIVh3N87FOUROQxLKSEWJg8oZcDA=; b=mHr6CsF0NfO4DiNjX0HdMa6NldIEiK4P4H5/Q5tuG1JaJCK/yZPxUz8HxrtWlBWS2D R/CRvQ6XmgRn8+M0WzHSp8HvkM5qEQSP8EZTsFxko0nIZ32Jbzr7/nYIGLUhzk6YWulQ 5vI26skONqa3PqieyWIXoN3Clg4TaXVJL5GsqH39AVHXQbudX7WRUxgOeR5+IeWlZtpF nbPrM/xos7AdtrA3N/yMZlHUyO+hgTRaGS3Aqj/IDR7EDdVaeWPDtoLnyJFHRMINo/Y3 I7m6CQwSWBPO1qj/tvQnTQFFeStxupQgoQ8MNmdJGXNWkWAhtH98gO4dYFg9cf8mCh1X kIPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o123-v6si30000519pfd.36.2018.09.21.17.25.05; Fri, 21 Sep 2018 17:25:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392372AbeIVGPf (ORCPT + 99 others); Sat, 22 Sep 2018 02:15:35 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44155 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391739AbeIVGKp (ORCPT ); Sat, 22 Sep 2018 02:10:45 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vdv-0008BZ-CL; Sat, 22 Sep 2018 01:19:27 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdo-0000ti-SJ; Sat, 22 Sep 2018 01:19:20 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Wen Xu" , "=?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?=" , "Viacheslav Dubeyko" , "Linus Torvalds" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 50/63] hfsplus: fix NULL dereference in hfsplus_lookup() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.58-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Ernesto A. Fernández commit a7ec7a4193a2eb3b5341243fc0b621c1ac9e4ec4 upstream. 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 Reported-by: Wen Xu Cc: Viacheslav Dubeyko Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- fs/hfsplus/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/hfsplus/dir.c +++ b/fs/hfsplus/dir.c @@ -74,13 +74,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(sb->s_root->d_inode)-> - create_date) && - HFSPLUS_SB(sb)->hidden_dir) { + create_date)) { struct qstr str; char name[32];