Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp19800imu; Mon, 26 Nov 2018 16:28:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZvKCd2AxKuAbAocliOYa5TRiPk4vyKWCTUb+/AX4693VFRmlTME2CaGEKA3pVHDOc4HV1 X-Received: by 2002:a62:4b4d:: with SMTP id y74mr29018714pfa.186.1543278510861; Mon, 26 Nov 2018 16:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543278510; cv=none; d=google.com; s=arc-20160816; b=RFjtlYgOgcPTAJ6Bs85ak8XN4FMytGYT+P2ENRgVq9hbQBHWDeRX3W+/AWh0/dd1dw DQUsuYtkFx3LzB1SFdBiOdsT2p+WKKti/yhyr0hxBxy1R8Vq/YlOwUyuKHm4y5Tmj3Qs JzsoqKkJYOMdCtox33TdXQIWCyLkliu4+lEJk+B7+2Z8srfOt2JTNQODROLsf0ebmzUe Ulj8yeMDNwaDUnu6k04UOWqwQuGwd1xlwG3jy2UlgT1iZZAaGUWpaP3HRcGbwlE0AY/c EinkNBHxSuQoWY+SGHO0/BoPvAw47i39HRf7Hoo/yBS9KUr7SZ8P0m3x1UA0ov/L6W6B n+3g== 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-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=8KUL6bkNPGbXSPw+V/6mQty5nllCIc0vXGkFSlaw6lc=; b=iiarhm/Tqud8nWrwkt6EEsLWx+L4x6/owQKyqOpOQSftfWSIUZ2KOEP8MS0sUY7foH Dc8fqwQEJMW1bi+8ToJSsAGPiHQHGerhqyKmaLV7+QZeGsarPoGhAm2qZgHVEfzuzWjr zknWFvk+4sDHigL03rbMUGz3cxCMG4z8JdVpzpK0WOwqcmAww0oOf155SnBZDuvjyHoP 6lUCs1MzinxxOGm5QIeB6VIaFIf4iju2RmEfd248EfA7BV0hpNjiOnV9GF/TO2ueZnx0 tlKGIJMn42tv78irxnaq40GPEXZOofkkvi7yA8sXbj6mfVbbwvpqUHHFo16JiTunPLbt Rpww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=ABbokJpA; 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 y7si1766778plk.275.2018.11.26.16.28.15; Mon, 26 Nov 2018 16:28:30 -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=ABbokJpA; 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 S1728002AbeK0LXa (ORCPT + 99 others); Tue, 27 Nov 2018 06:23:30 -0500 Received: from m12-12.163.com ([220.181.12.12]:48545 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727784AbeK0LXa (ORCPT ); Tue, 27 Nov 2018 06:23:30 -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=8KUL6 bkNPGbXSPw+V/6mQty5nllCIc0vXGkFSlaw6lc=; b=ABbokJpAoW1o9akccmf6d qgXJE8Es1We0wb7AD9fOdJQBxi8Pi7Oc6h225i7GwSVxu07aLpfwPkk/hrpVw1B/ UGu3XhjAF4EpwvLoxK/G0nokMAoDLViygQcYjhOlkBE66P1lHLbC5WBXpJnS1a/0 3O+sw/le2AIBgkRoDTI5bQ= Received: from bp (unknown [106.120.213.96]) by smtp8 (Coremail) with SMTP id DMCowACHx3ddj_xb2z+GCA--.22173S2; Tue, 27 Nov 2018 08:27:09 +0800 (CST) Date: Tue, 27 Nov 2018 08:27:10 +0800 From: PanBian To: Brian Foster Cc: Carlos Maiolino , "Darrick J. Wong" , linux-xfs@vger.kernel.org, Dave Chinner , linux-kernel@vger.kernel.org Subject: Re: [PATCH] xfs: libxfs: move xfs_perag_put late Message-ID: <20181127002710.GB109273@bp> Reply-To: PanBian References: <1543052660-58625-1-git-send-email-bianpan2016@163.com> <20181126093139.cgojlmtubzuzdb23@hades.usersys.redhat.com> <20181126103619.GA95394@bp> <20181126141750.GA14585@bfoster> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181126141750.GA14585@bfoster> User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: DMCowACHx3ddj_xb2z+GCA--.22173S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFyUAr15uFy8Cry7JFyftFb_yoW8AFW5pF WfCF1FyF4kKr47C3yIyr48Z340qwsxKrWFgryYgr1xuas8XrnagwsxKryj9F9FgrW8J348 XF4jq393GrnIyFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jmNtsUUUUU= X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzwUMclaD0bPVVQAAsD Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 26, 2018 at 09:17:50AM -0500, Brian Foster wrote: > On Mon, Nov 26, 2018 at 06:36:19PM +0800, PanBian wrote: > > On Mon, Nov 26, 2018 at 10:31:39AM +0100, Carlos Maiolino wrote: > > > On Sat, Nov 24, 2018 at 05:44:20PM +0800, Pan Bian wrote: > > > > The function xfs_alloc_get_freelist calls xfs_perag_put to drop the > > > > reference. In this case, pag may be released. However, > > > > pag->pagf_btreeblks is read and write after the put operation. This may > > > > result in a use-after-free bug. This patch moves the put operation late. > > > > > > > > > > The patch looks reasonable, can you detail more how did you find it? Via code > > > inspection of you hit this user-after-free in some way? > > > > I wrote a tool to check such bugs statically. It first scans the source code > > to extract paired alloc/free functions. Equipped with such functions, it > > performs an intra-procedural data flow analysis to detect mismatched > > alloc/free bugs and use-after-free bugs. > > > > You should probably drop the "use after free" text from your commit log > because that's not how the perag reference counting works. If you look > at xfs_perag_put(), you'll see it only drops a reference count and > returns. We only ever free the perag structs on unmount (or mount > failure), where we assert the refcount is zero. It looks like some other > serialization mechanism would have to break down for that assert to fail > due to this error in the allocation code because the fs is mostly shut > down at this point in time. I will follow your guidance to correct the commit log and resubmit the patch. Thanks, Pan > > Misleading commit log aside, the change seems fine to me. I think it's > appropriate to follow the traditional/implied _get()/_put() pattern. > > Brian > > > Best regards, > > Pan Bian > >