From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7347FC4361B for ; Wed, 9 Dec 2020 18:12:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 294EC23C1A for ; Wed, 9 Dec 2020 18:12:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732429AbgLISMb (ORCPT ); Wed, 9 Dec 2020 13:12:31 -0500 Received: from verein.lst.de ([213.95.11.211]:51014 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731010AbgLISMa (ORCPT ); Wed, 9 Dec 2020 13:12:30 -0500 Received: by verein.lst.de (Postfix, from userid 2407) id B262868B02; Wed, 9 Dec 2020 19:11:48 +0100 (CET) Date: Wed, 9 Dec 2020 19:11:48 +0100 From: Christoph Hellwig To: Damien Le Moal Cc: linux-fsdevel@vger.kernel.org, Johannes Thumshirn , Christoph Hellwig Subject: Re: [PATCH] zonefs: fix page reference and BIO leak Message-ID: <20201209181148.GA21836@lst.de> References: <20201209113738.300930-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201209113738.300930-1-damien.lemoal@wdc.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Dec 09, 2020 at 08:37:38PM +0900, Damien Le Moal wrote: > In zonefs_file_dio_append(), the pages obtained using > bio_iov_iter_get_pages() are not released on completion of the > REQ_OP_APPEND BIO and when bio_iov_iter_get_pages() fails. Fix this by > adding the missing calls to bio_release_pages() before returning. > Furthermore, a call to bio_put() is missing when > bio_iov_iter_get_pages() fails. Add it to avoid leaking the BIO > allocated. The call to bio_io_error() is removed from this error path > as the error code is returned directly to the caller. > > Reported-by: Christoph Hellwig > Fixes: 02ef12a663c7 ("zonefs: use REQ_OP_ZONE_APPEND for sync DIO") > Cc: stable@vger.kernel.org > Signed-off-by: Damien Le Moal > --- > fs/zonefs/super.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c > index ff5930be096c..eb5d1db018e1 100644 > --- a/fs/zonefs/super.c > +++ b/fs/zonefs/super.c > @@ -692,7 +692,8 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) > > ret = bio_iov_iter_get_pages(bio, from); > if (unlikely(ret)) { > - bio_io_error(bio); > + bio_release_pages(bio, false); > + bio_put(bio); > return ret; > } > size = bio->bi_iter.bi_size; > @@ -703,6 +704,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) > > ret = submit_bio_wait(bio); > > + bio_release_pages(bio, false); > bio_put(bio); > > zonefs_file_write_dio_end_io(iocb, size, ret, 0); I think it might be a good idea to move the calls to bio_release_pages and bio_put after zonefs_file_write_dio_end_io and then jump to them from the above error case. That keeps the resource unwinding in a single place.