Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp748526imm; Thu, 13 Sep 2018 07:11:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYaXSR5Eqmt108X1EQMMZ8/mesOvlQUCJjsRLpYhIYjBkNtUj5xVFJ8M3PAoHAGs/dMn14R X-Received: by 2002:a63:fe02:: with SMTP id p2-v6mr7501937pgh.148.1536847905519; Thu, 13 Sep 2018 07:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847905; cv=none; d=google.com; s=arc-20160816; b=KTrVidFZJQe80VBmI3nYjigii9jT/wwtTJq1dITSXw+JKQU0AdwVKlx7jNClaaL3yN 2cOpyWOmP2NYGnOcWAhwly0WzK4l/RmcYyDog7yUdbYKw5SzYDtWyxKfmbXmjdo7I7d2 +Mjt1WWMAQK16V9nx0K3DdlkcTVIZbzv1u2bQ+YYrXT52xiygj5sijQ+9WcliIJDSMmX 7ClAS60uj5KnI3h+F9ZG49KrcUI383Pdf1QKHwj+V/gx79IimDkzSKu+g1RvKavIPHT9 y8vjPNr2jp5YrYRej4H1pht49DjvODNeEP0HwbrO0y+wy2opU6kRAvQOZgeunXmTlMjq cGnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=NzKENsRNDr15kslfec5y/CBAWgoa4T37iDlLEj2Ax20=; b=vK4jTWVTusH2o4KoakSU+nbidb1tZ6HJW9vGvM+MGw9rPE1yhYRbplc8AGee3KubPj +prnwOk7yNoeDmCgo2O11hv/3ds8yBs3yS+IOP6/4xcznVPU3++VMkSn+wseCz5PuJgA GAssvFmkzHkxIAcTwnZRYBe5iQVbn3C+8kpSrrbzPcaTQUj/L+R8W5mg0VPHszpQihmS W9bESGH9Qxq2UmztaDpt8nOajlU2g9ZG0hGgGwXsCRkou6Noz79ms/snTq6Sli7pViVS yBw/vAe5DOfKNNlf4ocUjjeIYWWEL33NpMhPnCC67Hwee5c8mLJkfLLSHHxH9nX5dW4v IWVg== 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 137-v6si4294790pfx.155.2018.09.13.07.11.26; Thu, 13 Sep 2018 07:11:45 -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 S1730796AbeIMTC2 (ORCPT + 99 others); Thu, 13 Sep 2018 15:02:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33576 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730002AbeIMTC1 (ORCPT ); Thu, 13 Sep 2018 15:02:27 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0E568D19; Thu, 13 Sep 2018 13:52:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "=?UTF-8?q?Ernesto=20A . =20Fern=C3=A1ndez?=" , Wen Xu , Viacheslav Dubeyko , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.18 045/197] hfsplus: fix NULL dereference in hfsplus_lookup() Date: Thu, 13 Sep 2018 15:29:54 +0200 Message-Id: <20180913131843.346659588@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Ernesto A. Fern?ndez" [ 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 Reported-by: Wen Xu Cc: Viacheslav Dubeyko Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/hfsplus/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/hfsplus/dir.c +++ b/fs/hfsplus/dir.c @@ -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];