From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 59DA627D for ; Fri, 8 Mar 2019 18:49:08 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from yskoh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 8 Mar 2019 19:49:05 +0200 Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx [10.101.0.96]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x28HloB0002625; Fri, 8 Mar 2019 19:49:03 +0200 From: Yongseok Koh To: Pallantla Poornima Cc: Akhil Goyal , dpdk stable Date: Fri, 8 Mar 2019 09:47:22 -0800 Message-Id: <20190308174749.30771-44-yskoh@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190308174749.30771-1-yskoh@mellanox.com> References: <20190308174749.30771-1-yskoh@mellanox.com> Subject: [dpdk-stable] patch 'drivers: fix sprintf with snprintf' has been queued to LTS release 17.11.6 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Mar 2019 17:49:08 -0000 Hi, FYI, your patch has been queued to LTS release 17.11.6 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objection by 03/13/19. So please shout if anyone has objection. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. If the code is different (ie: not only metadata diffs), due for example to a change in context or macro names, please double check it. Thanks. Yongseok --- >>From e2f0b6ae985d09c5c6b50ee9d262b0acb661c6b2 Mon Sep 17 00:00:00 2001 From: Pallantla Poornima Date: Mon, 7 Jan 2019 10:46:23 +0000 Subject: [PATCH] drivers: fix sprintf with snprintf [ backported from upstream commit a1e8241a919f7239d16e63fbc41549b2c951e1ae ] sprintf function is not secure as it doesn't check the length of string. More secure function snprintf is used Fixes: 828d51d8fc ("bus/fslmc: refactor scan and probe functions") Fixes: e5cbdfc537 ("crypto/dpaa2_sec: add basic operations") Fixes: b23d4e898a ("crypto/dpaa2_sec: add per dev mempool to store FLE") Fixes: 623326dded ("crypto/dpaa2_sec: introduce poll mode driver") Fixes: 7e3e2954e0 ("crypto/dpaa_sec: move mempool allocation to config") Fixes: c3e85bdcc6 ("crypto/dpaa_sec: add crypto driver for NXP DPAA platform") Signed-off-by: Pallantla Poornima Acked-by: Akhil Goyal --- drivers/bus/fslmc/fslmc_bus.c | 4 ++-- drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 8 +++++--- drivers/crypto/dpaa_sec/dpaa_sec.c | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 001e56ca1..b33a01e18 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -216,8 +216,8 @@ rte_fslmc_scan(void) goto scan_fail; /* Scan devices on the group */ - sprintf(fslmc_dirpath, "%s/%d/devices", VFIO_IOMMU_GROUP_PATH, - groupid); + snprintf(fslmc_dirpath, sizeof(fslmc_dirpath), "%s/%d/devices", + VFIO_IOMMU_GROUP_PATH, groupid); dir = opendir(fslmc_dirpath); if (!dir) { FSLMC_BUS_LOG(ERR, "Unable to open VFIO group dir."); diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c index 67fb6e24c..8de8ef8df 100644 --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c @@ -2326,14 +2326,15 @@ dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev) retcode); goto init_error; } - sprintf(cryptodev->data->name, "dpsec-%u", hw_id); + snprintf(cryptodev->data->name, sizeof(cryptodev->data->name), + "dpsec-%u", hw_id); internals->max_nb_queue_pairs = attr.num_tx_queues; cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs; internals->hw = dpseci; internals->token = token; - sprintf(str, "fle_pool_%d", cryptodev->data->dev_id); + snprintf(str, sizeof(str), "fle_pool_%d", cryptodev->data->dev_id); internals->fle_pool = rte_mempool_create((const char *)str, FLE_POOL_NUM_BUFS, FLE_POOL_BUF_SIZE, @@ -2364,7 +2365,8 @@ cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv, int retval; - sprintf(cryptodev_name, "dpsec-%d", dpaa2_dev->object_id); + snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d", + dpaa2_dev->object_id); cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id()); if (cryptodev == NULL) diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c index 438dd3bcf..09bce20b8 100644 --- a/drivers/crypto/dpaa_sec/dpaa_sec.c +++ b/drivers/crypto/dpaa_sec/dpaa_sec.c @@ -1460,7 +1460,8 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv, int retval; - sprintf(cryptodev_name, "dpaa_sec-%d", dpaa_dev->id.dev_id); + snprintf(cryptodev_name, sizeof(cryptodev_name), "dpaa_sec-%d", + dpaa_dev->id.dev_id); cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id()); if (cryptodev == NULL) -- 2.11.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-03-08 09:46:42.425688716 -0800 +++ 0044-drivers-fix-sprintf-with-snprintf.patch 2019-03-08 09:46:40.216403000 -0800 @@ -1,38 +1,33 @@ -From a1e8241a919f7239d16e63fbc41549b2c951e1ae Mon Sep 17 00:00:00 2001 +From e2f0b6ae985d09c5c6b50ee9d262b0acb661c6b2 Mon Sep 17 00:00:00 2001 From: Pallantla Poornima Date: Mon, 7 Jan 2019 10:46:23 +0000 Subject: [PATCH] drivers: fix sprintf with snprintf +[ backported from upstream commit a1e8241a919f7239d16e63fbc41549b2c951e1ae ] + sprintf function is not secure as it doesn't check the length of string. More secure function snprintf is used Fixes: 828d51d8fc ("bus/fslmc: refactor scan and probe functions") -Fixes: c22fab9a6c ("raw/dpaa2_qdma: support configuration APIs") Fixes: e5cbdfc537 ("crypto/dpaa2_sec: add basic operations") Fixes: b23d4e898a ("crypto/dpaa2_sec: add per dev mempool to store FLE") Fixes: 623326dded ("crypto/dpaa2_sec: introduce poll mode driver") -Fixes: e7a45f3cc2 ("crypto/caam_jr: add UIO specific operations") -Fixes: f44bccadd8 ("crypto/caam_jr: add device basic operations") Fixes: 7e3e2954e0 ("crypto/dpaa_sec: move mempool allocation to config") Fixes: c3e85bdcc6 ("crypto/dpaa_sec: add crypto driver for NXP DPAA platform") -Cc: stable@dpdk.org Signed-off-by: Pallantla Poornima Acked-by: Akhil Goyal --- - drivers/bus/fslmc/fslmc_bus.c | 4 ++-- - drivers/crypto/caam_jr/caam_jr.c | 2 +- - drivers/crypto/caam_jr/caam_jr_uio.c | 13 ++++++------- - drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 8 +++++--- - drivers/crypto/dpaa_sec/dpaa_sec.c | 5 +++-- - drivers/raw/dpaa2_qdma/dpaa2_qdma.c | 2 +- - 6 files changed, 18 insertions(+), 16 deletions(-) + drivers/bus/fslmc/fslmc_bus.c | 4 ++-- + drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 8 +++++--- + drivers/crypto/dpaa_sec/dpaa_sec.c | 3 ++- + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c -index fa1505377..44c0827ce 100644 +index 001e56ca1..b33a01e18 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c -@@ -297,8 +297,8 @@ rte_fslmc_scan(void) +@@ -216,8 +216,8 @@ rte_fslmc_scan(void) goto scan_fail; /* Scan devices on the group */ @@ -42,57 +37,12 @@ + VFIO_IOMMU_GROUP_PATH, groupid); dir = opendir(fslmc_dirpath); if (!dir) { - DPAA2_BUS_ERR("Unable to open VFIO group directory"); -diff --git a/drivers/crypto/caam_jr/caam_jr.c b/drivers/crypto/caam_jr/caam_jr.c -index 45b281331..0263170fd 100644 ---- a/drivers/crypto/caam_jr/caam_jr.c -+++ b/drivers/crypto/caam_jr/caam_jr.c -@@ -2011,7 +2011,7 @@ caam_jr_dev_configure(struct rte_cryptodev *dev, - PMD_INIT_FUNC_TRACE(); - - internals = dev->data->dev_private; -- sprintf(str, "ctx_pool_%d", dev->data->dev_id); -+ snprintf(str, sizeof(str), "ctx_pool_%d", dev->data->dev_id); - if (!internals->ctx_pool) { - internals->ctx_pool = rte_mempool_create((const char *)str, - CTX_POOL_NUM_BUFS, -diff --git a/drivers/crypto/caam_jr/caam_jr_uio.c b/drivers/crypto/caam_jr/caam_jr_uio.c -index d94101c2f..bf872a220 100644 ---- a/drivers/crypto/caam_jr/caam_jr_uio.c -+++ b/drivers/crypto/caam_jr/caam_jr_uio.c -@@ -284,11 +284,11 @@ uio_map_registers(int uio_device_fd, int uio_device_id, - memset(uio_map_size_str, 0, sizeof(uio_map_size_str)); - - /* Compose string: /sys/class/uio/uioX */ -- sprintf(uio_sys_root, "%s/%s%d", SEC_UIO_DEVICE_SYS_ATTR_PATH, -- "uio", uio_device_id); -+ snprintf(uio_sys_root, sizeof(uio_sys_root), "%s/%s%d", -+ SEC_UIO_DEVICE_SYS_ATTR_PATH, "uio", uio_device_id); - /* Compose string: maps/mapY */ -- sprintf(uio_sys_map_subdir, "%s%d", SEC_UIO_DEVICE_SYS_MAP_ATTR, -- uio_map_id); -+ snprintf(uio_sys_map_subdir, sizeof(uio_sys_map_subdir), "%s%d", -+ SEC_UIO_DEVICE_SYS_MAP_ATTR, uio_map_id); - - /* Read first (and only) line from file - * /sys/class/uio/uioX/maps/mapY/size -@@ -389,9 +389,8 @@ uio_job_ring *config_job_ring(void) - - /* Find UIO device created by SEC kernel driver for this job ring. */ - memset(uio_device_file_name, 0, sizeof(uio_device_file_name)); -- -- sprintf(uio_device_file_name, "%s%d", SEC_UIO_DEVICE_FILE_NAME, -- job_ring->uio_minor_number); -+ snprintf(uio_device_file_name, sizeof(uio_device_file_name), "%s%d", -+ SEC_UIO_DEVICE_FILE_NAME, job_ring->uio_minor_number); - - /* Open device file */ - job_ring->uio_fd = open(uio_device_file_name, O_RDWR); + FSLMC_BUS_LOG(ERR, "Unable to open VFIO group dir."); diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c -index ef6e9c151..c2c22515d 100644 +index 67fb6e24c..8de8ef8df 100644 --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c -@@ -3371,14 +3371,15 @@ dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev) +@@ -2326,14 +2326,15 @@ dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev) retcode); goto init_error; } @@ -110,7 +60,7 @@ internals->fle_pool = rte_mempool_create((const char *)str, FLE_POOL_NUM_BUFS, FLE_POOL_BUF_SIZE, -@@ -3409,7 +3410,8 @@ cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused, +@@ -2364,7 +2365,8 @@ cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv, int retval; @@ -121,19 +71,10 @@ cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id()); if (cryptodev == NULL) diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c -index 5caceef3f..39533a9cc 100644 +index 438dd3bcf..09bce20b8 100644 --- a/drivers/crypto/dpaa_sec/dpaa_sec.c +++ b/drivers/crypto/dpaa_sec/dpaa_sec.c -@@ -2469,7 +2469,7 @@ dpaa_sec_dev_configure(struct rte_cryptodev *dev, - PMD_INIT_FUNC_TRACE(); - - internals = dev->data->dev_private; -- sprintf(str, "ctx_pool_%d", dev->data->dev_id); -+ snprintf(str, sizeof(str), "ctx_pool_%d", dev->data->dev_id); - if (!internals->ctx_pool) { - internals->ctx_pool = rte_mempool_create((const char *)str, - CTX_POOL_NUM_BUFS, -@@ -2675,7 +2675,8 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused, +@@ -1460,7 +1460,8 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv, int retval; @@ -143,19 +84,6 @@ cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id()); if (cryptodev == NULL) -diff --git a/drivers/raw/dpaa2_qdma/dpaa2_qdma.c b/drivers/raw/dpaa2_qdma/dpaa2_qdma.c -index f474442d4..60621eb85 100644 ---- a/drivers/raw/dpaa2_qdma/dpaa2_qdma.c -+++ b/drivers/raw/dpaa2_qdma/dpaa2_qdma.c -@@ -313,7 +313,7 @@ rte_qdma_vq_create(uint32_t lcore_id, uint32_t flags) - qdma_vqs[i].exclusive_hw_queue = 1; - } else { - /* Allocate a Ring for Virutal Queue in VQ mode */ -- sprintf(ring_name, "status ring %d", i); -+ snprintf(ring_name, sizeof(ring_name), "status ring %d", i); - qdma_vqs[i].status_ring = rte_ring_create(ring_name, - qdma_dev.fle_pool_count, rte_socket_id(), 0); - if (!qdma_vqs[i].status_ring) { -- 2.11.0