Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2729698imj; Mon, 11 Feb 2019 07:37:47 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib3E4s8iP2Fgt4/3wCfx0Wap2R/Lnca7pHanCdqmfyliI8HdYozdwhKBukkTbY/HAzEr4VF X-Received: by 2002:a17:902:a50a:: with SMTP id s10mr36354157plq.278.1549899467201; Mon, 11 Feb 2019 07:37:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899467; cv=none; d=google.com; s=arc-20160816; b=y9PfbZFp4ENAEDYyrti3D+pTfVSI2R2QN0JNcoiHE856NaYIwF71IKDWbmCs3ygLOV 6YhFZ7+dQ3UcURahpavhtk6dJgKOUq0UrlNkGr5k9GLwiNK95CF4MTZYZGdUb96CkpYU UaVZi5XoQq9KhmeDfNQMyzBs5oh1OR5AlzVtTeVi0UTbTbdsJf0PlTAmCfFdxZ4PsaGM iDDgNWYYDq7uCXhaFRyGunpCpkWDtIAkp6zVbdH2rC+vk/0ik5WBzeiZqpt792L4pnbB jUdZ4Fd+dEAcX/EfaUnMOsnEotDFmfhd7TGxdU2560KgH3sg1jKkqAW8wq7ZcwDoavzL RBBA== 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=NDQxJN2wbkN7aDooAcW4MNOkwTmy8MFJB496bdBW+Xo=; b=gPIGJdcz64PrDWbbxLpOs4l3YQ3f1KZ5xiuTeCUF+rDaPMrZJGs/yiMOUrGGdot0SY Fw+fe3E+RLPzkdV/wdT8ykl6DyB87PdkX3AVx3Zx81Tqm5eV7e/bY7aZhW3T5JY9ZfdY pe2CY9C8p5srWxjoiapXiRubfTXloJHjZqUysViXY97+mPW+kzpDzdIDFXf7iVMPRO3h 7CcfdnqbZkKKMRLlBuk+XYvytxS/XyDm1bIdSf+N4GeRHTXDIfvriFUa41dlHarXdnHl NLLy7ozTh8U3uwDdfeZqqrwz2D31pjb0VxA/NZBtWRwNyxBbPEWQnWpYeodRofdbrumu balA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cYDTEY6B; 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 t18si9430712plr.50.2019.02.11.07.37.30; Mon, 11 Feb 2019 07:37:47 -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=cYDTEY6B; 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 S2388849AbfBKPgk (ORCPT + 99 others); Mon, 11 Feb 2019 10:36:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:37798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387849AbfBKOvl (ORCPT ); Mon, 11 Feb 2019 09:51:41 -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 20F2520844; Mon, 11 Feb 2019 14:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896700; bh=R2Ft30IZYFavJ+BMMfIq6sBjwlwNUn5QVGIaUO4Wt78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cYDTEY6Bvh6Z1QlCWIdXeSdJDpft1bhRMnX+g2/ara5hGQi6pVmxTBVL7ISbdrtJ0 ncsQ7AAUTEqFAk6e/XrK7nOO1AyUvaJE4byhbK0twY2bv2uty4YyRCyckb0MN9GN8Q 8CSre2VPwnYHMTWHSaCsq1XjFfbW6DRFJ32toF5I= 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.19 272/313] sctp: check and update stream->out_curr when allocating stream_out Date: Mon, 11 Feb 2019 15:19:12 +0100 Message-Id: <20190211141911.447906126@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@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.19-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); }