提交 8467fdbb 编写于 作者: T Tomas Hozza 提交者: Greg Kroah-Hartman

tools: hv: Use CLOEXEC when opening kvp_pool files

Use CLOEXEC flag when opening kvp_pool_x files to prevent file
descriptor leakage. Not using it was causing a problem when
SELinux was enabled.
Signed-off-by: NTomas Hozza <thozza@redhat.com>
Acked-by: NK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 0f3f2f86
...@@ -151,7 +151,7 @@ static void kvp_update_file(int pool) ...@@ -151,7 +151,7 @@ static void kvp_update_file(int pool)
*/ */
kvp_acquire_lock(pool); kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "w"); filep = fopen(kvp_file_info[pool].fname, "we");
if (!filep) { if (!filep) {
kvp_release_lock(pool); kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool); syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
...@@ -182,7 +182,7 @@ static void kvp_update_mem_state(int pool) ...@@ -182,7 +182,7 @@ static void kvp_update_mem_state(int pool)
kvp_acquire_lock(pool); kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "r"); filep = fopen(kvp_file_info[pool].fname, "re");
if (!filep) { if (!filep) {
kvp_release_lock(pool); kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool); syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
...@@ -246,13 +246,13 @@ static int kvp_file_init(void) ...@@ -246,13 +246,13 @@ static int kvp_file_init(void)
records_read = 0; records_read = 0;
num_blocks = 1; num_blocks = 1;
sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i); sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */); fd = open(fname, O_RDWR | O_CREAT | O_CLOEXEC, 0644 /* rw-r--r-- */);
if (fd == -1) if (fd == -1)
return 1; return 1;
filep = fopen(fname, "r"); filep = fopen(fname, "re");
if (!filep) if (!filep)
return 1; return 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册