ivshmem: fix errors identified by hardening
authorStephen Hemminger <stephen@networkplumber.org>
Fri, 7 Mar 2014 18:13:41 +0000 (10:13 -0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 17 Apr 2014 13:48:44 +0000 (15:48 +0200)
Need to pass mode argument to open with O_CREAT.
Must check return value from ftruncate().

Signed-off-by: Stephen Hemminger <shemming@brocade.com>
Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
lib/librte_eal/linuxapp/eal/eal_ivshmem.c

index 87e88c3..abc15f9 100644 (file)
@@ -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);