Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3710774imu; Mon, 28 Jan 2019 09:26:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN5kJHewyafa/KeNoyGiNFk3m4os+GU1EUL3oF4CWCgdmAKucIM3zuUOTKHMlQFH7UUfU0J3 X-Received: by 2002:a17:902:2ac3:: with SMTP id j61mr22557930plb.185.1548696376347; Mon, 28 Jan 2019 09:26:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696376; cv=none; d=google.com; s=arc-20160816; b=WVNS28EPtjgzZSGruDtmYSaRuIH5wzyD4OKpq30EcPYgMBvlhksSxg/j4ttTtc0sBo AEJ9///4j/+nOTNtwUAWSTO3aMEQ3LhQqchqlb93vpXgqbYtn8lMhmNDHuSwKZD/FS2n kPuP+/zsTM0PNjC29dhTYvBFkVWkEGLqUf7HMezOtXrVPASN8JguCfm3Ph0VJuG7WSbR NtAGBFMdhH7gb+5ezGMR+WJNtxK5PBTM0VV5cr6b+r2nnfLqylWUrq2k2egP/Sgr/aNW cC4LAHQxHZfZp7/mQ5y0rBJMl9aOsQQG0D0FZkkEMzxS8HwBVtOsCQAIhogI7hKI2lPh PBLQ== 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=TyI8hrZXAE/3MOytqOLnQguW3ZpiB6Yve3D9hKyUjsg=; b=pI8UeGikIETNYnzjgmCoBIUUXdqWH9Xzu02HDUqalTl8TAYWYgzH5qu2O5j0SxpKTA NQCtDteLatHE5EIrPXmzudGb1e4XAUIic3Cir00M/LRqK8dM38wYxMG6eGfDjmuleSfR 82IJBFI0beCm4szV/irPxtazA8SIPrw+FFrwkvawwUyD28k75lX8Cs3uiFLmCLXkLqNg acLwYhXQpRnsRnk74ty+OeQ7CWe5XL6o30lB8JD46i2+mwZ3ES9fZa+7+lAbxfzjE497 cpSgf/bs12QdRCar10dm4O6U+BCljDDn24EFFXSnuVHezYIf5UqvrxCCXlTfBMq7Dv9k SU0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V6/fSta1"; 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 f4si476236pgg.492.2019.01.28.09.26.00; Mon, 28 Jan 2019 09:26:16 -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="V6/fSta1"; 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 S1728076AbfA1QA4 (ORCPT + 99 others); Mon, 28 Jan 2019 11:00:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:46202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730862AbfA1QAy (ORCPT ); Mon, 28 Jan 2019 11:00:54 -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 AB1F82175B; Mon, 28 Jan 2019 16:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691253; bh=Gu/bul+kriYcN94uMrAWo0kYYB3ZX3NjGr/JJYtEsAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V6/fSta1O/uUeoo6huvfrICdD77myvzd/8Pe0Np2Z0yh+AB1dOvE3P4v7/2oDTkQ4 NbPkOHK6NN2MXNIbXPALkZ1Dn5rbCAMKEDxZi75GA0Naws7/scR/km08eFlBoW883D SOFgvl0AZ1K0d/oCom8ovZZ5UbQo5jVb1W9WU1FQ= 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 033/258] sctp: Fix SKB list traversal in sctp_intl_store_ordered(). Date: Mon, 28 Jan 2019 10:55:39 -0500 Message-Id: <20190128155924.51521-33-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 e15e067d0656625c77c52b4e5f0cfbf0c0c3583f ] Same change as made to sctp_intl_store_reasm(). 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 0a78cdf86463..500449b72eca 100644 --- a/net/sctp/stream_interleave.c +++ b/net/sctp/stream_interleave.c @@ -383,7 +383,7 @@ static void sctp_intl_store_ordered(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->lobby); if (!pos) { @@ -403,18 +403,25 @@ static void sctp_intl_store_ordered(struct sctp_ulpq *ulpq, return; } + loc = NULL; skb_queue_walk(&ulpq->lobby, pos) { cevent = (struct sctp_ulpevent *)pos->cb; - if (cevent->stream > event->stream) + if (cevent->stream > event->stream) { + loc = pos; break; - + } if (cevent->stream == event->stream && - MID_lt(event->mid, cevent->mid)) + MID_lt(event->mid, cevent->mid)) { + loc = pos; break; + } } - __skb_queue_before(&ulpq->lobby, pos, sctp_event2skb(event)); + if (!loc) + __skb_queue_tail(&ulpq->lobby, sctp_event2skb(event)); + else + __skb_queue_before(&ulpq->lobby, loc, sctp_event2skb(event)); } static void sctp_intl_retrieve_ordered(struct sctp_ulpq *ulpq, -- 2.19.1