From patchwork Wed May 10 09:23:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 91999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3488777vqo; Wed, 10 May 2023 02:41:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mcL2b2sWT2dIKICQMw56lLckgL3pZnS7G5Zi7q2GY1wgHA7qv1MVz/4ySFsSXpieGysvg X-Received: by 2002:a05:6a20:7f92:b0:ff:aa2c:427a with SMTP id d18-20020a056a207f9200b000ffaa2c427amr17440245pzj.19.1683711698582; Wed, 10 May 2023 02:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683711698; cv=none; d=google.com; s=arc-20160816; b=1KJPbnemooW71DmorU/kMoSUmdQvDMHv3e2z/iHTAI7VTInRY4Fki3PXhj0hrGrEGL hcRbFmipmRp4Hn9U/phZhbUxGiDbOssYQAcCmxihjebavI7DqBmIW44Esk0zyqmG+opD Fqv7CFasViMKCnHmIgfwPsPHeMlSlmoTrqrxYIvLOSTzST0RUEubUukULc2QEcHo70j8 XX/rA9Ld8V2WG+nCUiYuDvdmxTOWxoFI8nSa7EyoSDR3bQNjC2DyIc9okdwT0sl4hkjk cyw/xk43qRYlcsDi1ufvLBcVW2cksrmEYTSTUZS8OfJGuoUjiNLm4KL8IKJmfnlHzV3n jRog== 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:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-filter; bh=w4x/xmVNbv4I0guPaGI8ZGyOwgpS23MMbSf6Bjs7mFA=; b=zbhkMrStToz4RRgQfrF01GCWnE/nx1ssg7JVd7Bb6426/zlt5p2t7og3Aq7u55aba1 qg85b4bHITf3Iam305llFuRhWPWgW4r6utL1ZK/Pe88Jrh3AfKjNlfOa84eaMiaoyqIe 0HhC5yQP8iGFHiq+wEzzay+PQ7Fi09TeFV2XonfrmKUoSxmA2vaOVSrepxyn7ohB0j8T w1zWDac9lG9kedDeezVUeelusYrLTBcYmthtM9phcnGlnPiaY0Tw54j6B3BUxg9/AoEv JCQ2d3Zfw6zBRkIgdhUNPcD4DCNf88rVMJh/d5gyYh0x9w+Z17SNjlRiSGG/cjmWggQ2 ZZYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=ujNUL3fy; 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 p19-20020a637f53000000b0052c81982b3bsi3654017pgn.255.2023.05.10.02.41.25; Wed, 10 May 2023 02:41:38 -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=ujNUL3fy; 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 S236908AbjEJJYe (ORCPT + 99 others); Wed, 10 May 2023 05:24:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236955AbjEJJX7 (ORCPT ); Wed, 10 May 2023 05:23:59 -0400 Received: from mx0.infotecs.ru (mx0.infotecs.ru [91.244.183.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D79E3AA5; Wed, 10 May 2023 02:23:45 -0700 (PDT) Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 0A511113DE19; Wed, 10 May 2023 12:23:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 0A511113DE19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1683710622; bh=w4x/xmVNbv4I0guPaGI8ZGyOwgpS23MMbSf6Bjs7mFA=; h=From:To:CC:Subject:Date:From; b=ujNUL3fyv98mny2pW30/ksfLn+JcwssPN+u/sAMWAVZhWM078i8VvE7gAgEOF0Dhr 2/W5AdUj1SVHfJ5fISz+Q4JCSMDsl+u4JLZYVZKIiyrQ2vRoopQzQksWF8j0zRgyLI PIvQfGF5bRKY8tbuFiHqSBKtDJNxfFGQm3B82404= Received: from msk-exch-01.infotecs-nt (msk-exch-01.infotecs-nt [10.0.7.191]) by mx0.infotecs-nt (Postfix) with ESMTP id 030E63032D49; Wed, 10 May 2023 12:23:41 +0300 (MSK) From: Gavrilov Ilia To: Neil Horman CC: Gavrilov Ilia , Simon Horman , Marcelo Ricardo Leitner , 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-next v4] sctp: fix a potential OOB access in sctp_sched_set_sched() Thread-Topic: [PATCH net-next v4] sctp: fix a potential OOB access in sctp_sched_set_sched() Thread-Index: AQHZgyEbpS0tA1Fa+Uyl1ufVP9SybQ== Date: Wed, 10 May 2023 09:23:40 +0000 Message-ID: <20230510092344.1390444-1-Ilia.Gavrilov@infotecs.ru> 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: 177219 [May 10 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_uf_ne_domains}, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;infotecs.ru:7.1.1;lore.kernel.org: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/10 08:03:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2023/05/10 03:39:00 #21251912 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?1765499678183842183?= X-GMAIL-MSGID: =?utf-8?q?1765499678183842183?= From: "Ilia.Gavrilov" 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. Acked-by: Marcelo Ricardo Leitner Reviewed-by: Xin Long Reviewed-by: Simon Horman Signed-off-by: Ilia.Gavrilov --- V4: - revert to V2 - repost according to https://lore.kernel.org/all/20230503184928.458eb0da@kernel.org/ V3: - Change description - Remove 'fixes' V2: - Change the order of local variables - Specify the target tree in the subject 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);