From patchwork Fri Mar 19 09:02:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weihang Li X-Patchwork-Id: 12150425 X-Patchwork-Delegate: leon@leon.nu Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E52FCC433DB for ; Fri, 19 Mar 2021 09:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B035D64F3B for ; Fri, 19 Mar 2021 09:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbhCSJFH (ORCPT ); Fri, 19 Mar 2021 05:05:07 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:13579 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbhCSJE6 (ORCPT ); Fri, 19 Mar 2021 05:04:58 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4F1yZt04DxzPkfk; Fri, 19 Mar 2021 17:02:30 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Fri, 19 Mar 2021 17:04:48 +0800 From: Weihang Li To: , CC: , , Subject: [PATCH for-next] RDMA/core: Check invalid QP state for ib_modify_qp_is_ok() Date: Fri, 19 Mar 2021 17:02:25 +0800 Message-ID: <1616144545-18159-1-git-send-email-liweihang@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Xi Wang Out-of-bounds may occur in 'qp_state_table' when the caller passing wrong QP state value. Signed-off-by: Xi Wang Signed-off-by: Weihang Li --- drivers/infiniband/core/verbs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 28464c5..66ba4e6 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1613,6 +1613,10 @@ bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state, cur_state != IB_QPS_SQD && cur_state != IB_QPS_SQE) return false; + if (cur_state >= ARRAY_SIZE(qp_state_table) || + next_state >= ARRAY_SIZE(qp_state_table[0])) + return false; + if (!qp_state_table[cur_state][next_state].valid) return false;