eal: tighten permissions on shared memory files

Message ID 20190403160034.31176-1-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series eal: tighten permissions on shared memory files |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Bruce Richardson April 3, 2019, 4 p.m. UTC
  When creating files on disk, e.g. for EAL configuration or shared memory
locks, etc., there is no need to grant any permissions on those files to
other users. All directories are already created with 0700 permissions, so
we should create all files with 0600 permissions.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_eal/freebsd/eal/eal.c               | 2 +-
 lib/librte_eal/freebsd/eal/eal_hugepage_info.c | 2 +-
 lib/librte_eal/linux/eal/eal.c                 | 2 +-
 lib/librte_eal/linux/eal/eal_hugepage_info.c   | 2 +-
 lib/librte_eal/linux/eal/eal_memory.c          | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
  

Comments

Bruce Richardson April 3, 2019, 4:02 p.m. UTC | #1
Adding stable@dpdk.org since this is suitable for backporting

On Wed, Apr 03, 2019 at 05:00:34PM +0100, Bruce Richardson wrote:
> When creating files on disk, e.g. for EAL configuration or shared memory
> locks, etc., there is no need to grant any permissions on those files to
> other users. All directories are already created with 0700 permissions, so
> we should create all files with 0600 permissions.
> 
CC: stable@dpdk.org
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/librte_eal/freebsd/eal/eal.c               | 2 +-
>  lib/librte_eal/freebsd/eal/eal_hugepage_info.c | 2 +-
>  lib/librte_eal/linux/eal/eal.c                 | 2 +-
>  lib/librte_eal/linux/eal/eal_hugepage_info.c   | 2 +-
>  lib/librte_eal/linux/eal/eal_memory.c          | 2 +-
>  5 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_eal/freebsd/eal/eal.c b/lib/librte_eal/freebsd/eal/eal.c
> index 790c6afa7..c6ac9028f 100644
> --- a/lib/librte_eal/freebsd/eal/eal.c
> +++ b/lib/librte_eal/freebsd/eal/eal.c
> @@ -227,7 +227,7 @@ rte_eal_config_create(void)
>  		return;
>  
>  	if (mem_cfg_fd < 0){
> -		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> +		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
>  		if (mem_cfg_fd < 0)
>  			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
>  	}
> diff --git a/lib/librte_eal/freebsd/eal/eal_hugepage_info.c b/lib/librte_eal/freebsd/eal/eal_hugepage_info.c
> index 1e8f5df23..32012e142 100644
> --- a/lib/librte_eal/freebsd/eal/eal_hugepage_info.c
> +++ b/lib/librte_eal/freebsd/eal/eal_hugepage_info.c
> @@ -22,7 +22,7 @@ static void *
>  map_shared_memory(const char *filename, const size_t mem_size, int flags)
>  {
>  	void *retval;
> -	int fd = open(filename, flags, 0666);
> +	int fd = open(filename, flags, 0600);
>  	if (fd < 0)
>  		return NULL;
>  	if (ftruncate(fd, mem_size) < 0) {
> diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c
> index 75ed0cf10..f7ae62d7b 100644
> --- a/lib/librte_eal/linux/eal/eal.c
> +++ b/lib/librte_eal/linux/eal/eal.c
> @@ -320,7 +320,7 @@ rte_eal_config_create(void)
>  		rte_mem_cfg_addr = NULL;
>  
>  	if (mem_cfg_fd < 0){
> -		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> +		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
>  		if (mem_cfg_fd < 0)
>  			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
>  	}
> diff --git a/lib/librte_eal/linux/eal/eal_hugepage_info.c b/lib/librte_eal/linux/eal/eal_hugepage_info.c
> index ce3e99256..91a4fede7 100644
> --- a/lib/librte_eal/linux/eal/eal_hugepage_info.c
> +++ b/lib/librte_eal/linux/eal/eal_hugepage_info.c
> @@ -45,7 +45,7 @@ static void *
>  map_shared_memory(const char *filename, const size_t mem_size, int flags)
>  {
>  	void *retval;
> -	int fd = open(filename, flags, 0666);
> +	int fd = open(filename, flags, 0600);
>  	if (fd < 0)
>  		return NULL;
>  	if (ftruncate(fd, mem_size) < 0) {
> diff --git a/lib/librte_eal/linux/eal/eal_memory.c b/lib/librte_eal/linux/eal/eal_memory.c
> index 39cd359a0..319352521 100644
> --- a/lib/librte_eal/linux/eal/eal_memory.c
> +++ b/lib/librte_eal/linux/eal/eal_memory.c
> @@ -541,7 +541,7 @@ create_shared_memory(const char *filename, const size_t mem_size)
>  		return retval;
>  	}
>  
> -	fd = open(filename, O_CREAT | O_RDWR, 0666);
> +	fd = open(filename, O_CREAT | O_RDWR, 0600);
>  	if (fd < 0)
>  		return NULL;
>  	if (ftruncate(fd, mem_size) < 0) {
> -- 
> 2.20.1
>
  
Thomas Monjalon April 4, 2019, 5:51 p.m. UTC | #2
03/04/2019 18:02, Bruce Richardson:
> Adding stable@dpdk.org since this is suitable for backporting
> 
> On Wed, Apr 03, 2019 at 05:00:34PM +0100, Bruce Richardson wrote:
> > When creating files on disk, e.g. for EAL configuration or shared memory
> > locks, etc., there is no need to grant any permissions on those files to
> > other users. All directories are already created with 0700 permissions, so
> > we should create all files with 0600 permissions.
> > 
> CC: stable@dpdk.org
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

It means the primary and secondary processes must have the same owner.
Is it worth to document it?
I feel the mask could be an EAL option.

Anyway the directories have already a fixed tight mask, so
Applied, thanks
  

Patch

diff --git a/lib/librte_eal/freebsd/eal/eal.c b/lib/librte_eal/freebsd/eal/eal.c
index 790c6afa7..c6ac9028f 100644
--- a/lib/librte_eal/freebsd/eal/eal.c
+++ b/lib/librte_eal/freebsd/eal/eal.c
@@ -227,7 +227,7 @@  rte_eal_config_create(void)
 		return;
 
 	if (mem_cfg_fd < 0){
-		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
+		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
 		if (mem_cfg_fd < 0)
 			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
 	}
diff --git a/lib/librte_eal/freebsd/eal/eal_hugepage_info.c b/lib/librte_eal/freebsd/eal/eal_hugepage_info.c
index 1e8f5df23..32012e142 100644
--- a/lib/librte_eal/freebsd/eal/eal_hugepage_info.c
+++ b/lib/librte_eal/freebsd/eal/eal_hugepage_info.c
@@ -22,7 +22,7 @@  static void *
 map_shared_memory(const char *filename, const size_t mem_size, int flags)
 {
 	void *retval;
-	int fd = open(filename, flags, 0666);
+	int fd = open(filename, flags, 0600);
 	if (fd < 0)
 		return NULL;
 	if (ftruncate(fd, mem_size) < 0) {
diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c
index 75ed0cf10..f7ae62d7b 100644
--- a/lib/librte_eal/linux/eal/eal.c
+++ b/lib/librte_eal/linux/eal/eal.c
@@ -320,7 +320,7 @@  rte_eal_config_create(void)
 		rte_mem_cfg_addr = NULL;
 
 	if (mem_cfg_fd < 0){
-		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
+		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
 		if (mem_cfg_fd < 0)
 			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
 	}
diff --git a/lib/librte_eal/linux/eal/eal_hugepage_info.c b/lib/librte_eal/linux/eal/eal_hugepage_info.c
index ce3e99256..91a4fede7 100644
--- a/lib/librte_eal/linux/eal/eal_hugepage_info.c
+++ b/lib/librte_eal/linux/eal/eal_hugepage_info.c
@@ -45,7 +45,7 @@  static void *
 map_shared_memory(const char *filename, const size_t mem_size, int flags)
 {
 	void *retval;
-	int fd = open(filename, flags, 0666);
+	int fd = open(filename, flags, 0600);
 	if (fd < 0)
 		return NULL;
 	if (ftruncate(fd, mem_size) < 0) {
diff --git a/lib/librte_eal/linux/eal/eal_memory.c b/lib/librte_eal/linux/eal/eal_memory.c
index 39cd359a0..319352521 100644
--- a/lib/librte_eal/linux/eal/eal_memory.c
+++ b/lib/librte_eal/linux/eal/eal_memory.c
@@ -541,7 +541,7 @@  create_shared_memory(const char *filename, const size_t mem_size)
 		return retval;
 	}
 
-	fd = open(filename, O_CREAT | O_RDWR, 0666);
+	fd = open(filename, O_CREAT | O_RDWR, 0600);
 	if (fd < 0)
 		return NULL;
 	if (ftruncate(fd, mem_size) < 0) {