* [BUG] libxl_ctx_free calls close(0)
@ 2017-07-20 17:36 Victor Kirhenshtein
2017-07-21 8:20 ` Wei Liu
0 siblings, 1 reply; 5+ messages in thread
From: Victor Kirhenshtein @ 2017-07-20 17:36 UTC (permalink / raw)
To: xen-devel
Hello,
it seems that libxl_ctx_free always calls close(0) for some
reason, even if libxl never opens file descriptor 0. It sometimes
closes valid descriptor in application causing random and
hard to debug I/O errors.
The following simple program can be used to reproduce this bug:
#include <stdio.h>
#include <libxl.h>
static void LogMessage(struct xentoollog_logger *logger,
xentoollog_level level,
int errnoval /* or -1 */,
const char *context /* eg "xc", "xl", may be 0 */,
const char *format /* without level, context, \n
*/,
va_list al)
{
}
static void LogProgress(struct xentoollog_logger *logger,
const char *context /* see above */,
const char *doing_what /* no \r,\n */,
int percent, unsigned long done, unsigned long
total)
{
}
static void LogDestroy(struct xentoollog_logger *logger)
{
}
int main(int argc, char *argv[])
{
xentoollog_logger logger;
logger.vmessage = LogMessage;
logger.progress = LogProgress;
logger.destroy = LogDestroy;
libxl_ctx *ctx;
int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, &logger);
if (rc != 0)
{
printf("libxl_ctx_alloc failed (%d)\n", rc);
return 1;
}
libxl_ctx_free(ctx);
return 0;
}
Strace output for it is following (I omit shared library
loading on startup):
set_tid_address(0x7f787db29a50) = 17944
set_robust_list(0x7f787db29a60, 24) = 0
rt_sigaction(SIGRTMIN, {0x7f787c4809b0, [], SA_RESTORER|SA_SIGINFO,
0x7f787c489890}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f787c480a40, [],
SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f787c489890}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY})
= 0
brk(0) = 0x156d000
brk(0x158e000) = 0x158e000
pipe([3, 4]) = 0
fcntl(3, F_GETFL) = 0 (flags O_RDONLY)
fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
fcntl(4, F_GETFL) = 0x1 (flags O_WRONLY)
fcntl(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
open("/proc/xen/privcmd", O_RDWR) = 5
fcntl(5, F_GETFD) = 0
fcntl(5, F_SETFD, FD_CLOEXEC) = 0
stat("/var/run/xenstored/socket", {st_mode=S_IFSOCK|0600, st_size=0,
...}) = 0
socket(PF_LOCAL, SOCK_STREAM, 0) = 6
fcntl(6, F_GETFD) = 0
fcntl(6, F_SETFD, FD_CLOEXEC) = 0
connect(6, {sa_family=AF_LOCAL, sun_path="/var/run/xenstored/socket"},
110) = 0
close(5) = 0
close(6) = 0
close(3) = 0
close(4) = 0
close(0) = 0
exit_group(0) = ?
+++ exited with 0 +++
Best regards,
Victor Kirhenshtein
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [BUG] libxl_ctx_free calls close(0)
2017-07-20 17:36 [BUG] libxl_ctx_free calls close(0) Victor Kirhenshtein
@ 2017-07-21 8:20 ` Wei Liu
2017-07-21 10:18 ` Victor Kirhenshtein
0 siblings, 1 reply; 5+ messages in thread
From: Wei Liu @ 2017-07-21 8:20 UTC (permalink / raw)
To: Victor Kirhenshtein; +Cc: Ian Jackson, Wei Liu, xen-devel
CC Ian Jackson
I don't know which version of Xen you're using. Can you check if it
contains the following commit?
commit fa13f7b0c0f3d01741e35d573009503c3bf7b6a6
Author: Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Aug 18 14:02:37 2014 +0100
Commit: Ian Campbell <ian.campbell@citrix.com>
CommitDate: Wed Aug 27 02:30:25 2014 +0100
tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
Reported-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
On Thu, Jul 20, 2017 at 08:36:28PM +0300, Victor Kirhenshtein wrote:
> Hello,
>
> it seems that libxl_ctx_free always calls close(0) for some
> reason, even if libxl never opens file descriptor 0. It sometimes
> closes valid descriptor in application causing random and
> hard to debug I/O errors.
>
> The following simple program can be used to reproduce this bug:
>
> #include <stdio.h>
> #include <libxl.h>
>
> static void LogMessage(struct xentoollog_logger *logger,
> xentoollog_level level,
> int errnoval /* or -1 */,
> const char *context /* eg "xc", "xl", may be 0 */,
> const char *format /* without level, context, \n
> */,
> va_list al)
> {
> }
>
> static void LogProgress(struct xentoollog_logger *logger,
> const char *context /* see above */,
> const char *doing_what /* no \r,\n */,
> int percent, unsigned long done, unsigned long
> total)
> {
> }
>
> static void LogDestroy(struct xentoollog_logger *logger)
> {
> }
>
>
> int main(int argc, char *argv[])
> {
> xentoollog_logger logger;
> logger.vmessage = LogMessage;
> logger.progress = LogProgress;
> logger.destroy = LogDestroy;
>
> libxl_ctx *ctx;
> int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, &logger);
> if (rc != 0)
> {
> printf("libxl_ctx_alloc failed (%d)\n", rc);
> return 1;
> }
>
>
> libxl_ctx_free(ctx);
> return 0;
> }
>
> Strace output for it is following (I omit shared library
> loading on startup):
>
> set_tid_address(0x7f787db29a50) = 17944
> set_robust_list(0x7f787db29a60, 24) = 0
> rt_sigaction(SIGRTMIN, {0x7f787c4809b0, [], SA_RESTORER|SA_SIGINFO,
> 0x7f787c489890}, NULL, 8) = 0
> rt_sigaction(SIGRT_1, {0x7f787c480a40, [],
> SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f787c489890}, NULL, 8) = 0
> rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
> getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY})
> = 0
> brk(0) = 0x156d000
> brk(0x158e000) = 0x158e000
> pipe([3, 4]) = 0
> fcntl(3, F_GETFL) = 0 (flags O_RDONLY)
> fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
> fcntl(4, F_GETFL) = 0x1 (flags O_WRONLY)
> fcntl(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
> open("/proc/xen/privcmd", O_RDWR) = 5
> fcntl(5, F_GETFD) = 0
> fcntl(5, F_SETFD, FD_CLOEXEC) = 0
> stat("/var/run/xenstored/socket", {st_mode=S_IFSOCK|0600, st_size=0,
> ...}) = 0
> socket(PF_LOCAL, SOCK_STREAM, 0) = 6
> fcntl(6, F_GETFD) = 0
> fcntl(6, F_SETFD, FD_CLOEXEC) = 0
> connect(6, {sa_family=AF_LOCAL, sun_path="/var/run/xenstored/socket"},
> 110) = 0
> close(5) = 0
> close(6) = 0
> close(3) = 0
> close(4) = 0
> close(0) = 0
> exit_group(0) = ?
> +++ exited with 0 +++
>
> Best regards,
> Victor Kirhenshtein
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [BUG] libxl_ctx_free calls close(0)
2017-07-21 8:20 ` Wei Liu
@ 2017-07-21 10:18 ` Victor Kirhenshtein
2017-07-21 10:20 ` Wei Liu
2017-07-24 10:10 ` Ian Jackson
0 siblings, 2 replies; 5+ messages in thread
From: Victor Kirhenshtein @ 2017-07-21 10:18 UTC (permalink / raw)
To: Wei Liu; +Cc: Ian Jackson, xen-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 5297 bytes --]
It is 4.4.1 (4.4.1-9+deb8u9 from Debian 8 repository). Looks like
Debian just have too old version in repository. Problem is not
reproduces on 4.6.5.
Best regards,
Victor Kirhenshtein
-----Original Message-----
From: Wei Liu <wei.liu2@citrix.com>
To: Victor Kirhenshtein <victor@radensolutions.com>
Cc: xen-devel@lists.xen.org, Wei Liu <wei.liu2@citrix.com>, Ian Jackson
<Ian.Jackson@eu.citrix.com>
Subject: Re: [Xen-devel] [BUG] libxl_ctx_free calls close(0)
Date: Fri, 21 Jul 2017 09:20:38 +0100
CC Ian Jackson
I don't know which version of Xen you're using. Can you check if it
contains the following commit?
commit fa13f7b0c0f3d01741e35d573009503c3bf7b6a6
Author: Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Aug 18 14:02:37 2014 +0100
Commit: Ian Campbell <ian.campbell@citrix.com>
CommitDate: Wed Aug 27 02:30:25 2014 +0100
tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
Reported-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
On Thu, Jul 20, 2017 at 08:36:28PM +0300, Victor Kirhenshtein wrote:
>
> Hello,
>
> it seems that libxl_ctx_free always calls close(0) for some
> reason, even if libxl never opens file descriptor 0. It sometimes
> closes valid descriptor in application causing random and
> hard to debug I/O errors.
>
> The following simple program can be used to reproduce this bug:
>
> #include <stdio.h>
> #include <libxl.h>
>
> static void LogMessage(struct xentoollog_logger *logger,
> xentoollog_level level,
> int errnoval /* or -1 */,
> const char *context /* eg "xc", "xl", may be 0
> */,
> const char *format /* without level, context, \n
> */,
> va_list al)
> {
> }
>
> static void LogProgress(struct xentoollog_logger *logger,
> const char *context /* see above */,
> const char *doing_what /* no \r,\n */,
> int percent, unsigned long done, unsigned long
> total)
> {
> }
>
> static void LogDestroy(struct xentoollog_logger *logger)
> {
> }
>
>
> int main(int argc, char *argv[])
> {
> xentoollog_logger logger;
> logger.vmessage = LogMessage;
> logger.progress = LogProgress;
> logger.destroy = LogDestroy;
>
> libxl_ctx *ctx;
> int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, &logger);
> if (rc != 0)
> {
> printf("libxl_ctx_alloc failed (%d)\n", rc);
> return 1;
> }
>
>
> libxl_ctx_free(ctx);
> return 0;
> }
>
> Strace output for it is following (I omit shared library
> loading on startup):
>
> set_tid_address(0x7f787db29a50) = 17944
> set_robust_list(0x7f787db29a60, 24) = 0
> rt_sigaction(SIGRTMIN, {0x7f787c4809b0, [], SA_RESTORER|SA_SIGINFO,
> 0x7f787c489890}, NULL, 8) = 0
> rt_sigaction(SIGRT_1, {0x7f787c480a40, [],
> SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f787c489890}, NULL, 8) = 0
> rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
> getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024,
> rlim_max=RLIM64_INFINITY})
> = 0
> brk(0) = 0x156d000
> brk(0x158e000) = 0x158e000
> pipe([3, 4]) = 0
> fcntl(3, F_GETFL) = 0 (flags O_RDONLY)
> fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
> fcntl(4, F_GETFL) = 0x1 (flags O_WRONLY)
> fcntl(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
> open("/proc/xen/privcmd", O_RDWR) = 5
> fcntl(5, F_GETFD) = 0
> fcntl(5, F_SETFD, FD_CLOEXEC) = 0
> stat("/var/run/xenstored/socket", {st_mode=S_IFSOCK|0600, st_size=0,
> ...}) = 0
> socket(PF_LOCAL, SOCK_STREAM, 0) = 6
> fcntl(6, F_GETFD) = 0
> fcntl(6, F_SETFD, FD_CLOEXEC) = 0
> connect(6, {sa_family=AF_LOCAL,
> sun_path="/var/run/xenstored/socket"},
> 110) = 0
> close(5) = 0
> close(6) = 0
> close(3) = 0
> close(4) = 0
> close(0) = 0
> exit_group(0) = ?
> +++ exited with 0 +++
>
> Best regards,
> Victor Kirhenshtein
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel
[-- Attachment #1.1.2: Type: text/html, Size: 8793 bytes --]
[-- Attachment #1.2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 4967 bytes --]
[-- Attachment #2: Type: text/plain, Size: 127 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [BUG] libxl_ctx_free calls close(0)
2017-07-21 10:18 ` Victor Kirhenshtein
@ 2017-07-21 10:20 ` Wei Liu
2017-07-24 10:10 ` Ian Jackson
1 sibling, 0 replies; 5+ messages in thread
From: Wei Liu @ 2017-07-21 10:20 UTC (permalink / raw)
To: Victor Kirhenshtein; +Cc: Ian Jackson, Wei Liu, xen-devel
On Fri, Jul 21, 2017 at 01:18:52PM +0300, Victor Kirhenshtein wrote:
> It is 4.4.1 (4.4.1-9+deb8u9 from Debian 8 repository). Looks like
> Debian just have too old version in repository. Problem is not
> reproduces on 4.6.5.
Right. That commit is included in 4.5, not 4.4.
Just backporting that one patch should fix your problem.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] libxl_ctx_free calls close(0)
2017-07-21 10:18 ` Victor Kirhenshtein
2017-07-21 10:20 ` Wei Liu
@ 2017-07-24 10:10 ` Ian Jackson
1 sibling, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2017-07-24 10:10 UTC (permalink / raw)
To: Victor Kirhenshtein; +Cc: Wei Liu, xen-devel
Victor Kirhenshtein writes ("Re: [Xen-devel] [BUG] libxl_ctx_free calls close(0)"):
> It is 4.4.1 (4.4.1-9+deb8u9 from Debian 8 repository). Looks like Debian just
> have too old version in repository. Problem is not reproduces on 4.6.5.
Debian jessie is not likely to get significant updates to its Xen
packages, I'm afraid.
If this is a new setup you are building, I recommend using stretch.
Currently, jessie also has outstanding security issues. Xen 4.4 is
out of upstream security support.
Ian.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-07-24 10:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-20 17:36 [BUG] libxl_ctx_free calls close(0) Victor Kirhenshtein
2017-07-21 8:20 ` Wei Liu
2017-07-21 10:18 ` Victor Kirhenshtein
2017-07-21 10:20 ` Wei Liu
2017-07-24 10:10 ` Ian Jackson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).