Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1044870pxb; Thu, 9 Sep 2021 18:56:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8TyLWNVhbLZ2zwSqQNBRMWf8ecIxLf6Omn2rQNAgeXZfGc8EEd1Ye20erPcrYq+FkQ6gR X-Received: by 2002:a92:d3c1:: with SMTP id c1mr4689035ilh.194.1631238974576; Thu, 09 Sep 2021 18:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631238974; cv=none; d=google.com; s=arc-20160816; b=lkKahDmNvqM8o6hxBukn9rLOdprvsHWZnNlVIJLDo33WZ4/au7QdRFa76yC8IGHGCR GjJAdbpfHn+Dj/bvpREZGgLqG+JscvZSsBSeNE4NLHRcqcC1XUhGRIpcyljtjj4MH/tt Vy9AUUk9OFVmQus1gDNAppR3mQhc/CA6HXVbLbnUbt2TgWCRReLSgq99rCuO4QwrSWWT M1Y8ET75oWohSGWGhmxv8SSehRxVXeJKWiNWllKF2EHgUF7GgKKMQuMwLObh9XL03kQ9 suy5kK/uvEge1z2hyQENcdbx2xfh6QEsXyw+1A/BPkapF8YoOnMY5WTlSouYSc4lfzWc oNbQ== 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=S2WphXrT0UbC7VoKi8Ww5Xn/DRx2efBilk5eEa5rGUw=; b=H/gMloFhY72mRfjJzh96vSQVkKUlamvn4pQ7Bwg8/bJo00GDJepTeqnjPv8WC5HEAY E09Trm3MzqyTOVfvbCiuTo91zi4Vu/oyFZHFCtFtZgnE6vss9ml1AtfFdfs5fLu1otAi Iv3AStOJ8zmK0961MfY9zso+vqiBTyR/trmyzKlmPR/Lrlu0zbZ3sUNGLc822/g7RefU GYWWNxU7PrrYrugz380SuKlx+D7ZefrJI/CkZQiT5U1EE14e50A1EQiY1X2RveyX+aIZ 1Xmxy24y2sTsVGfsNB1d0bMTNwGaDYIK0XQSVGU4z9de0qBlLQ8j6azIu0C3WVxIdCe4 Z0BA== 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 ay23si3932169iob.33.2021.09.09.18.56.03; Thu, 09 Sep 2021 18:56:14 -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 S229652AbhIJBzM (ORCPT + 99 others); Thu, 9 Sep 2021 21:55:12 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:32992 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbhIJBzM (ORCPT ); Thu, 9 Sep 2021 21:55:12 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R781e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Unqrd8t_1631238837; Received: from B-D1K7ML85-0059.local(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0Unqrd8t_1631238837) by smtp.aliyun-inc.com(127.0.0.1); Fri, 10 Sep 2021 09:53:58 +0800 Subject: Re: [Ocfs2-devel] [PATCH v2] ocfs2: Fix handle refcount leak in two exception handling paths To: Wengang Wang Cc: Chenyuan Mi , akpm , Xin Tan , Xiyu Yang , "yuanxzhang@fudan.edu.cn" , "linux-kernel@vger.kernel.org" , "ocfs2-devel@oss.oracle.com" References: <20210908102055.10168-1-cymi20@fudan.edu.cn> <06d9e055-29b9-731c-5a36-d888f2c83188@linux.alibaba.com> <6018AF95-3613-4D43-A3E6-7BAA0E0BE009@oracle.com> From: Joseph Qi Message-ID: Date: Fri, 10 Sep 2021 09:53:57 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/10/21 1:48 AM, Wengang Wang wrote: > > > On Sep 9, 2021, at 4:07 AM, Joseph Qi > wrote: > > Hi Wengang, > > On 9/9/21 1:12 AM, Wengang Wang wrote: > Hi, > > Sorry for late involving, but this doesn’t look right to me. > > On Sep 8, 2021, at 3:51 AM, Joseph Qi > wrote: > > > > On 9/8/21 6:20 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 > > > Reviewed-by: Joseph Qi > > --- > fs/ocfs2/alloc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c > index f1cc8258d34a..b05fde7edc3a 100644 > --- a/fs/ocfs2/alloc.c > +++ b/fs/ocfs2/alloc.c > @@ -5940,6 +5940,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, > status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh, > OCFS2_JOURNAL_ACCESS_WRITE); > if (status < 0) { > + ocfs2_commit_trans(osb, handle); > mlog_errno(status); > goto bail; > } > @@ -5964,6 +5965,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, > data_alloc_bh, start_blk, > num_clusters); > if (status < 0) { > + ocfs2_commit_trans(osb, handle); > > As a transaction, stuff expected to be in the same handle should be treated as atomic. > Here the stuff includes the tl_bh and other metadata block which will be modified in ocfs2_free_clusters(). > Coming here, some of related meta blocks may be in the handle but others are not due to the error happened. > If you do a commit, partial meta blocks are committed to log. — that breaks the atomic idea, it will cause FS inconsistency. > So what’s reason you want to commit the meta block changes, which is not all of expected, in this handle to journal log? > > Do you really see a hit on the failure? or just you detected the refcount leak by code review? > > You may want to look at ocfs2_journal_dirty() for the error handling part. > > > For the first error handling, since we don't call ocfs2_journal_dirty() > yet, so won't be a problem. > For the second error handling, I think we don't have a better way. Look > at other callers of ocfs2_free_clusters(), we simply ignore the error > code. > Anyway, we should commit transaction if starts, otherwise journal will > be abnormal. > > I don't think so. If error happened, we should fail ocfs2, rather than do a partial committing. > Umm... not exactly... Take ocfs2_free_clusters() for example, when it fails in case of EIO or ENOMEM, we can't just abort journal in such cases, because it is not so serious, only a bit blocks still occupied and they will recovery during the next mount. That's why we have "errors=continue" in most filesystems, we should always consider the business continuity first. Also you can look at ext4_free_blocks() for reference. Thanks, Joseph