Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp608813ybz; Wed, 15 Apr 2020 15:04:34 -0700 (PDT) X-Google-Smtp-Source: APiQypKatHHw9Gz5E5LRlhvye9wNQ0mh/LpnnLDUnZKs0jAQl0vna1q8KJs/ozah74I2QVlbSHwl X-Received: by 2002:a50:cd89:: with SMTP id p9mr26954500edi.188.1586988274536; Wed, 15 Apr 2020 15:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586988274; cv=none; d=google.com; s=arc-20160816; b=TZkYoK10AKtxDb0bx9p9EL+vi9ZElVErCENRlskhh2KuWnUIAnnl/sUFjFFST3MVOs yAF/ZNTnVYaQDzHxe6zCich1Ql1DS0jIY+tCVk0N7AUN5+KO3DfSImetup7EAK/z3Ipw dXAIDQhUXGQkw8MMegoltROKJt3eel0jipIXTRLYJk/KAkFD8fX2DQ4GGQwfW/XxSDMh JtdnNkiq12rP0cCnOsgSlm3IaxDV/YGCaPJomJYxXZCWnG/UOWKHYwqzJI7HPQ7hH4x4 h9uu2Awb0izPXRNj5K9IwRMSP8DqiaYTDets8rrslNe66S2N+41OaWSXAU0GkRA1hXsD mLbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=LVAQ9J7ES0gVdEpWuTTGWknTSsSV4mYXh79p5m57x78=; b=jE3lWSyqtN8nJkVL1vDfKN92QK5gcKYkKF9KLPsEcYe3kF9e/CWwolM7GbMgwsEeLW uJvW/35TcL9Zo7WY13jRaPWm2cC0oKI2IXGDKZoyYupuCJjA7dYCTgdxQMWd6QHfPZ+x NsftxCLyKPeSJGOfD+vFa2u/BraObzpuQT3EAhbKXCl9mbAUsXz0a8g+OFeXpw/vxvl7 hVXP6nz/J0Sx8zvS8IGraeQPzRr1wIbYjeDu2MWRoYm9LK6QoBjuaWolgTRL8gBqgMiM NJUV1MeI41pbIOwXsAzYzntVfZli8J6Av/h1T3s9QXfyws9f8vCNkXZh6EYIoJbMg8GE +9cw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u22si11718392eja.142.2020.04.15.15.04.10; Wed, 15 Apr 2020 15:04:34 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392890AbgDOCNg (ORCPT + 99 others); Tue, 14 Apr 2020 22:13:36 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:32848 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387984AbgDOCN3 (ORCPT ); Tue, 14 Apr 2020 22:13:29 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6234E7247FE3D8DBD1C0; Wed, 15 Apr 2020 10:13:27 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Wed, 15 Apr 2020 10:13:21 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH v2] f2fs: fix to avoid page count leak Date: Wed, 15 Apr 2020 10:13:13 +0800 Message-ID: <20200415021313.95538-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In f2fs_read_data_pages(), once we add page into radix tree, we need to release reference count of that page, however when f2fs_read_multi_pages() fails, we didn't handle that case correctly, fix it. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu --- v2: - add Fixes tag - improve commit message a bit fs/f2fs/compress.c | 2 +- fs/f2fs/data.c | 6 +++++- fs/f2fs/f2fs.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 498e0c2ba6ea..dbe3fa359a29 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -79,7 +79,7 @@ static void f2fs_drop_rpages(struct compress_ctx *cc, int len, bool unlock) } } -static void f2fs_put_rpages(struct compress_ctx *cc) +void f2fs_put_rpages(struct compress_ctx *cc) { f2fs_drop_rpages(cc, cc->cluster_size, false); } diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 1139d8cf4b8d..22a31e2401cf 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2138,7 +2138,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, } else if (!PageUptodate(page)) { continue; } - unlock_page(page); + f2fs_put_page(page, 1); cc->rpages[i] = NULL; cc->nr_rpages--; } @@ -2303,6 +2303,8 @@ int f2fs_mpage_readpages(struct address_space *mapping, max_nr_pages, &last_block_in_bio, is_readahead, false); + if (ret) + f2fs_put_rpages(&cc); f2fs_destroy_compress_ctx(&cc); if (ret) goto set_error_page; @@ -2346,6 +2348,8 @@ int f2fs_mpage_readpages(struct address_space *mapping, max_nr_pages, &last_block_in_bio, is_readahead, false); + if (ret) + f2fs_put_rpages(&cc); f2fs_destroy_compress_ctx(&cc); } } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index da5e9dd747fa..94d044feffd0 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3803,6 +3803,7 @@ static inline bool f2fs_post_read_required(struct inode *inode) */ #ifdef CONFIG_F2FS_FS_COMPRESSION bool f2fs_is_compressed_page(struct page *page); +void f2fs_put_rpages(struct compress_ctx *cc); struct page *f2fs_compress_control_page(struct page *page); int f2fs_prepare_compress_overwrite(struct inode *inode, struct page **pagep, pgoff_t index, void **fsdata); -- 2.18.0.rc1