Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3281703imu; Sat, 24 Nov 2018 01:47:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/WlcZfKhI3I51+ZOp4Da8RegEvQc7Hm1TMLLuWdZXTo0nNjeLwtfYSyQk1K3NWYNFkQJozY X-Received: by 2002:a63:2744:: with SMTP id n65mr17179358pgn.65.1543052867102; Sat, 24 Nov 2018 01:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543052867; cv=none; d=google.com; s=arc-20160816; b=MnX3Bvm6cXUjIzCjOgfEAIjILJhzMqA37nH5TAb0tFAoVYb6wYLRmvTvD3dejviEKw DGyE1Pyd8dJC6pXerRXIYXshf0bXVTcsamcwSNRNZjFX8sWUcslbL/sTFU+FZXNmCPh3 yFd416OzNhU+defP8Pv7Dui+T9qHNc2G3WreyOS99rwhCbqef1COK37GbDz6QEWHqoiW 5jnN8S1+yhru9360//5dhHIP5xOW0uAdTaa6yNyqZuN7kncgPyx5I0663SBLVsjwi6Rv NHJCXCB6sz4cG0ngHU0tJiKtX2gQ03q1XHZ1BJZydwYK7Vh+kjNjZ3Ii1Z2C19wKxseq 9drA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=7cISUyBLpwoif6qmk8OegIZqzP9o3YE8YT9b7KIr0nQ=; b=FRPtgH092wNSrae6SisMrk84TniHJide94gOHzoCpZcjsJ9iqKRUWoeXLJfBgYrJ1P zkjZxk3zQ9+TNy+NYLRIcJB69wJM51y4SFI2Raqx+WaPqweQsn5ccKHYfk1UUB2Qelap YRwbKl4xawsUy1+BCa6ibgSivoykgxitDiCCA3p1jpovA1t2dGZyUcZYCviczXIA1YaP 9H/catTBr6beQWqDsSO7fJi08nWr5uAGBBAE667crOZnErjO3huDxkipnou6UwsvwLzB N2DIJ/T9gBRQ0+t8rJvgzfLvdI1GeBhS6Kiu0tG56OlX0WKsDXe6Pu0Idvrs6+0vBJqS +QzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=YH1V9J4o; 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 t88-v6si24472209pfk.139.2018.11.24.01.47.32; Sat, 24 Nov 2018 01:47:47 -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=YH1V9J4o; 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 S1726106AbeKXUe0 (ORCPT + 99 others); Sat, 24 Nov 2018 15:34:26 -0500 Received: from m12-16.163.com ([220.181.12.16]:57191 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbeKXUe0 (ORCPT ); Sat, 24 Nov 2018 15:34:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=7cISUyBLpwoif6qmk8 OegIZqzP9o3YE8YT9b7KIr0nQ=; b=YH1V9J4oJYWJtcEG9HvIAleze1ReIGVOlM IxkxsD4fk2pRo5X5kkQsPOGSH9vlAFF76r+Evmlw4LGfax5s3Y0is3VX2otppjkk nU537SzCCDJk2tEbCxQa6NWM8WR3cFaFXptOPAhw5C5HIZdaW1n3fUYsF4WqyYFK CoK1S8xco= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp12 (Coremail) with SMTP id EMCowAC3yFNzHflbe0hlBg--.22306S3; Sat, 24 Nov 2018 17:44:23 +0800 (CST) From: Pan Bian To: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org, Brian Foster , Dave Chinner , Carlos Maiolino , linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] xfs: libxfs: move xfs_perag_put late Date: Sat, 24 Nov 2018 17:44:20 +0800 Message-Id: <1543052660-58625-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: EMCowAC3yFNzHflbe0hlBg--.22306S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7JFyrZF4UXFyrur43Kw45Jrb_yoWDCFX_Ka 18KFs7A34ktrW7K3W5X395t3WUtF4fG393WayfJFW3K34UGFn3ZwsrXrn0qF13urWaqFZ8 G3yDGFW3KryYvjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU89Xo7UUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Pan Bian --- fs/xfs/libxfs/xfs_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index e1c0c0d..4be387d 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2435,7 +2435,6 @@ xfs_alloc_get_freelist( be32_add_cpu(&agf->agf_flcount, -1); xfs_trans_agflist_delta(tp, -1); pag->pagf_flcount--; - xfs_perag_put(pag); logflags = XFS_AGF_FLFIRST | XFS_AGF_FLCOUNT; if (btreeblk) { @@ -2443,6 +2442,7 @@ xfs_alloc_get_freelist( pag->pagf_btreeblks++; logflags |= XFS_AGF_BTREEBLKS; } + xfs_perag_put(pag); xfs_alloc_log_agf(tp, agbp, logflags); *bnop = bno; -- 2.7.4