From patchwork Sun Apr 25 12:59:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 92130 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5448EA0548; Sun, 25 Apr 2021 14:59:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3485841139; Sun, 25 Apr 2021 14:59:51 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 5A6564110A for ; Sun, 25 Apr 2021 14:59:49 +0200 (CEST) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FSp2m6WvLzvSTS for ; Sun, 25 Apr 2021 20:57:20 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Sun, 25 Apr 2021 20:59:42 +0800 From: "Min Hu (Connor)" To: CC: , Date: Sun, 25 Apr 2021 20:59:54 +0800 Message-ID: <1619355594-15223-1-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] lib/librte_power: fix using variables before validity check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: HongBo Zheng In function power_guest_channel_read_msg, 'lcore_id' is used before validity check, which may cause buffer 'global_fds' accessed by index 'lcore_id' overflow. This patch moves the validity check of 'lcore_id' before the 'lcore_id' being used for the first time. Fixes: 9dc843eb273b ("power: extend guest channel API for reading") Cc: stable@dpdk.org Signed-off-by: HongBo Zheng Signed-off-by: Min Hu (Connor) Reviewed-by: Reshma Pattan --- lib/power/guest_channel.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/power/guest_channel.c b/lib/power/guest_channel.c index 2f7507a..d3de3f1 100644 --- a/lib/power/guest_channel.c +++ b/lib/power/guest_channel.c @@ -166,6 +166,12 @@ int power_guest_channel_read_msg(void *pkt, if (pkt_len == 0 || pkt == NULL) return -1; + if (lcore_id >= RTE_MAX_LCORE) { + RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range 0...%d\n", + lcore_id, RTE_MAX_LCORE-1); + return -1; + } + fds.fd = global_fds[lcore_id]; fds.events = POLLIN; @@ -179,12 +185,6 @@ int power_guest_channel_read_msg(void *pkt, return -1; } - if (lcore_id >= RTE_MAX_LCORE) { - RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range 0...%d\n", - lcore_id, RTE_MAX_LCORE-1); - return -1; - } - if (global_fds[lcore_id] < 0) { RTE_LOG(ERR, GUEST_CHANNEL, "Channel is not connected\n"); return -1;