Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1594869pxb; Thu, 4 Feb 2021 18:00:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxt9qiHRLm1Tffb1mHmaiJg2LL/SL2bES3mGzaBMgmv/67tvam1S9dGPHWoLMT1V77bxaG2 X-Received: by 2002:a17:906:7e42:: with SMTP id z2mr1859278ejr.177.1612490450820; Thu, 04 Feb 2021 18:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612490450; cv=none; d=google.com; s=arc-20160816; b=mpH8AKuPndy5Q4i4Vssk++opL+DY48qYB1CLGdyvpuS5Ar9ZUnOCvisIXZ2ADcEo5p hXabGYcjMYn+CElJS/9CgUSuzEDCBGQUVxha+dODM+9WuGxh5wrcuxYozalT3K+nFeMn 5Rm+NseP1skOdFEeEe2c2rgjrOd75F4ujnaihFE+M28OtAUsRgLHtOw9BFXRHD6MONU6 AjWkEguptCDcYAWtguZkdHX39Wv7Zun9RqYjeQ7y+KWwkdWxXJ1ZnYEvaRhw9tphY7eJ kc93Ur3N/cmNMaWjDNRMa8hYjK9ivX570j6wk8KDfhaGvy4lsZmwxLBkH5kJLQrFL6oK aWHQ== 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:cc:subject:date:to :from; bh=KpI5ltv90s82L24cF2iixGJFwfdq9bwDfHqcVSLj9sE=; b=Ut8yN4RqWikmDMIYBkGh5goP+oss0CJFT3l0SkVhdWuzZPJVUh+tyIag8Nl+BKf411 DA2n/UhKtPyzUfkG3fUYmgDgAn/SP4csnEBe+4g70pqwf9hTnhoAI2PbDL2VA3OAJyim RLyyhGwWPSFhi/DjbAObYMrZ2hnDTDo9qkwlFXPh9iBgp6LL+W/27mK8qHySPT8DpVas RkD/BhSYR9lEDZ5ghOcZrhWjeg02Z9pWbtTU5yPw7dV2/QaPXaXKozGVaZI1Uc2I2cH2 +dO61OYQ5Wsas6Xh3Lv5i4HnBdS4HMFQLzyNFToU5dVTnXvlAyCV5GMEnzpFyfLZ+LMv Ha3Q== 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 w27si4141266ejq.673.2021.02.04.18.00.26; Thu, 04 Feb 2021 18:00:50 -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; 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 S232230AbhBEArr (ORCPT + 99 others); Thu, 4 Feb 2021 19:47:47 -0500 Received: from mx2.suse.de ([195.135.220.15]:38218 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232198AbhBEArm (ORCPT ); Thu, 4 Feb 2021 19:47:42 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9246AAE3F; Fri, 5 Feb 2021 00:47:00 +0000 (UTC) From: NeilBrown To: Andrew Morton , Alexander Viro , Vlad Yasevich , Neil Horman , Marcelo Ricardo Leitner Date: Fri, 05 Feb 2021 11:36:30 +1100 Subject: [PATCH 3/3] net: fix iteration for sctp transport seq_files Cc: Xin Long , linux-kernel@vger.kernel.org, "David S. Miller" , linux-sctp@vger.kernel.org, netdev@vger.kernel.org Message-ID: <161248539022.21478.17038123892954492263.stgit@noble1> In-Reply-To: <161248518659.21478.2484341937387294998.stgit@noble1> References: <161248518659.21478.2484341937387294998.stgit@noble1> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- net/sctp/proc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/net/sctp/proc.c b/net/sctp/proc.c index f7da88ae20a5..982a87b3e11f 100644 --- a/net/sctp/proc.c +++ b/net/sctp/proc.c @@ -215,6 +215,12 @@ static void sctp_transport_seq_stop(struct seq_file *seq, void *v) { 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(struct seq_file *seq, void *v, loff_t *pos) { 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 seq_file *seq, void *v) 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_file *seq, void *v) seq_printf(seq, "\n"); } - sctp_transport_put(transport); - return 0; }