From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 19E9CA0548; Mon, 26 Apr 2021 10:25:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 009B54118F; Mon, 26 Apr 2021 10:25:03 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id A4DEC4118E for ; Mon, 26 Apr 2021 10:25:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619425499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LkP70KGo7vpQXUZo/WwwP8TF45hQuO1Yg1lk66AgkUk=; b=CL9rIOZ+Vp2e0qxw3vCP0CM+KecRD/Q6SyKbPCTMDgoSnAQn10ebfdFJ19i03EJv5KNYUd l4ZWJqJUUZZeA4FUqa6P8KQFNZL0nlWevBmtYW7gSDce6KP+2WNeWlK/j1zQZ6GGzSRN/B UMsyoYNESgq9tGu4JkwqGyX2hqttqX0= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-85-4fFvm5x2OleYfM2juQk-0g-1; Mon, 26 Apr 2021 04:24:57 -0400 X-MC-Unique: 4fFvm5x2OleYfM2juQk-0g-1 Received: by mail-vk1-f198.google.com with SMTP id h6-20020a0561220b66b02901e488cc9b21so5698967vkf.10 for ; Mon, 26 Apr 2021 01:24:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LkP70KGo7vpQXUZo/WwwP8TF45hQuO1Yg1lk66AgkUk=; b=qBUCUNs+DQ2Kngh6P2pFamRVFA75OU57qSs6HNLNyZNStgkHJVIQv13tEBZuPJN0GZ vrVLfYBk5PonE5Blwtg4LmK1Ackz/d6+qwWS4e8NDnaaggzczlaRrfXXlh4IDoaX4x3f NcqYk/YZwoOmvP3969+bKu5sAkM+7TnQi65WermNw1D2JKewubiV+TTnpqKLAWJ5JdpG n2fF01S1MpakDzkxAXUEx8pM3rqbkLyGUjBVrLvLWS1rP2G+BCUVGd99FUxdF/VACfz6 8LjyMHX62kKAMf+EShP+XVLu27f3kdho2bHqJdxCHFU0Dj4uc0kzmFvd7XaVy8W7Qxz7 OfqQ== X-Gm-Message-State: AOAM533EYEN9cw9b3WH6rji4j+UvrnoSsnMv/2Nka501wMWBZCLVrLF/ 1Dcv+TtkL9MWvrwaUI4Lbn6CV5JJAGLpOif5UrPFic2zOmOk4edC5B1bO6KN14uJrLllhBMH4Bb tlpp9+XvwPuTfBNmnSiI= X-Received: by 2002:a05:6102:348:: with SMTP id e8mr11511302vsa.10.1619425497342; Mon, 26 Apr 2021 01:24:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMeoQYAEUxgqvWbZkVzP5TSw/kLQNPg8kdRxeNADQ8cFNYHuZTWD3Q8/e2zmhesNh8aPm9m01EIbYNHxK7uV8= X-Received: by 2002:a05:6102:348:: with SMTP id e8mr11511293vsa.10.1619425497139; Mon, 26 Apr 2021 01:24:57 -0700 (PDT) MIME-Version: 1.0 References: <20210419054426.26812-1-Cheng1.jiang@intel.com> In-Reply-To: <20210419054426.26812-1-Cheng1.jiang@intel.com> From: David Marchand Date: Mon, 26 Apr 2021 10:24:46 +0200 Message-ID: To: Cheng Jiang Cc: Maxime Coquelin , "Xia, Chenbo" , dev , dpdk stable Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [dpdk-stable] [PATCH] examples/vhost: fix potential overflow in args process 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" On Mon, Apr 19, 2021 at 7:59 AM Cheng Jiang wrote: > > Add args length check to fix potential overflow issue. > > Coverity issue: 363741 > Fixes: 965b06f0358 ("examples/vhost: enhance getopt_long usage") > Cc: stable@dpdk.org No need for Cc: stable since this issue only affects the current release. > > Signed-off-by: Cheng Jiang It should indeed fix the coverity report but this limit does not make sense. Could you make dma_type point at either optarg (it should be fine as we only read this string)? Something like (untested): diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 2ca7d98c58..158e5e9a8a 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -55,9 +55,6 @@ #define INVALID_PORT_ID 0xFF -/* Maximum long option length for option parsing. */ -#define MAX_LONG_OPT_SZ 64 - /* mask of enabled ports */ static uint32_t enabled_port_mask = 0; @@ -97,7 +94,7 @@ static int builtin_net_driver; static int async_vhost_driver; -static char dma_type[MAX_LONG_OPT_SZ]; +static char *dma_type; /* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time = BURST_RX_WAIT_US; @@ -201,7 +198,7 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE]; static inline int open_dma(const char *value) { - if (strncmp(dma_type, "ioat", 4) == 0) + if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) return open_ioat(value); return -1; @@ -669,7 +666,7 @@ us_vhost_parse_args(int argc, char **argv) break; case OPT_DMA_TYPE_NUM: - strcpy(dma_type, optarg); + dma_type = optarg; break; case OPT_DMAS_NUM: @@ -1472,7 +1469,7 @@ new_device(int vid) struct rte_vhost_async_features f; struct rte_vhost_async_channel_ops channel_ops; - if (strncmp(dma_type, "ioat", 4) == 0) { + if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) { channel_ops.transfer_data = ioat_transfer_data_cb; channel_ops.check_completed_copies = ioat_check_completed_copies_cb; -- David Marchand