net/mlx5: fix existing file removal
authorXueming Li <xuemingl@mellanox.com>
Fri, 16 Mar 2018 15:22:27 +0000 (23:22 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 30 Mar 2018 12:08:44 +0000 (14:08 +0200)
There is no guarantee that the file won't be removed by external
user/application between the stat() and remove() syscalls, remove() will
fail if the file no longer exists.

Fixes: f8b9a3bad467 ("net/mlx5: install a socket to exchange a file descriptor")
Cc: stable@dpdk.org
Signed-off-by: Xueming Li <xuemingl@mellanox.com>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
drivers/net/mlx5/mlx5_socket.c

index 955306d..7ce2ebc 100644 (file)
@@ -33,7 +33,6 @@ mlx5_socket_init(struct rte_eth_dev *dev)
        };
        int ret;
        int flags;
-       struct stat file_stat;
 
        /*
         * Initialise the socket to communicate with the secondary
@@ -59,9 +58,7 @@ mlx5_socket_init(struct rte_eth_dev *dev)
        }
        snprintf(sun.sun_path, sizeof(sun.sun_path), "/var/tmp/%s_%d",
                 MLX5_DRIVER_NAME, priv->primary_socket);
-       ret = stat(sun.sun_path, &file_stat);
-       if (!ret)
-               claim_zero(remove(sun.sun_path));
+       remove(sun.sun_path);
        ret = bind(priv->primary_socket, (const struct sockaddr *)&sun,
                   sizeof(sun));
        if (ret < 0) {