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 D3CDDA0548 for ; Mon, 26 Apr 2021 10:25:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A1625411AB; Mon, 26 Apr 2021 10:25:04 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 8A7E14118E for ; Mon, 26 Apr 2021 10:25:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619425502; 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=AucdrqWEeuQyuys0Dcst8Gj/BGl64+/ftwycgDUpHWOERVjHl+IQ6kMqENNScFdTRWiGG0 99c1Zc2iouY5+At9SFB8pgwutPe6b9F22WphMyjy3h7dyQnlk4aG3mDBai2s98oMQbxRls R4nD19rwF2cH3A9WkgtCPSvczlcEPDg= 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-102-NhEfouOFOSW_PmbSyER4mg-1; Mon, 26 Apr 2021 04:24:57 -0400 X-MC-Unique: NhEfouOFOSW_PmbSyER4mg-1 Received: by mail-vk1-f198.google.com with SMTP id g185-20020a1f20c20000b02901e083517917so8673006vkg.18 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=YkvLeryn+vJqggdjAsPOVIgMSRABZvKT/WkHjAxp9jXf0IEPM4WcA8P7Ex3sXw06Y+ o1482mYsFc9UXhf2/WH2RH5Lc22yGVaw7SrlMjxG3WSwmR5d7fbisJfklpeFmuuc4CML 9thMWOGAHIFJkhcLEYdkBiea+d6AJCDmJku2BckxUjKX1PXuJQZOMn2ZqDdSulDOfZd+ 00bSH0+5i1jRc5BQZdDCPAXv5Zpi/s+D28w1eIshBML2hhD3/VvSBbMili9/W/FbUj/O Tjg2Z5ana454HcWcVvrqpZQep0qLEPv5PEJ26fd1P8QGhKNliS57nNYqWZDsj6dwZ1o8 Nleg== X-Gm-Message-State: AOAM532tjNjvgelH05joFHR12N3yD0OIKyGJXP1mVB2kXfvhnvbzGpYI 4G3/jb7k6jdO2ge9id4H9g4y0u85xbAblLU5VFG9DP8btoEef/6OxXWG2FFj5KuTujcrUrzUUyu iSS4GGhIlXKmi/whiOsdJ6CM= X-Received: by 2002:a05:6102:348:: with SMTP id e8mr11511297vsa.10.1619425497311; 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-stable] [PATCH] examples/vhost: fix potential overflow in args process X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" 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