Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5074501pxb; Mon, 15 Feb 2021 08:50:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUGF4OFUDfsoMLEPI3kO9sXUdqudL8nC6IsCAxb5w2P2+avUrnMqtjU9/TZb6rNmdGxgGu X-Received: by 2002:a17:907:2d10:: with SMTP id gs16mr16632993ejc.0.1613407858025; Mon, 15 Feb 2021 08:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613407858; cv=none; d=google.com; s=arc-20160816; b=DKRHjtIuDfjclyEbtjgiSu6z/Tjwaw6LYRPmX29oRb0WutogcjUnAByZ2KOs6pd531 wEGWHqf7U/JzWhviL9ULTOJqvMnuSYUT8HqX9Vpgh2lR0TsBnbVZ1HdxD6IwyUEXWsI8 1As3lK021mvjlVlBO95h5ScLedDQzfkQM76K6x3BmfjHfGsREVcvOKKqzpyGBiJaQlbQ SZHfc9UWY2+pHy+gbEqcwVnKVqhWdN+wUTdd52Uwx8mtBt/+5EeSGRbGRfkHj9q2Lu42 QUKnr/HbM0zd5LaCAYrvVTv0Cem46lArNjuD+rdYqdU/DuY04OWQzswkCLJQSiW3FdPl NSYw== 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=X2SxAapy3o0E34b+TQTvSPHm5ga6WHoiqJ1yNudEqwjpaT2OBlP/StWeYOUveeV29Q bfNdCWyvzkbGTH5Hsrrm4lrDkwhHzKZbGRNIyBLKQghIXslYQM2BO2BLgUc/JM/Ulcyj nxTE8n2hhYT4jjSFSp8KFhccD7Y2lDw3AbpezkEn9BoqjSZ6iYcbswkV7AESqrEOmAJQ k26EhtD8F+8t37VpgNedvfl8jJD+GC/3IfzcUfdDacXGRQu9cfrR3juFfq8yh79P9Pbz WzMW6drK49VNFP1uqlyToNdGDyRIQMvFlWSjNXiHMg2LjoE93hcBzaljxyoTQJvp4D1c mrqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RJzlntPC; 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 g8si1423218edr.439.2021.02.15.08.50.34; Mon, 15 Feb 2021 08:50:58 -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=RJzlntPC; 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 S232135AbhBOQrz (ORCPT + 99 others); Mon, 15 Feb 2021 11:47:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:49782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230223AbhBOPiO (ORCPT ); Mon, 15 Feb 2021 10:38:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 69EF064EF5; Mon, 15 Feb 2021 15:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403271; bh=CqKua+9AC4BBzGT223pySJUvNsv/Q9xQ2IvYXgmVfvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJzlntPC3PryPfx7sJ0sRZgQkZaVxnUX/QoRdjrIQLJpURqMa5dIJPGd9+dXlRWPo mGj+jsXlFXC5cVDuaNDC0BzICgfYZrBcL45Pfq0LSY/tJgHzi4LCTMdB4XtK2PE3pt nw856qKnrZOpGG6Au524FIOZzyouOaId11XiDwCQ= 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.10 093/104] net: fix iteration for sctp transport seq_files Date: Mon, 15 Feb 2021 16:27:46 +0100 Message-Id: <20210215152722.460127927@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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; }