From 524f073a10fec965e3c7ffe49163c02709686617 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 7 Mar 2014 10:13:41 -0800 Subject: [PATCH] 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 --- lib/librte_eal/linuxapp/eal/eal_ivshmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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); -- 2.20.1