qemu-ga: don't leak fds to exec()ed processes
cover qemu-ga: don't leak fds to exec()ed processes
Please, check individual patches for details.
Luiz Capitulino (2):
qemu-ga: ga_open_pidfile(): use qemu_open()
qemu-ga: add ga_open_logfile()
qga/main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.0
PATCH 1/2 qemu-ga: ga_open_pidfile(): use qemu_open()
This ensures that O_CLOEXEC is passed to open(), this way the pid file fd is not leaked to executed processes.
--- qga/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qga/main.c +1 -1
@@ -242,7 +242,7 @@ static bool ga_open_pidfile(const char *pidfile)int pidfd;char pidstr[32 ]; - pidfd =open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); + pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR );if (pidfd ==-1 ||lockf (pidfd,F_TLOCK ,0 )) {g_critical ("Cannot lock pid file, %s" ,strerror (errno));if (pidfd !=-1 ) {
Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 1/2] qemu-ga: ga_open_pidfile(): use qemu_open()
Quoted 7 lines · Luiz Capitulino
This ensures that
O_CLOEXECis passed toopen(), this way the pid file fd is not leaked to executed processes.Signed-off-by Luiz Capitulino <[email protected]>--- qga/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
qga/main.c +1
-1@@ -242,7 +242,7 @@ static bool ga_open_pidfile(const char *pidfile)int pidfd;char pidstr[32 ]; - pidfd =open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR ); + pidfd =qemu_open (pidfile,O_CREAT |O_WRONLY ,S_IRUSR |S_IWUSR );if (pidfd ==-1 ||lockf (pidfd,F_TLOCK ,0 )) {g_critical ("Cannot lock pid file, %s" ,strerror (errno));if (pidfd !=-1 ) {
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/2 qemu-ga: add ga_open_logfile()
In reply to Luiz CapitulinoThis function sets O_CLOEXEC on the log file fd so that it isn't leaked to executed processes.
--- qga/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
qga/main.c +15 -2
@@ -236,6 +236,19 @@ void ga_set_response_delimited(GAState *s) s->delimit_response = true; } +static FILE *ga_open_logfile (const char *logfile) +{ +FILE *f; + + f =fopen (logfile,"a" ); +if (!f) { +return NULL ; + } + +qemu_set_cloexec (fileno (f)); +return f; +} +#ifndef _WIN32static bool ga_open_pidfile (const char *pidfile) {
@@ -377,7 +390,7 @@ void ga_unset_frozen(GAState *s)* in a frozen state at start up, do it now */ if (s->deferred_options.log_filepath) { - s->log_file =fopen (s->deferred_options.log_filepath,"a" ); + s->log_file =ga_open_logfile (s->deferred_options.log_filepath);if (!s->log_file) { s->log_file = stderr; }
@@ -838,7 +851,7 @@ int main(int argc, char **argv)become_daemon (pid_filepath); }if (log_filepath) { -FILE *log_file =fopen (log_filepath,"a" ); +FILE *log_file =ga_open_logfile (log_filepath);if (!log_file) {g_critical ("unable to open specified log file: %s" ,strerror (errno));
Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 2/2] qemu-ga: add ga_open_logfile()
Quoted 7 lines · Luiz Capitulino
This function sets
O_CLOEXECon the log file fd so that it isn't leaked to executed processes.Signed-off-by Luiz Capitulino <[email protected]>--- qga/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 5 lines · Luiz Capitulino
Please, check individual patches for details.
Luiz Capitulino (2):
qemu-ga:ga_open_pidfile(): useqemu_open()
qemu-ga: addga_open_logfile()
Quoted 5 lines
qga/main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)Signature · 1 line
1.8.0
mdroth
AppliedQuoted 5 lines · Luiz Capitulino
Please, check individual patches for details.
Luiz Capitulino (2):
qemu-ga:ga_open_pidfile(): useqemu_open()
qemu-ga: addga_open_logfile()
Thanks, applied to qga branch.
Quoted 7 lines
qga/main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)Signature · 1 line
1.8.0