From: Stephen Hemminger Date: Fri, 7 Mar 2014 18:13:41 +0000 (-0800) Subject: ivshmem: fix errors identified by hardening X-Git-Tag: spdx-start~10886 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=524f073a10fec965e3c7ffe49163c02709686617;p=dpdk.git ivshmem: fix errors identified by hardening Need to pass mode argument to open with O_CREAT. Must check return value from ftruncate(). Signed-off-by: Stephen Hemminger Acked-by: Thomas Monjalon --- diff --git a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c index 87e88c3453..abc15f9e55 100644 --- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c +++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c @@ -472,7 +472,7 @@ create_shared_config(void) rte_snprintf(path, sizeof(path), IVSHMEM_CONFIG_PATH, internal_config.hugefile_prefix); - fd = open(path, O_CREAT | O_RDWR); + fd = open(path, O_CREAT | O_RDWR, 0600); if (fd < 0) { RTE_LOG(ERR, EAL, "Could not open %s: %s\n", path, strerror(errno)); @@ -486,7 +486,10 @@ create_shared_config(void) return -1; } - ftruncate(fd, sizeof(struct ivshmem_shared_config)); + if (ftruncate(fd, sizeof(struct ivshmem_shared_config)) < 0) { + RTE_LOG(ERR, EAL, "ftruncate failed: %s\n", strerror(errno)); + return -1; + } ivshmem_config = mmap(NULL, sizeof(struct ivshmem_shared_config), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);