All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomas Hozza <thozza@redhat.com>
To: gregkh@linuxfoundation.org
Cc: kys@microsoft.com, jasowang@redhat.com, haiyangz@microsoft.com,
	linux-kernel@vger.kernel.org, habdi@microsoft.com,
	Tomas Hozza <thozza@redhat.com>
Subject: [PATCH 2/2] tools: hv: Use CLOEXEC when opening kvp_pool files
Date: Tue,  8 Jan 2013 12:26:43 +0100	[thread overview]
Message-ID: <1357644403-11140-2-git-send-email-thozza@redhat.com> (raw)
In-Reply-To: <1357644403-11140-1-git-send-email-thozza@redhat.com>

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: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 6b56b75..31f839cc 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -151,7 +151,7 @@ static void kvp_update_file(int pool)
 	 */
 	kvp_acquire_lock(pool);
 
-	filep = fopen(kvp_file_info[pool].fname, "w");
+	filep = fopen(kvp_file_info[pool].fname, "we");
 	if (!filep) {
 		kvp_release_lock(pool);
 		syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
@@ -182,7 +182,7 @@ static void kvp_update_mem_state(int pool)
 
 	kvp_acquire_lock(pool);
 
-	filep = fopen(kvp_file_info[pool].fname, "r");
+	filep = fopen(kvp_file_info[pool].fname, "re");
 	if (!filep) {
 		kvp_release_lock(pool);
 		syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
@@ -246,13 +246,13 @@ static int kvp_file_init(void)
 		records_read = 0;
 		num_blocks = 1;
 		sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
-		fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+		fd = open(fname, O_RDWR | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH);
 
 		if (fd == -1)
 			return 1;
 
 
-		filep = fopen(fname, "r");
+		filep = fopen(fname, "re");
 		if (!filep)
 			return 1;
 
-- 
1.7.11.7


  reply	other threads:[~2013-01-08 11:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 11:26 [PATCH 1/2] tools: hv: Fix how ifcfg-* file is created Tomas Hozza
2013-01-08 11:26 ` Tomas Hozza [this message]
2013-01-10 20:20   ` [PATCH 2/2] tools: hv: Use CLOEXEC when opening kvp_pool files KY Srinivasan
2013-01-17 19:48   ` Greg KH
2013-01-18 14:23     ` [PATCH] " Tomas Hozza
2013-01-18 16:36       ` KY Srinivasan
2013-01-10 20:19 ` [PATCH 1/2] tools: hv: Fix how ifcfg-* file is created KY Srinivasan
2013-01-11  8:02   ` Tomas Hozza
2013-01-13 21:27     ` [PATCH] " Tomas Hozza
2013-02-22 18:57       ` Olaf Hering
2013-02-25  7:41         ` Tomas Hozza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357644403-11140-2-git-send-email-thozza@redhat.com \
    --to=thozza@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=habdi@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.