Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3244066imu; Sat, 24 Nov 2018 00:57:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xx1E0lRlxLQgHYmIIpPsBGggXW/b2t9KbwM4tYlnAnmLeH21wSnEGu96SVhW2o0l0xCNPL X-Received: by 2002:a62:62c5:: with SMTP id w188mr303274pfb.160.1543049823325; Sat, 24 Nov 2018 00:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049823; cv=none; d=google.com; s=arc-20160816; b=C2Y6QgQP5it4wB3z0lq3cPC1/M6qbJviFQdDZGVG4MlDIVzH/d/X/vjz5laQOjVp/Z 5rHNj5JdMGw+pHiAFgGub2juBXeDajmSp2mdyqYnhgPeM6cziSpbWLVd8kPcex8uDNKt O+Kr4KPhE+5dYIOWOhj3jHu3QlQv1EKoVRlaXTBRrcfcDz+KbwCTE0qpIsX1jvdQ33vq ajbq9iBwX+UcBpZm77CsuJnZiug31uuKQb1l1QfwcFa/11Xt35DmxoWpevSdt0eWpNI7 czh2Cbw8LUj2TjuIOxPR0Mz+zv3Jys9IOyBYi5FGvYIDNz6d1FB7jOk4ML4fVvK5rpoa YOJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Mia710GVrkzIa0+UQuBOddn+CcnraMEfxnPJ31GICwg=; b=pgBEKsituUuxBbvaFnQPgE3Nq+aT8mSUVYtXrT07X6QolYaOEMv/I4KklaYQk22NmM t2ImbgJVpykTCi9mEB/UQVkPYhIFRUD2hT4BrZXbQLwjX41exzQn5j2+3y+97Vn7n+QF nD0i5EUKhNHnXfs2RtrCTTDDz5hPUluaevBkdR+w4pb5vPJDVLfXLmswY3s2OqJWhHa8 O0sbYVjL0HT44kELaq0buAFIUC2k6oPftqPS0AvCUPbhkOhnGyXDkgMyEQUEAqVWhfTQ ufMnZwS6+f2Zt9E75qhmx/RTPvVroJpy3lPJNm2nWuOZ6HE1gVfR2PvCBCZxp5Gb30ij qR0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="L2h/gIm+"; 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 ay4si24156498plb.235.2018.11.24.00.56.49; Sat, 24 Nov 2018 00:57:03 -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="L2h/gIm+"; 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 S1729254AbeKXMlG (ORCPT + 99 others); Sat, 24 Nov 2018 07:41:06 -0500 Received: from m12-13.163.com ([220.181.12.13]:58618 "EHLO m12-13.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729235AbeKXMlG (ORCPT ); Sat, 24 Nov 2018 07:41:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=Mia71 0GVrkzIa0+UQuBOddn+CcnraMEfxnPJ31GICwg=; b=L2h/gIm+dr74pezFFWqeR JRV1UuUTdpoEx2mBiIbLgKiQ+TmmkEIQY74gzvWBtcpwY7BygWVGrKKireEUT9D2 Jdxgn1jkbiLcX8Uy7sorYz4kiekHsk8Z3e7CWNN9kHbQmvt6LZzMiQDXttee30Px UTgv+kEPgJJMnMSbvsrP0A= Received: from bp (unknown [106.120.213.96]) by smtp9 (Coremail) with SMTP id DcCowAAnZcpOr_hbiqcSBg--.18944S2; Sat, 24 Nov 2018 09:54:22 +0800 (CST) Date: Sat, 24 Nov 2018 09:54:23 +0800 From: PanBian To: Viacheslav Dubeyko Cc: Joe Perches , Ernesto =?iso-8859-1?Q?A=2E_Fern=E1ndez?= , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] hfs: do not free node before using Message-ID: <20181124015423.GB23256@bp> Reply-To: PanBian References: <1542963889-128825-1-git-send-email-bianpan2016@163.com> <1543020709.12764.3.camel@dubeyko.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1543020709.12764.3.camel@dubeyko.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: DcCowAAnZcpOr_hbiqcSBg--.18944S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tw1DGF47Xw1DXF4DKw45ZFb_yoW8Wr17pr yxCF42kF4DZ34IkrnavF1Fg34vyw4xJrs0kws5Cr1xZ3Z8Xr97Wr18KryY93W5ZrW8Z3yj qrs8G3sxWrsxZaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jNjjgUUUUU= X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzw4JclaD0ZEAlgAAs5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 23, 2018 at 04:51:49PM -0800, Viacheslav Dubeyko wrote: > 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? Of course, it is a solution. But I think doing like that does not really simplify the code, as we have to declare an extra local variable, and assign node->this to it... Best, Pan > > Thanks, > Vyacheslav Dubeyko. > > > > + hfs_bnode_put(node); > > ? return; > > ? } > > + hfs_bnode_put(node); > > ? node = hfs_bnode_find(tree, i); > > ? if (IS_ERR(node)) > > ? return;