Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp347466pxb; Wed, 8 Sep 2021 02:36:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxJ2FQVkS8drkvgvBGkdUS3wgsaiXZl0QwF/LJEhxazOPWK1GeAPaQYb70a4j9bBZFzBxX X-Received: by 2002:aa7:dc50:: with SMTP id g16mr2865244edu.182.1631093817974; Wed, 08 Sep 2021 02:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631093817; cv=none; d=google.com; s=arc-20160816; b=m5frcF2MYWzLYTKWExJEKxzcEyYqAwp+BAin+Qz8v50/FScTXBJSTeQMD1yD6Yhk0M U+XLWCdKgyOrbfaoQh/BCOFPsnfjgKCKx+6MfskaV6XpYTB2UnUzzdfExaPG1pswygVn 9/Wo8BvZ+NS0Kx47R86rPkQLEQbj29gEK/wQrXjt6l1fEjz3E5NQqKgl0pdboIgjrpts C980GXoVgQPcysJGOAMZIzIg0YGaAaBvW2ZQrDIDJHbxFXrBzlF7Pnth2f1QgvLm7JsW aIVQgJmLH3O5prJOFlcpZ8hnxd8B50NJU2JLOLH3O1CzNQedSb+XZcMoma/yX9Q7Bts1 d/FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=KiaAo+Gxc3m3sijTy9t7cjKWZ9iu/fIBo23GlNIzSmY=; b=Z4KW/Cz0HeFsZEqe6C/WrRyQKgR7FzJ+t1P1J/5XS39+VR3ZyO8TJB+sMfLwVgSUUF CrkbbzGvUa2kOFBBTKb0Y4sjWjRTq/+c+/NjuAt8Ibt10aYuwNsW3ZuMpX/Uik/dke0O s9BM+fjL0GsMjHsbL5fzhZR9JvNiP3SyMWxc8RId35Vy9b6iZ1fECzESJlSJMOqOg2I7 T8rQfgO+L7ei0xd58WeJf7bhOFNtIC8G2WFs9ZQMIj6vSeAaVznUKnPLu40z3XFCwHKM 7OxyYO+65OvguDW52gwj9yVu3LaWB7thmlI8NKo3yIl4B/aNiiXpeCRFXYWlQFRRHF6j EO7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si1681988edt.87.2021.09.08.02.36.33; Wed, 08 Sep 2021 02:36:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348506AbhIHJG0 (ORCPT + 99 others); Wed, 8 Sep 2021 05:06:26 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:57654 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234820AbhIHJGT (ORCPT ); Wed, 8 Sep 2021 05:06:19 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R721e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0UngJA3E_1631091909; Received: from B-D1K7ML85-0059.local(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0UngJA3E_1631091909) by smtp.aliyun-inc.com(127.0.0.1); Wed, 08 Sep 2021 17:05:10 +0800 Subject: Re: [PATCH] ocfs2: Fix handle refcount leak in two exception handling paths To: Chenyuan Mi Cc: yuanxzhang@fudan.edu.cn, Xiyu Yang , Xin Tan , Mark Fasheh , Joel Becker , ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org References: <20210908062603.6723-1-cymi20@fudan.edu.cn> From: Joseph Qi Message-ID: <636c032f-b0ee-8b1f-998d-bed2869297a0@linux.alibaba.com> Date: Wed, 8 Sep 2021 17:05:09 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210908062603.6723-1-cymi20@fudan.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chenyuan, Thanks for reporting this bug. But the fix looks incorrect. It will commit transaction once more in normal case. The simplest way is calling ocfs2_commit_trans() in each of the error handling path before goto bail. if (status < 0) { ocfs2_commit_trans(osb, handle); mlog_errno(status); goto bail; } Thanks, Joseph On 9/8/21 2:26 PM, Chenyuan Mi wrote: > The reference counting issue happens in two exception handling > paths of ocfs2_replay_truncate_records(). When executing these > two exception handling paths, the function forgets to decrease > the refcount of handle increased by ocfs2_start_trans(), causing > a refcount leak. > > Fix this issue by using ocfs2_commit_trans() to decrease the > refcount of handle in two handling paths. > > Signed-off-by: Chenyuan Mi > Signed-off-by: Xiyu Yang > Signed-off-by: Xin Tan > > --- > fs/ocfs2/alloc.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c > index f1cc8258d34a..b87960cdda0d 100644 > --- a/fs/ocfs2/alloc.c > +++ b/fs/ocfs2/alloc.c > @@ -5941,7 +5941,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, > OCFS2_JOURNAL_ACCESS_WRITE); > if (status < 0) { > mlog_errno(status); > - goto bail; > + goto bail_commit; > } > > tl->tl_used = cpu_to_le16(i); > @@ -5965,7 +5965,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, > num_clusters); > if (status < 0) { > mlog_errno(status); > - goto bail; > + goto bail_commit; > } > } > > @@ -5975,6 +5975,8 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, > > osb->truncated_clusters = 0; > > +bail_commit: > + ocfs2_commit_trans(osb, handle); > bail: > return status; > } >