Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2749112imj; Mon, 11 Feb 2019 07:56:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IYkEy9cB5JSi1aqzs+DMolGyawi1CNXi2VfQcgmfNwf4G/yK84Gbvv+hxGAnKDyZmycp0AW X-Received: by 2002:a63:fc59:: with SMTP id r25mr19201573pgk.302.1549900563922; Mon, 11 Feb 2019 07:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900563; cv=none; d=google.com; s=arc-20160816; b=V1NFUZfJecytN0lh0yT/4gKrsiSe/P+rnLzuXL1nNp+BO9Zf9vtKcAZTIsw5zelYbS /ugNDjcrU4mVChiZoJGMfTagJyu/usCuBt8PpvoIrxaKbiK793ftDeReN2HvUMG2ruEx E6N496FkT+UM9Mziig445HYnTYX/f9/IZacOnGjfzMs6kxRTUUupPzucjsRoKSiBYDGF clt8Z4ms2nppBc66ZtSi3CMerils/1Jmo5J+P0m5Py26+CpJ5BpIySO5HFTtRsryzra0 owBZFHIanHXXmdUnqWSmIDmtYtf+dTTGHC/+cSS0hnKKtEJSZbi21dlJXuoXskgLAFMp i4Gg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JmL/NYTMmkgHsqOR9CMUB7tYFaGogR8QTg9pwsTfP2Q=; b=r94CvhiCfOaz7PZnhDSia/z56ivonXKSdSAEpnThF5LHoqk2in7CKNvGkpgQm8ba/O 3Fxph1Woc0DY9wKeJXvJxXhQxFFW6yLql7ra+YEDXtS4oFc2eKxOPptES0ac53Fehg3d flSfPWVicv4rQLfxojzO0xWqwC6S+Vg/bZsx7WhuJHJcCSycxBc6fY+ofxYmA0sOZrA9 UM3thysE4GDy309zOytKPzd97DAgtVyaOeMCNhfvGo9nO75touyA3I6u9unPwXs7KHQd /u+t/8E2+tFkyTFZlmdcdgBXu5pnQiIUIrgIiUdEpVJGm1GN8axoXQsHElAjjln/w9te X5bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TWkWpzMA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i129si10974573pfb.32.2019.02.11.07.55.47; Mon, 11 Feb 2019 07:56:03 -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=TWkWpzMA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731068AbfBKOfh (ORCPT + 99 others); Mon, 11 Feb 2019 09:35:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:44234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730749AbfBKOfc (ORCPT ); Mon, 11 Feb 2019 09:35:32 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF07E2081B; Mon, 11 Feb 2019 14:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895732; bh=YmWo7/E7zEpJuMNMDx1Jb54q8BCkAR+VNCHaA/FWrXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWkWpzMA9Za8pqJ1nefLZeOIA2ltGXc0tpuQ9OdkFG5Bb3DKMZ/jQkX5XLRz62UO/ xXYwSCaE3zOxJxYcyslDLyYAnHdKHRKwP+uXEZOR+6Mhjlce9iB54xpa+5f6W/Pwye sCrSQ6JJKhR87RKl5cRceOIkDNjJSs1fFuEMVzxs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ying Xu , syzbot+e33a3a138267ca119c7d@syzkaller.appspotmail.com, Xin Long , Neil Horman , "David S. Miller" Subject: [PATCH 4.20 304/352] sctp: check and update stream->out_curr when allocating stream_out Date: Mon, 11 Feb 2019 15:18:51 +0100 Message-Id: <20190211141906.218437701@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xin Long [ Upstream commit cfe4bd7a257f6d6f81d3458d8c9d9ec4957539e6 ] Now when using stream reconfig to add out streams, stream->out will get re-allocated, and all old streams' information will be copied to the new ones and the old ones will be freed. So without stream->out_curr updated, next time when trying to send from stream->out_curr stream, a panic would be caused. This patch is to check and update stream->out_curr when allocating stream_out. v1->v2: - define fa_index() to get elem index from stream->out_curr. v2->v3: - repost with no change. Fixes: 5bbbbe32a431 ("sctp: introduce stream scheduler foundations") Reported-by: Ying Xu Reported-by: syzbot+e33a3a138267ca119c7d@syzkaller.appspotmail.com Signed-off-by: Xin Long Acked-by: Neil Horman Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/stream.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -84,6 +84,19 @@ static void fa_zero(struct flex_array *f } } +static size_t fa_index(struct flex_array *fa, void *elem, size_t count) +{ + size_t index = 0; + + while (count--) { + if (elem == flex_array_get(fa, index)) + break; + index++; + } + + return index; +} + /* Migrates chunks from stream queues to new stream queues if needed, * but not across associations. Also, removes those chunks to streams * higher than the new max. @@ -147,6 +160,13 @@ static int sctp_stream_alloc_out(struct if (stream->out) { fa_copy(out, stream->out, 0, min(outcnt, stream->outcnt)); + if (stream->out_curr) { + size_t index = fa_index(stream->out, stream->out_curr, + stream->outcnt); + + BUG_ON(index == stream->outcnt); + stream->out_curr = flex_array_get(out, index); + } fa_free(stream->out); }