Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp724269pxb; Wed, 8 Sep 2021 10:47:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzGOpCfZKRQp7WPPiKdgt8G49cm+OlF0O0wJ+rMB88xvEDOLmrARFiC3AoN1qbd7Nm/ox6 X-Received: by 2002:a05:6e02:503:: with SMTP id d3mr807297ils.107.1631123237939; Wed, 08 Sep 2021 10:47:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631123237; cv=none; d=google.com; s=arc-20160816; b=CwyDa2tAtE9HkeESpZrhbk5GpXdOn/aBLPttpwBAOZgdXVXqVJkrO9qIZsF1Ca4JUS QD8lrTOkpn7NHwcyYxqDu5/QmC3Tisqy7mwGZvl5qPQSK87WGoxCQpPzRpv7q8OqXDsi C4eGGc6ZxKCx4dyJ5k00IZIr11fa2mgHbVhUvGP518aRvOz940WWpXjluxUJa8dHqlGN J7Zwc71RWzEPAygsxwy1htn6K0+xj/DpZ0Yu7Vnc36wJqGOJomLiOV/1jSTADoKRCtqf rTD6OGjjlkWJ+SNs3PC1KomPORkr3oQn3xYqIiPDMQmAx2oBsPZI5eNr9NAOmJ4Rq4Ca Cc1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=wIYOIZTjSumo0cZjZ+r3pqvQFMtN5uYJIKOnJtD04/o=; b=poxR6jgAEwi5mOZQ7NcdaSAYKxvSr3lV2ogg1Ey9FiEp9MEopR3TlGQ9HWyMmMrNEA sOOqROiwgVQx88BMnvre9aP9JjafhJ8UHYo6axf5zNmYRFM0HBbvmzGib6IphTpA4wVm BZGdFib/N2D/1cJIDBaqEXV5VTK1rJZlgT8lwIIjEaIRnD6tx07Qd5vJpGyzr3dPKUmU j6DhNfPFuhcbVJKXsNiM/h7kMd3b1TOt9XubIvOSFzzUc3fGrY6UwYvgeF+XtqBYR1wv wsx3g9t4nJawCjflN+lDLwpne5DHFO1mU/quMNhq5kfo/auVX3apUA83po4A1U7PjSiW LqSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PsX3QHBy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u3si3063889iom.82.2021.09.08.10.47.05; Wed, 08 Sep 2021 10:47:17 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PsX3QHBy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352213AbhIHP6w (ORCPT + 99 others); Wed, 8 Sep 2021 11:58:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53595 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352227AbhIHP6v (ORCPT ); Wed, 8 Sep 2021 11:58:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631116663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wIYOIZTjSumo0cZjZ+r3pqvQFMtN5uYJIKOnJtD04/o=; b=PsX3QHBylRXyxxVqG/WcxByaVSGahPD6L+DUkrpsIxBTPewnIp+UerG7hDry4dtnV8s6Ci 8u3ysc5zkf+RCJs4pisbQHX8U0z3oDg4CX98YXO/dAGB+FpkB4EoEWnHD/Hy4JYWMFhQA0 mpgX9wDyr6TCRkBymchcyLeuk7s/gB0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-ALKHmArIND-X1cA0CTMYxA-1; Wed, 08 Sep 2021 11:57:42 -0400 X-MC-Unique: ALKHmArIND-X1cA0CTMYxA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20025801A92; Wed, 8 Sep 2021 15:57:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id F017C5D9C6; Wed, 8 Sep 2021 15:57:39 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 1/6] afs: Fix missing put on afs_read objects and missing get on the key therein From: David Howells To: linux-afs@lists.infradead.org Cc: Marc Dionne , dhowells@redhat.com, markus.suvanto@gmail.com, Marc Dionne , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 08 Sep 2021 16:57:39 +0100 Message-ID: <163111665914.283156.3038561975681836591.stgit@warthog.procyon.org.uk> In-Reply-To: <163111665183.283156.17200205573146438918.stgit@warthog.procyon.org.uk> References: <163111665183.283156.17200205573146438918.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)