Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3212551imu; Sat, 24 Nov 2018 00:13:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/UaT3DVGkBP1vftEl2IXAnnxryeQK9zaU+FSsTUI/u2ByiFMR0lSmNcubhl/1sj2aNYu8pn X-Received: by 2002:a63:fb46:: with SMTP id w6mr17227387pgj.321.1543047217986; Sat, 24 Nov 2018 00:13:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543047217; cv=none; d=google.com; s=arc-20160816; b=SG8CE/fSqWSBnSoSt/1TrPuDZkMxXliKE8VyyZ28q7DtG0dpZsbezVWzcsIRcQJrBP BszLGllwyXw0i1e8Gy+1TGvlHKQE1U42rir3urQ+r973erXRAiwaWQi1Z+9NCkA5pt6a slOC8srBh2+U5FWc24IAXWrysqvwIS0z/ogWh9ECvueS/aypB9JATra1xwYNPHtJElz9 a2J0+aKOhyt3TBtfktZWF+adAoAPDa5KO+SPFo4bLhqhfdkwivClq+EXIfDOsjpa+yoM 4hIdltgCYqrmutiGfdoMY+pzieTAhLFnxzHIg43Ic5vKxHLM9FjHyOQlx1xthP27ZoT2 Xo8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=DCwuoK5VcJCo4dkCoMh3n7cLwH609uBf3xTxpnmAMOs=; b=v0rXP/TifZaae6DHr4OPbzhWnTu0ZtkdFaa4nImXHGtHIXRMjV9ebXKbahsVaS7FZ4 a0FCSk9ycWgbzCqHsx2ajsUVcZvkNAfmSmyMc/9ZpWxo3OsU8vnd4nmvJxFsNDUMJRHm 1LHNTnlmH9Q0UOAr8nFzQuEf0KRDllcaZNTFQ9cynMSpS5ZWlQB0WzauJCjLzIZbfiXO Xwwe/1ch5eomCVzZa6wkxJ6w5DjeOrxE5gemaEcOrYnr+s4zmYohkfYWUV731vBgZWK3 4zTuQ+3SRWpbLAxbRSorEfu+ZS37Zqg0vHPQ1exVLWAcEXsfIlFiB56ARz3dHxPhC4QE f8jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Rs2mgK8h; 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 z86si44953701pfl.209.2018.11.24.00.13.23; Sat, 24 Nov 2018 00:13:37 -0800 (PST) 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; dkim=pass header.i=@163.com header.s=s110527 header.b=Rs2mgK8h; 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 S2408758AbeKWTtR (ORCPT + 99 others); Fri, 23 Nov 2018 14:49:17 -0500 Received: from m12-14.163.com ([220.181.12.14]:60837 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732135AbeKWTtR (ORCPT ); Fri, 23 Nov 2018 14:49:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=DCwuoK5VcJCo4dkCoM h3n7cLwH609uBf3xTxpnmAMOs=; b=Rs2mgK8hQf3+MXwjmJ4HElyRqbrbW31mp8 TovCDrQEJHtKbYTWvQKkHjYB2PPCjflmICN3zsGE4TWiC2Sd8MsTqAByi1ncAgPO tS7L2NlQnkJJ1o26NWewJjmgs5S+PdH6usVyDoi0a8EaBHV8yY+fa710h354Egep XX4fa5Rlg= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp10 (Coremail) with SMTP id DsCowABH_OGwwvdbbrrlBQ--.19497S3; Fri, 23 Nov 2018 17:04:51 +0800 (CST) From: Pan Bian To: Joe Perches , =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] hfs: do not free node before using Date: Fri, 23 Nov 2018 17:04:49 +0800 Message-Id: <1542963889-128825-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DsCowABH_OGwwvdbbrrlBQ--.19497S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtr1DCw1xCFy5WF43CFWfXwb_yoWfCrg_XF 4xW3Z7t3yrGFZ7JFZ3ArZYqrW2gF4rGws3Ww4xtFWak3yYvan8Jrs7Zr9YyryxuF4agr15 J3yktry8Gay7JjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0dWrJUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiDhMIclXlpkg5VQAAsV Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function hfs_bmap_free frees node via hfs_bnode_put(node). However, it then reads node->this when dumping error message on an error path, which may result in a use-after-free bug. This patch frees node only when it is never used. Fixes: d614267329f("hfs/hfsplus: convert printks to pr_") Signed-off-by: Pan Bian --- fs/hfs/btree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c index 98b96ff..19017d2 100644 --- a/fs/hfs/btree.c +++ b/fs/hfs/btree.c @@ -338,13 +338,14 @@ void hfs_bmap_free(struct hfs_bnode *node) nidx -= len * 8; i = node->next; - hfs_bnode_put(node); if (!i) { /* panic */; pr_crit("unable to free bnode %u. bmap not found!\n", node->this); + hfs_bnode_put(node); return; } + hfs_bnode_put(node); node = hfs_bnode_find(tree, i); if (IS_ERR(node)) return; -- 2.7.4