Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3244076imu; Sat, 24 Nov 2018 00:57:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/XJtVVbmErfFyXG0YAtSGeonWEYkRmvil2Bfp9crTYmpZ13c8xe6V3KBWXgBfr4j5ufW9ny X-Received: by 2002:a65:5bc4:: with SMTP id o4mr17429690pgr.426.1543049824779; Sat, 24 Nov 2018 00:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049824; cv=none; d=google.com; s=arc-20160816; b=wqjd8+PKbS+nxsjo09VnZitFmkxqpdHy7m2f+JRhxpvsbnUktub24e4yloBn6NUS50 R0joXfmCjlO2gWDUH3BAkg/uI9Ojc92scipxXep6Q3XzxD7Md5HUjnTTNKv+9bKVzKTr ZAzFSNRiMMRdgRypeHUtOLSvETYNDD2+P33zCqDPZaUIISunuCC0K64PH8x3ytJQWrBN P4s6ORpT8tW71QoKQxzKZhs0RojPQGjD4DK2uiA4QspztKnhQDa39/eZi3fsYhHn2VD6 HWP4UBie5NDFViz2QlISVHsMJx6OBzyIk5NGZYmiff6o8vgP/LEzOjb2wQXKGbWv7LKp 4Gzw== 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 :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=XziGM6DHoArBzDrxn00kdBpyQ80f9urGU+CKhUkADO4=; b=t7vog0BOdUWCJu+dAvgGzn/9s18PvIBaACa7Tk25xmnJJBHzqSLJailLyCxsLXsLLE oZPL73wRr3OxjsCM2/lUOeNcPy7M1FDwaWgA/6yruobdhJJODBQLpSkyBsURr7C2CE8P L/rFwzZwqz4gkDVlUwaq3erTMvEwQXE4m90IgQSDlV4cRdtz1pumFQ8hwG/KB8jXFnv1 CXH5PTtbScvgdgakfSiUGG4Yn9WwXlkcRecvvt0VGthDdPEf8PZTj7lRjc+Hl3Rjtbe0 DfRSSvhFh2gX1ZC3EiHToG+YcCeRRGQ97ZxIjMFu9VKL4hndE6iu4Z+FJcX86M+qKJgm n4kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dubeyko-com.20150623.gappssmtp.com header.s=20150623 header.b=wr0HF1gl; 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 y12si28314693pgh.289.2018.11.24.00.56.50; Sat, 24 Nov 2018 00:57:04 -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=@dubeyko-com.20150623.gappssmtp.com header.s=20150623 header.b=wr0HF1gl; 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 S1728693AbeKXLiZ (ORCPT + 99 others); Sat, 24 Nov 2018 06:38:25 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37655 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728649AbeKXLiY (ORCPT ); Sat, 24 Nov 2018 06:38:24 -0500 Received: by mail-pf1-f195.google.com with SMTP id u3-v6so3965956pfm.4 for ; Fri, 23 Nov 2018 16:51:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=XziGM6DHoArBzDrxn00kdBpyQ80f9urGU+CKhUkADO4=; b=wr0HF1gl0lh70FqeQCT1m0aCsboh7HI6OF9EAofV5acn5Gc0PkXKsnG8AtQwitxbxp pIw/FzGsJci5HMjcX7VE3RUcQ4DPBQw2S0jbYJf9NAJ06GW05N7Ei3cyIOENi7CG6cR3 9zLWmI5WC1orkZ2hfjpl0Z6zg0EHAQsAAu4oQ2jJE4uvo7DkZhM3cLQ3cEeEs/IsMWHR eMZaVsYNz5t+wRBYMeQS/lXQiGX6dlY5zRdddIDsXBdgDPq+A+GhXSy3gqJ3IeSx1Qrk w9sUxGIKiDcIvIqKxUq+LBh31hAuTGwSx1XpVZoHps5p+Shd7AoCW4wF+q3/rEFNdQKO Xc9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=XziGM6DHoArBzDrxn00kdBpyQ80f9urGU+CKhUkADO4=; b=UYlpahIIchWXFRKCKQb1Btq/FFk8+e1Pr0pRSxRh2BMspT0i8Ujq5ezqp8sAmkK93Y C6YK8zGX74BsObrbqvy/i1V8MM91HJzFtn7eVl9GZVZVVGKmu+ILAyoKMkf5z9W/oMxi 64VJiWTy2cyllFMAhYktM6Idr2Jh23sS9eOkdB9EjTTv+x9zOSDbdlabnuRv9ODP+uAy SS1OG+LVUvJuPlVmN/hUfJKKxUisMe0g2goy2mrJTa4nNHYlcOCdrlezZSCxHEAApkvl Vfizho2/34vBaOMoSKCamkqz4ew6VijzoQQ4368u/13v9oU8CzdZRF7vtlQqJxvMzcSC Xilg== X-Gm-Message-State: AA+aEWYEt8zEG4CD8Ew80z9qZpnGUDuiq9S3coBHKyEr3CoZHedtZkMJ 8osputt+gYmbZsebuLdi6Rmt2A== X-Received: by 2002:a62:7dcb:: with SMTP id y194mr7765686pfc.113.1543020718195; Fri, 23 Nov 2018 16:51:58 -0800 (PST) Received: from ubuntu-16 (c-24-130-14-162.hsd1.ca.comcast.net. [24.130.14.162]) by smtp.gmail.com with ESMTPSA id d21sm50304357pgv.37.2018.11.23.16.51.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 16:51:51 -0800 (PST) Message-ID: <1543020709.12764.3.camel@dubeyko.com> Subject: Re: [PATCH] hfs: do not free node before using From: Viacheslav Dubeyko To: Pan Bian , Joe Perches , "Ernesto A." =?ISO-8859-1?Q?Fern=E1ndez?= , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 23 Nov 2018 16:51:49 -0800 In-Reply-To: <1542963889-128825-1-git-send-email-bianpan2016@163.com> References: <1542963889-128825-1-git-send-email-bianpan2016@163.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-11-23 at 17:04 +0800, Pan Bian wrote: > 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); What's about simply to store node->this into the local variable in the beginning of the cycle? In this case, it is possible to use the node ID in the pr_crit() and to use the hfs_bnode_put(node) in the same place without to use it twice. What do you think? Thanks, Vyacheslav Dubeyko. > + hfs_bnode_put(node); >   return; >   } > + hfs_bnode_put(node); >   node = hfs_bnode_find(tree, i); >   if (IS_ERR(node)) >   return;