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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 C10B7C433F5 for ; Fri, 10 Sep 2021 21:10:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3B1961208 for ; Fri, 10 Sep 2021 21:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234348AbhIJVMH (ORCPT ); Fri, 10 Sep 2021 17:12:07 -0400 Received: from mail-ej1-f44.google.com ([209.85.218.44]:33770 "EHLO mail-ej1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229655AbhIJVMG (ORCPT ); Fri, 10 Sep 2021 17:12:06 -0400 Received: by mail-ej1-f44.google.com with SMTP id x11so6963472ejv.0; Fri, 10 Sep 2021 14:10:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9UmuHpu0cKxiQt++F9TGuOrk3G7S1/A6mYH0c36xdco=; b=LMGsPbnBR4xPj4P/2VKlJK91kBvwIcDypk7lTJ9QzVtaArQNaOuR2udX55GaZ10gYI F9m2/0JgvR1YuU28sBnnat1X1WsXP8GcK86EY+XPFDfxJhDFFjMLQ3MxN3mLu2uXpot2 eFhQWp2nRmiQToyYPAfNfJEYfCosMlBktBs3qlnbtB9q0NLzX4+BTwdwcSyQ1MP+Ei/l jfk+UT6WN1yaFXHDcuDr1tp9Rte9CvfnTAGrzO8DQfTCM2N4YvgNWaTbzxegpeA4iYSy pKgrAxZoxxgTVmi45l4Sot4Kg5hA4zXr0i6G3JpGVlq9NPBYeRTDJsXLXFPjDe5gnERe Fw/g== X-Gm-Message-State: AOAM530VQ76wXYXd9l+o2C1+zPQfekKo1+FhSX+aXbV3wY8DtiAKcuUM 4qgPL6wTiJEKHmBuMnE825+ku9s13no= X-Google-Smtp-Source: ABdhPJznWasfW90FIjz/BZqRStamQExSrh6n2KZMW+zQlaX3aghygulRK5Ci6yyFmhpHNynB+tx60A== X-Received: by 2002:a17:906:a3d9:: with SMTP id ca25mr3739305ejb.306.1631308253495; Fri, 10 Sep 2021 14:10:53 -0700 (PDT) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com. [209.85.221.47]) by smtp.gmail.com with ESMTPSA id i6sm2860344ejd.57.2021.09.10.14.10.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Sep 2021 14:10:53 -0700 (PDT) Received: by mail-wr1-f47.google.com with SMTP id w29so3685359wra.8; Fri, 10 Sep 2021 14:10:53 -0700 (PDT) X-Received: by 2002:adf:e349:: with SMTP id n9mr12196570wrj.326.1631308253036; Fri, 10 Sep 2021 14:10:53 -0700 (PDT) MIME-Version: 1.0 References: <163111665183.283156.17200205573146438918.stgit@warthog.procyon.org.uk> <163111665914.283156.3038561975681836591.stgit@warthog.procyon.org.uk> In-Reply-To: <163111665914.283156.3038561975681836591.stgit@warthog.procyon.org.uk> From: Marc Dionne Date: Fri, 10 Sep 2021 18:10:42 -0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/6] afs: Fix missing put on afs_read objects and missing get on the key therein To: David Howells Cc: linux-afs@lists.infradead.org, Markus Suvanto , linux-fsdevel@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 8, 2021 at 12:58 PM David Howells wrote: > > The afs_read objects created by afs_req_issue_op() get leaked because > afs_alloc_read() returns a ref and then afs_fetch_data() gets its own ref > which is released when the operation completes, but the initial ref is > never released. > > Fix this by discarding the initial ref at the end of afs_req_issue_op(). > > This leak also covered another bug whereby a ref isn't got on the key > attached to the read record by afs_req_issue_op(). This isn't a problem as > long as the afs_read req never goes away... > > Fix this by calling key_get() in afs_req_issue_op(). > > This was found by the generic/074 test. It leaks a bunch of kmalloc-192 > objects each time it is run, which can be observed by watching > /proc/slabinfo. > > Fixes: f7605fa869cf ("afs: Fix leak of afs_read objects") > Reported-by: Marc Dionne > Signed-off-by: David Howells > cc: linux-afs@lists.infradead.org > Link: https://lore.kernel.org/r/163010394740.3035676.8516846193899793357.stgit@warthog.procyon.org.uk/ > --- > > fs/afs/file.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/afs/file.c b/fs/afs/file.c > index db035ae2a134..6688fff14b0b 100644 > --- a/fs/afs/file.c > +++ b/fs/afs/file.c > @@ -295,7 +295,7 @@ static void afs_req_issue_op(struct netfs_read_subrequest *subreq) > fsreq->subreq = subreq; > fsreq->pos = subreq->start + subreq->transferred; > fsreq->len = subreq->len - subreq->transferred; > - fsreq->key = subreq->rreq->netfs_priv; > + fsreq->key = key_get(subreq->rreq->netfs_priv); > fsreq->vnode = vnode; > fsreq->iter = &fsreq->def_iter; > > @@ -304,6 +304,7 @@ static void afs_req_issue_op(struct netfs_read_subrequest *subreq) > fsreq->pos, fsreq->len); > > afs_fetch_data(fsreq->vnode, fsreq); > + afs_put_read(fsreq); > } > > static int afs_symlink_readpage(struct page *page) Tested that it prevents the leak of about 49K kmalloc-192 objects for a run of generic/074. Reviewed-and-tested-by: Marc Dionne Marc