From patchwork Wed May 3 13:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 89755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1348472vqo; Wed, 3 May 2023 06:59:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dlYhHAwP9182bSwSMKeR3T2pY5OOoyNML75cWYmpWoqp4EwvfRaMjVA8ihtXmw5Xyr4rx X-Received: by 2002:a05:6a21:32a7:b0:f4:7cbd:c236 with SMTP id yt39-20020a056a2132a700b000f47cbdc236mr27215829pzb.54.1683122397655; Wed, 03 May 2023 06:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683122397; cv=none; d=google.com; s=arc-20160816; b=D3WCJoYhmAgnAfIl35qTvxqSXLe6NGpK0rDRbv7wLRsTG2Szy/p/vo2jqTa921iJck X7Wc8MIUUxWxXmm6Z3AGb3qmQe8oc1Y6T0s411Lac5TU/q7CF5BEGBkTNZJc/jquukxk UESuS904sDNi95Mfv8Tft7UfoBmf8sojufExMy3E8Gg7+ZsvudNFm+ee02H1FETEItUm 2CQqmX4mRtT8fvT/XeeBKMAcFahcPxPFAWuLX6OGPnzTC8LT6ZdeeIvHnd6Q109CPUos EArk8Pqwk9YiSXsKrve6yiV4T6jK5XvU46WUJhqE3m3kWikMC5Byex6u8UqguuJZfP67 LIJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-filter; bh=GnrCJpVJCNk0NV1fxPQBwc/dFUx7eKHwkbX2sWg9ynY=; b=0P4fOAzH77WCeC9avLcJRe6av0gQ0wKgW2Cp5lVYDWIXhk594lzC/4Eqxlz26ZIdMp pXoR0y8ABad4Eyz+W7W2shoQ/Fa8s07VcYdWW8WY78QS/sKbLDK7IiLNXYZ9hoTzJGgu IsZ6W/pXrTT9h+nj5FN1a7JQ4BmYIbFPsHFA2colAiuRNOY1UpT/3/DTWq+XPq3wp8oj KNsqESwN2NISBlQPiAhr9gUhdnrALZIoAxLp0ARgcIwcPezrJ6lugLgEiJtvAa4TA9Bt 9QQb2kUBc/RcnGLpj54QY0llEZCiiGfR5yAxo34I4lLxxzzaui85MV8HM+1jxuk3uU0w 6UwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=rfCGWQgj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w30-20020aa79a1e000000b00640d906a8f3si23568214pfj.245.2023.05.03.06.59.45; Wed, 03 May 2023 06:59:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=rfCGWQgj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbjECNiG (ORCPT + 99 others); Wed, 3 May 2023 09:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbjECNiF (ORCPT ); Wed, 3 May 2023 09:38:05 -0400 Received: from mx0.infotecs.ru (mx0.infotecs.ru [91.244.183.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD0E2D4E; Wed, 3 May 2023 06:38:02 -0700 (PDT) Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 206DB11226F0; Wed, 3 May 2023 16:38:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 206DB11226F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1683121080; bh=GnrCJpVJCNk0NV1fxPQBwc/dFUx7eKHwkbX2sWg9ynY=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=rfCGWQgjOiqjKlrbomwavwKOtmfxAVYvsgPfwOheu2TNVitZAKzLL1Pe2YZxGYPeb PXolZKZqCI5KuAz6eu/FKPD3d4Nd2tTql1o74wH69XZwxfr4Ke+xHOXvf+KvcK2Pfr mWhohTwaeU2AdI6jTpMXx1aoLfNWsC5DxcVA9xH8= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id 06C7730B5781; Wed, 3 May 2023 16:38:00 +0300 (MSK) From: Gavrilov Ilia To: Marcelo Ricardo Leitner CC: Simon Horman , Neil Horman , Xin Long , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "linux-sctp@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" Subject: [PATCH net v4] sctp: fix a potential OOB access in sctp_sched_set_sched() Thread-Topic: [PATCH net v4] sctp: fix a potential OOB access in sctp_sched_set_sched() Thread-Index: AQHZfcR5cbjfVOs8NkmtkUREhiTeCg== Date: Wed, 3 May 2023 13:37:59 +0000 Message-ID: <20230503133752.4176720-1-Ilia.Gavrilov@infotecs.ru> References: In-Reply-To: Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.17.0.10] x-exclaimer-md-config: 208ac3cd-1ed4-4982-a353-bdefac89ac0a MIME-Version: 1.0 X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 177146 [May 03 2023] X-KLMS-AntiSpam-Version: 5.9.59.0 X-KLMS-AntiSpam-Envelope-From: Ilia.Gavrilov@infotecs.ru X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Auth: dkim=none X-KLMS-AntiSpam-Info: LuaCore: 510 510 bc345371020d3ce827abc4c710f5f0ecf15eaf2e, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;infotecs.ru:7.1.1;127.0.0.199:7.1.2 X-MS-Exchange-Organization-SCL: -1 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, bases: 2023/05/03 11:29:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2023/05/03 11:33:00 #21212261 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764881751090875356?= X-GMAIL-MSGID: =?utf-8?q?1764881751090875356?= The 'sched' index value must be checked before accessing an element of the 'sctp_sched_ops' array. Otherwise, it can lead to OOB access. Note that it's harmless since the 'sched' parameter is checked before calling 'sctp_sched_set_sched'. Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org) with SVACE. Reviewed-by: Xin Long Reviewed-by: Simon Horman Signed-off-by: Ilia.Gavrilov Acked-by: Marcelo Ricardo Leitner --- V2: - Change the order of local variables - Specify the target tree in the subject V3: - Change description - Remove 'fixes' V4: - revert to V2 net/sctp/stream_sched.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/sctp/stream_sched.c b/net/sctp/stream_sched.c index 330067002deb..4d076a9b8592 100644 --- a/net/sctp/stream_sched.c +++ b/net/sctp/stream_sched.c @@ -146,18 +146,19 @@ static void sctp_sched_free_sched(struct sctp_stream *stream) int sctp_sched_set_sched(struct sctp_association *asoc, enum sctp_sched_type sched) { - struct sctp_sched_ops *n = sctp_sched_ops[sched]; struct sctp_sched_ops *old = asoc->outqueue.sched; struct sctp_datamsg *msg = NULL; + struct sctp_sched_ops *n; struct sctp_chunk *ch; int i, ret = 0; - if (old == n) - return ret; - if (sched > SCTP_SS_MAX) return -EINVAL; + n = sctp_sched_ops[sched]; + if (old == n) + return ret; + if (old) sctp_sched_free_sched(&asoc->stream);