Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3244353imu; Sat, 24 Nov 2018 00:57:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/X1fxpPe003cJSZJhSZJ7h+xgal6Uts11WxUECQ0m46pG6ztzoFWb9+MbhGQaM9/9o2tGdf X-Received: by 2002:a17:902:6e16:: with SMTP id u22mr18855140plk.175.1543049853078; Sat, 24 Nov 2018 00:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049853; cv=none; d=google.com; s=arc-20160816; b=C87dr825ciQnW9GqtvjQhM/M2mgY+5e7ftYRvcsrideOmmQGJJwGUGfHsiAO2scrEE J8DTwUOUTA1pW4CikLhHLaa6cb+BFnGLgncL1kStwDLZHeVP0BagOUn4f7McA5tqq9P2 lpwsY5dKYMkukFE4snrB5lcDob9Qkb87/DIZc5CuSAh+MVmPghXVgQIVWQpKatWdk2AG Cqb0W+fLXl/MaJnuJFFRUBuWfktnzVir4HsxmmknIFnHqJ4DtLGzd7Dw/kX6rNxl+bz9 RMnFAUqSHoYo2Gw7S9pu0kBRE/p/N02yN//1N5K5gw6f4mn8rt6EhgMM28anWDr5ramO BQtA== 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=ZbW9rYi3Cz6z27YeA9E1w9eoVVKUuxmORxUFqr6PC5A=; b=QAplLD39bb6KHsGQ69x4tJAnOUxSHswTD/2/NtEb92MKFQq3n+oaiegsLklx20sjFW jHqiSr6vm0pQO4UNInDf/7xSS5ycbyoskCQ0g6JtA+ii9561xcuxEhS5GKF0Aj00qy4d IDEvvzoY5d0llQFTQ4IfFfKLbOHPpyFdHh+pyO4z4ZKy9H3BjG0KotdE/v/bs2UwZTmh u3KapVGw+Q7zI+bB2Ddh5lGx68Wb4Lta5d/Xdscm3wbEI8hYnx9sezNm6/+HkD4CSbgK TmMBur5brLXsnPzP+1+l2oybxLTTkdn/A5qOkJ86XdmsIlub2uhrWy98F6g1kb77Jg43 zIxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=XrQcL3eT; 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 b14si35144215pfc.156.2018.11.24.00.57.18; Sat, 24 Nov 2018 00:57:33 -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=XrQcL3eT; 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 S1729426AbeKXM6A (ORCPT + 99 others); Sat, 24 Nov 2018 07:58:00 -0500 Received: from m12-18.163.com ([220.181.12.18]:40781 "EHLO m12-18.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729268AbeKXM57 (ORCPT ); Sat, 24 Nov 2018 07:57:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=ZbW9rYi3Cz6z27YeA9 E1w9eoVVKUuxmORxUFqr6PC5A=; b=XrQcL3eTSM7uttLp7hSKMgSxWYvPE+kazm G6dRMiVdKL5KT/nNk6LecY3YPb99f11bSfNvHRfEwD/k2xhEbiVVG3S3ornKq8TS JPS/GytUdMCOdNKyWMPlMK0M9O1RSxf+RtGXuygvlYwrjlob4Wqor/bLYMQGx2Fm iubnIjbsw= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp14 (Coremail) with SMTP id EsCowACn0zU4s_hb184VBg--.38107S3; Sat, 24 Nov 2018 10:11:16 +0800 (CST) From: Pan Bian To: Andrew Morton , ernesto.mnd.fernandez@gmail.com, Joe Perches Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH V2] hfs: do not free node before using Date: Sat, 24 Nov 2018 10:10:58 +0800 Message-Id: <1543025458-31592-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: EsCowACn0zU4s_hb184VBg--.38107S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtr1DCw1xCFy5WF43uFykXwb_yoWfZFb_JF 4xW3Wxt34rGFZ7Jrs3CrZYqw42gF4rGwnagw4xtFWak3yYyan5Jr1kZr9YyryfuFWYgrn8 J3yktryUGay7GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnjFAJUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBZwQJcletsGsCLAAAsX 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: a1185ffa2fc("HFS rewrite") Signed-off-by: Pan Bian --- V2: correct the commit information in Fixes --- 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