Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3625201imu; Mon, 28 Jan 2019 08:03:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN6W+g4MWFNVPSPPhfXtUdAl5v9s26oSPy3hVDbDRTvYz/B30XB1TnooFLnx5ZuYiRfj4LCY X-Received: by 2002:a62:db41:: with SMTP id f62mr22840280pfg.123.1548691399536; Mon, 28 Jan 2019 08:03:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691399; cv=none; d=google.com; s=arc-20160816; b=0Re/fvlARmCgGU6Y3wb6zVh03XO+5Q2OVbnqpIwvkT8sDMlCddXx3jgV7nTpruHsLK +uHSHokm+OjuDAznScCVIVir4JAXx/vKDe/6Z98cDIRaZk1t64yMKlO7yHisDRPMdVzo B6T5S0XBDNdnCB1rv4uPjN0BZANa/D2AJk4dXJFyeNP2JWD7Jj16CPZsch9mv95osKnk pOuz403Y7peaTY8W0lxKUU3y3w2FHrVhtYzlvcB+u4T3g/nlkHb63HlGPLlWrWimM+xW xhN4E72Tg65mgpO8UuqJe/k137nwLL880GhBLBuWVgOjLyBom4R5y9ODasm21QiktAJR 63FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WAkqWvRNo9hMvwrmgZnAZ0sPZWBo4v/3a/ll0UzEmOo=; b=SaVDCHPcYY55EBGnRSAc2X+r6ovY31J5al6HlrBNjHIIr6s+Ngh24AHEpL0ElQh3FV lWLoEit4en8RwPkmQgv2J/3cedRVPeGWK8e5LrOxtDaeGME1zdlu47+h+Vs6yOla7iId 6T+lytmvDDWLOcjJXzC//8ejZ2fsOFBVe+/zZcXCbbSx4KuQxiaPkjCands0g/Wm1QKi RzRNjsjei/vrU/eQxzdGJV4eyzYbSK9IE0oW8MdE+lV6Nq69/1P1CcFuKifqbayK3nit ai9fJdUMgHWYEYZXisPVZjecO567zUqHeCLgOSlD46gpZc5n7OnTinfCQl+0p8p1a8Zf 1Qcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0Nj0afq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si14125420pgt.498.2019.01.28.08.03.03; Mon, 28 Jan 2019 08:03:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0Nj0afq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730894AbfA1QA7 (ORCPT + 99 others); Mon, 28 Jan 2019 11:00:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:46216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730525AbfA1QA4 (ORCPT ); Mon, 28 Jan 2019 11:00:56 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F121321848; Mon, 28 Jan 2019 16:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691255; bh=NthfVLmFK4e51EX0vCEjH2dF1Fxphnp2dyblMH1Fims=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z0Nj0afq3laPzK4gymDQs/58jcOORWhwNvGrC0SBMZ9eQZOY6I92wThrr34ta/mbL 2cUI3BPpCYBrPaXmgRv1lxXKtX215ip4ow/uVD7kj147MESYgGybrUldcbuACjOAL1 dd0ifpWdLsa9YBIgog6EJoeWzKSQm7pqZJtpGkUA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "David S. Miller" , Sasha Levin , linux-sctp@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 034/258] sctp: Fix SKB list traversal in sctp_intl_store_reasm(). Date: Mon, 28 Jan 2019 10:55:40 -0500 Message-Id: <20190128155924.51521-34-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "David S. Miller" [ Upstream commit 348bbc25c40844c5efa083a3842c7f53d70a815e ] To be fully correct, an iterator has an undefined value when something like skb_queue_walk() naturally terminates. This will actually matter when SKB queues are converted over to list_head. Formalize what this code ends up doing with the current implementation. Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/stream_interleave.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/net/sctp/stream_interleave.c b/net/sctp/stream_interleave.c index 500449b72eca..2b499a85db0e 100644 --- a/net/sctp/stream_interleave.c +++ b/net/sctp/stream_interleave.c @@ -140,7 +140,7 @@ static void sctp_intl_store_reasm(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event) { struct sctp_ulpevent *cevent; - struct sk_buff *pos; + struct sk_buff *pos, *loc; pos = skb_peek_tail(&ulpq->reasm); if (!pos) { @@ -166,23 +166,30 @@ static void sctp_intl_store_reasm(struct sctp_ulpq *ulpq, return; } + loc = NULL; skb_queue_walk(&ulpq->reasm, pos) { cevent = sctp_skb2event(pos); if (event->stream < cevent->stream || (event->stream == cevent->stream && - MID_lt(event->mid, cevent->mid))) + MID_lt(event->mid, cevent->mid))) { + loc = pos; break; - + } if (event->stream == cevent->stream && event->mid == cevent->mid && !(cevent->msg_flags & SCTP_DATA_FIRST_FRAG) && (event->msg_flags & SCTP_DATA_FIRST_FRAG || - event->fsn < cevent->fsn)) + event->fsn < cevent->fsn)) { + loc = pos; break; + } } - __skb_queue_before(&ulpq->reasm, pos, sctp_event2skb(event)); + if (!loc) + __skb_queue_tail(&ulpq->reasm, sctp_event2skb(event)); + else + __skb_queue_before(&ulpq->reasm, loc, sctp_event2skb(event)); } static struct sctp_ulpevent *sctp_intl_retrieve_partial( -- 2.19.1