Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5046569pxb; Mon, 15 Feb 2021 08:09:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMHCXw2yK3o/Ky/s304UclPJd2pPIc/K5rs6rocvNYcpTn1ttjNTZiv/GkAcY66c3wyPWm X-Received: by 2002:a17:906:34c3:: with SMTP id h3mr16168089ejb.132.1613405372921; Mon, 15 Feb 2021 08:09:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613405372; cv=none; d=google.com; s=arc-20160816; b=Z9culVsE0VoibWX7YVSeQFsitPbmvDXOMAZtdRZysjp7m5OBma72bjoITCiONMzx9s h2N0ClTqSpk8tICaIai/fvilwDKbkkIhDEOM5ek8vni5xPlKfF6UQoUHguhA3w4RKxUN v88MS4jrQ8bkG2Qe4Gs/HmxJ6ONiEjKUQYpYm4KwxY+Nfz/28sMVZXicQj9AAkVhqfHq WRK2a7SYIYTBaMhn3b3Q6B6NBoxInlNRiecU5qPTy6OTTz4ddowVys6mkM85efJNx0sc YMZVPt0nnqmHa1BuDZlZKD7Y2rrodPFWOG58d3fI0/xsp0yfeZlZF/0NYpA7OmUfP6Jg W3CQ== 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:subject:cc:to :from:dkim-signature; bh=OIVLJaSKaB708G5O0OJIBGM3pIVwjhmDvinpD00GAsA=; b=OOMknpC9ri72Ma2qicqcy36YAupsuVlp9BxKxdCRe56F/5b5RoS3L0zzWbzG3rzIRf iMrMtZAvjTqrmuuFGoNJhjXHjtsLx+vDL3B34gZTylXA0RJjuSOrKAyCUJpp8TV0Ph7s zORIyUpfac9M/QOToom/Xj+NmpxE4q/N6opyvUW/DPathBobRYGwY0DLmpvHNyZ0kM2m Xx879g4iPVUiwmhmH8O+cAYuc0w3p+CwgMZa9OT/7AavtHgyYoi/B6/6zmt8abUakv6B JXQL3rK6405+5JYk53CHd2oOdU6mASvrgJwZWw4EWdgNemUCShWfiEuHgAXQm95Luovq MLOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LHHhXs2L; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck13si12145683edb.505.2021.02.15.08.09.09; Mon, 15 Feb 2021 08:09:32 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=LHHhXs2L; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbhBOQH3 (ORCPT + 99 others); Mon, 15 Feb 2021 11:07:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:45434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbhBOPdE (ORCPT ); Mon, 15 Feb 2021 10:33:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD0DF64EB2; Mon, 15 Feb 2021 15:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403033; bh=CqKua+9AC4BBzGT223pySJUvNsv/Q9xQ2IvYXgmVfvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LHHhXs2LVd6hSSQJMV8hgLQ3uYyejLdgjtBJtmHwdTSk/QKeoVazvTGWl5lhb7/No NSnrqKyf3u2mA4SMl3yGOxPeHrqM6psxLMs/A/L48Pvp4fMRycet/6ML7DSycfu21H vh8XyWFFhD4Z7k4DrevI6rQpCoQtYpbxs5Iqjp7Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , NeilBrown , Marcelo Ricardo Leitner , Jakub Kicinski Subject: [PATCH 5.4 53/60] net: fix iteration for sctp transport seq_files Date: Mon, 15 Feb 2021 16:27:41 +0100 Message-Id: <20210215152717.077186043@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown commit af8085f3a4712c57d0dd415ad543bac85780375c upstream. The sctp transport seq_file iterators take a reference to the transport in the ->start and ->next functions and releases the reference in the ->show function. The preferred handling for such resources is to release them in the subsequent ->next or ->stop function call. Since Commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") there is no guarantee that ->show will be called after ->next, so this function can now leak references. So move the sctp_transport_put() call to ->next and ->stop. Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") Reported-by: Xin Long Signed-off-by: NeilBrown Acked-by: Marcelo Ricardo Leitner Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/sctp/proc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/net/sctp/proc.c +++ b/net/sctp/proc.c @@ -215,6 +215,12 @@ static void sctp_transport_seq_stop(stru { struct sctp_ht_iter *iter = seq->private; + if (v && v != SEQ_START_TOKEN) { + struct sctp_transport *transport = v; + + sctp_transport_put(transport); + } + sctp_transport_walk_stop(&iter->hti); } @@ -222,6 +228,12 @@ static void *sctp_transport_seq_next(str { struct sctp_ht_iter *iter = seq->private; + if (v && v != SEQ_START_TOKEN) { + struct sctp_transport *transport = v; + + sctp_transport_put(transport); + } + ++*pos; return sctp_transport_get_next(seq_file_net(seq), &iter->hti); @@ -277,8 +289,6 @@ static int sctp_assocs_seq_show(struct s sk->sk_rcvbuf); seq_printf(seq, "\n"); - sctp_transport_put(transport); - return 0; } @@ -354,8 +364,6 @@ static int sctp_remaddr_seq_show(struct seq_printf(seq, "\n"); } - sctp_transport_put(transport); - return 0; }