Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Crashes randomly after reading tls stuff (Debian, GNU TLS) #4484

Closed

Description

@michaelrsweet

Version: 1.7.5
CUPS.org User: odyx

Hi,

Bastian Blank has reported the Debian bug https://bugs.debian.org/760476 with the following strace log:

accept(8, {sa_family=AF_INET, sin_port=htons(60862), sin_addr=inet_addr("192.0.2.1")}, [16]) = 16
getsockname(16, {sa_family=AF_INET, sin_port=htons(631), sin_addr=inet_addr("192.0.2.1")}, [16]) = 0
setsockopt(16, SOL_TCP, TCP_NODELAY, [1], 4) = 0
fcntl(16, F_GETFD) = 0
fcntl(16, F_SETFD, FD_CLOEXEC) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 16, {EPOLLIN, {u32=3313009952, u64=140470218425632}}) = 0
epoll_wait(3, {{EPOLLIN, {u32=3313009952, u64=140470218425632}}}, 4096, 1000) = 1
recvfrom(16, "\26", 1, MSG_PEEK, NULL, NULL) = 1
access("/etc/cups/ssl/server.key", F_OK) = 0
access("/etc/cups/ssl/server.crt", F_OK) = 0
open("/etc/cups/ssl/server.key", O_RDONLY) = 17
fstat(17, {st_mode=S_IFREG|0640, st_size=1704, ...}) = 0
fstat(17, {st_mode=S_IFREG|0640, st_size=1704, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc1c411a000
lseek(17, 0, SEEK_CUR) = 0
read(17, "-----BEGIN PRIVATE KEY-----\nMIIE"..., 4096) = 1704
read(17, "", 4096) = 0
close(17) = 0
munmap(0x7fc1c411a000, 4096) = 0
open("/etc/cups/ssl/server.crt", O_RDONLY) = 17
fstat(17, {st_mode=S_IFREG|0644, st_size=1025, ...}) = 0
fstat(17, {st_mode=S_IFREG|0644, st_size=1025, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc1c411a000
lseek(17, 0, SEEK_CUR) = 0
read(17, "-----BEGIN CERTIFICATE-----\nMIIC"..., 4096) = 1025
read(17, "", 4096) = 0
close(17) = 0
munmap(0x7fc1c411a000, 4096) = 0
clock_gettime(CLOCK_REALTIME, {1409732232, 52793719}) = 0
getrusage(0x1 /* RUSAGE_??? */, {ru_utime={0, 732045}, ru_stime={0, 280017}, ...}) = 0
read(3, 0x7fffe61990b0, 16) = -1 EINVAL (Invalid argument)
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
tgkill(18683, 18683, SIGABRT) = 0
--- SIGABRT (Aborted) @ 0 (0) ---

I don't think we're modifying these codepaths in our distribution-specific patches [0] though.

Cheers,

OdyX

[0] http://anonscm.debian.org/cgit/printing/cups.git/tree/debian/patches

Activity

  1. michaelrsweet commented on Sep 16, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Didier, GNU TLS is aborting the process (never appropriate behavior for a library...), and without a backtrace it is impossible to diagnose this further.

    Feel free to re-open if you determine there is something in CUPS that needs to be fixed, but right now it looks like GNU TLS doesn't like something and isn't being nice enough to allow cupsd to deal with it.

  2. michaelrsweet commented on Oct 29, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: odyx

    This issue got discussed for some time, with new strace dumps (see https://bugs.debian.org/760476 for the full discussion). The conclusion seems to be that CUPS is "closing all file descriptors" at some point (including closing the /dev/urandom fd, which GnuTLS is using). Would this ring a bell for you, somewhere in the CUPS code?

    Cheers, OdyX

  3. michaelrsweet commented on Oct 29, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Re-opening for discussion, but this is not just CUPS.

    The only time cupsd closes all file descriptors is on initial launch when running in "daemon mode", like any other well-behaved daemon. And then we exec ourselves to avoid any nonsense with init on load code that DBUS uses. The only bug here seems to be that when running in child mode we are still closing the file descriptors...

    But, looking at the latest strace output it appears that GNU TLS has some init on load code that opens /dev/urandom, which is extremely odd given that you MUST call gnutls_global_init() before you use the library. This will cause problems for any daemon process since closing extra file descriptors is standard operating procedure.

    So it looks like you also need to fix GNU TLS to only open /dev/urandom when gnutls_global_init() is called and not before.

  4. michaelrsweet commented on Oct 29, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: nikmav

    Hi,
    I'm the author of gnutls. In 3.3.0 we made gnutls_global_init() optional [0], and is no longer required to be called to use the library. As Linux only supports randomness via a file descriptor we need to open /dev/urandom early and keep its fd (to avoid issues with servers which chroot in an environment without /dev/urandom). If you cannot avoid the mass fd closing, would a new function gnutls_fd_in_use() [1] solve the issue of cups?

    [0]. http://www.gnutls.org/manual/gnutls.html#Initialization

    [1]. https://gitorious.org/gnutls/gnutls/commit/2c12530bacc89485e807ec18ae455f4e190b383f

  5. michaelrsweet commented on Oct 31, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: nikmav

    I'm thinking of an alternative approach that will reopen the fd on the first call to gnutls_global_init() by the application if it is not available. That would solve the issue transparently for cups.

    https://www.gitorious.org/gnutls/gnutls/commit/684b825f5f78cc7ad1f61be232fd20ee0bc5b56f

  6. michaelrsweet commented on Nov 6, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: odyx

    Mike: I see you've marked this as pending; I assume you have a plan? I'm looking forward to a patch that would apply to 1.7.5 as that's the version we'll release the future stable release with. :)

  7. michaelrsweet commented on Nov 12, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Nikos: Having a gnutls_fd_in_use function isn't really useful, as it makes for a fragile API. I do understand the issues of needing to open /dev/urandom early, however since you've required applications to call gnutls_global_init for a long time it seems like the change to not require it (or at least moving its actions to load-time initializations) has unwanted side effects. Previously an application could make sure that initializations were done at an appropriate time, and now you've made that impossible...

    Didier: The change should be usable with 1.7.x, although you might need to tweak it slightly. All in the main() function anyways...

  8. michaelrsweet commented on Nov 12, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Fixed in Subversion repository.

  9. michaelrsweet commented on Nov 12, 2014

    @michaelrsweet
    ContributorAuthor

    "str4484.patch":

    Index: scheduler/main.c

    --- scheduler/main.c (revision 12243)
    +++ scheduler/main.c (working copy)
    @@ -100,7 +100,11 @@
    {
    int i; /* Looping var /
    char *opt; /
    Option character */

    • int fg; /* Run in the foreground */
    • int close_all = 1, /* Close all file descriptors? */
    •       disconnect = 1, /\* Disconnect from controlling terminal? */
      
    •       fg = 0,     /\* Run in foreground? */
      
    •       run_as_child = 0;
      
    •               /\* Running as child process? _/
      
      int fds; /_ Number of ready descriptors /
      cupsd_client_t *con; /
      Current client /
      cupsd_job_t *job; /
      Current job /
      @@ -116,8 +120,6 @@
      #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
      struct sigaction action; /
      Actions for POSIX signals /
      #endif /
      HAVE_SIGACTION && !HAVE_SIGSET */
    • int run_as_child = 0;
    •               /\* Needed for background fork/exec _/
      
      #ifdef APPLE
      int use_sysman = 1; /_ Use system management functions? */
      #else
      @@ -150,8 +152,10 @@
      #ifdef HAVE_LAUNCHD
      if (getenv("CUPSD_LAUNCHD"))
      {
    • OnDemand = 1;
    • fg = 1;
    • OnDemand = 1;
    • fg = 1;
    • close_all = 0;
    • disconnect = 0;
      }
      #endif /* HAVE_LAUNCHD */

    @@ -162,7 +166,8 @@
    {
    case 'C' : /* Run as child with config file */
    run_as_child = 1;

    •     fg           = -1;
      
    •     fg           = 1;
      
    •     close_all    = 0;
      

      case 'c' : /* Configuration file */
      i ++;
      @@ -217,11 +222,14 @@
      break;

         case 'f' : /* Run in foreground... */
      
    •     fg = 1;
      
    •     fg         = 1;
      
    •     disconnect = 0;
      
    •     close_all  = 0;
        break;
      
         case 'F' : /* Run in foreground, but disconnect from terminal... */
      
    •     fg = -1;
      
    •     fg        = 1;
      
    •     close_all = 0;
        break;
      
         case 'h' : /* Show usage/help */
      

      @@ -230,12 +238,16 @@

         case 'l' : /* Started by launchd/systemd... */
      

      #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)

    •     OnDemand = 1;
      
    •     fg       = 1;
      
    •     OnDemand   = 1;
      
    •     fg         = 1;
      
    •     close_all  = 0;
      
    •     disconnect = 0;
      

      #else
      _cupsLangPuts(stderr, _("cupsd: On-demand support not compiled "
      "in, running in normal mode."));

    •          fg = 0;
      
    •          fg         = 0;
      
    •     disconnect = 1;
      
    •     close_all  = 1;
      

      #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
      break;

    @@ -244,6 +256,8 @@
    "use only!\n", stderr);
    stop_scheduler = 1;
    fg = 1;

    •     disconnect     = 0;
      
    •     close_all      = 0;
        break;
      
         case 'P' : /* Disable security profiles */
      

      @@ -285,6 +299,8 @@
      case 't' : /* Test the cupsd.conf file... */
      TestConfigFile = 1;
      fg = 1;

    •     disconnect     = 0;
      
    •     close_all      = 0;
        break;
      

      default : /* Unknown option */
      @@ -332,8 +348,57 @@
      free(filename);
      }

    • if (disconnect)

    • {

    • /*

    • * Make sure we aren't tying up any filesystems...

    • */

    • chdir("/");
    • /*
    • * Disconnect from the controlling terminal...
    • */
    • setsid();
    • }
    • if (close_all)
    • {
    • /*
    • * Close all open files...
    • */
    • getrlimit(RLIMIT_NOFILE, &limit);
    • for (i = 0; i < (int)limit.rlim_cur && i < 1024; i ++)
    •  close(i);
      
    • /*
    • * Redirect stdin/out/err to /dev/null...
    • */
    • if ((i = open("/dev/null", O_RDONLY)) != 0)
    • {
    •  dup2(i, 0);
      
    •  close(i);
      
    • }
    • if ((i = open("/dev/null", O_WRONLY)) != 1)
    • {
    •  dup2(i, 1);
      
    •  close(i);
      
    • }
    • if ((i = open("/dev/null", O_WRONLY)) != 2)
    • {
    •  dup2(i, 2);
      
    •  close(i);
      
    • }
    • }

    /*

    • * If the user hasn't specified "-f", run in the background...

      • Run in the background as needed...
        */

      if (!fg)
      @@ -408,74 +473,17 @@
      #endif /* OpenBSD && OpenBSD < 201211 */

      /*

    • * Since CoreFoundation and DBUS both create fork-unsafe data on execution of

    • * a program, and since this kind of really unfriendly behavior seems to be

    • * more common these days in system libraries, we need to re-execute the

    • * background cupsd with the "-C" option to avoid problems. Unfortunately,

    • * we also have to assume that argv[0] contains the name of the cupsd

    • * executable - there is no portable way to get the real pathname...

    • * Since many system libraries create fork-unsafe data on execution of a

    • * program, we need to re-execute the background cupsd with the "-C" and "-s"

    • * options to avoid problems. Unfortunately, we also have to assume that

    • * argv[0] contains the name of the cupsd executable - there is no portable

      • way to get the real pathname...
        */
    • execlp(argv[0], argv[0], "-C", ConfigurationFile, (char *)0);

    • execlp(argv[0], argv[0], "-C", ConfigurationFile, "-s", CupsFilesFile, (char *)0);
      exit(errno);
      }

    • if (fg < 1)

    • {

    • /*

    • * Make sure we aren't tying up any filesystems...

    - */

    - chdir("/");

    -#ifndef DEBUG

    • /*
    • * Disable core dumps...

    - */

    • getrlimit(RLIMIT_CORE, &limit);
    • limit.rlim_cur = 0;

    - setrlimit(RLIMIT_CORE, &limit);

    • /*
    • * Disconnect from the controlling terminal...

    - */

    - setsid();

    • /*
    • * Close all open files...

    - */

    - getrlimit(RLIMIT_NOFILE, &limit);

    • for (i = 0; i < limit.rlim_cur && i < 1024; i ++)

    - close(i);

    • /*
    • * Redirect stdin/out/err to /dev/null...

    - */

    • if ((i = open("/dev/null", O_RDONLY)) != 0)
    • {
    •  dup2(i, 0);
      
    •  close(i);
      

    - }

    • if ((i = open("/dev/null", O_WRONLY)) != 1)
    • {
    •  dup2(i, 1);
      
    •  close(i);
      

    - }

    • if ((i = open("/dev/null", O_WRONLY)) != 2)
    • {
    •  dup2(i, 2);
      
    •  close(i);
      
    • }
      -#endif /* DEBUG */

    - }

    /*

    • Set the timezone info...
      */
  10. michaelrsweet commented on Nov 12, 2014

    @michaelrsweet
    ContributorAuthor

    "str4484-1.7.patch":

    --- a/scheduler/main.c
    +++ b/scheduler/main.c
    @@ -100,6 +100,8 @@
    int i; /* Looping var /
    char *opt; /
    Option character /
    int fg; /
    Run in the foreground */

    • int close_all = 1, /* Close all file descriptors? */
    •       disconnect = 1; /\* Disconnect from controlling terminal? _/
      
      int fds; /_ Number of ready descriptors /
      cupsd_client_t *con; /
      Current client /
      cupsd_job_t *job; /
      Current job */
      @@ -152,6 +154,8 @@
      {
      Launchd = 1;
      fg = 1;
    • close_all = 0;
    • disconnect = 0;
      }
      #endif /* HAVE_LAUNCHD */

    @@ -163,6 +167,7 @@
    case 'C' : /* Run as child with config file */
    run_as_child = 1;
    fg = -1;

    •     close_all    = 0;
      

      case 'c' : /* Configuration file */
      i ++;
      @@ -218,10 +223,13 @@

         case 'f' : /* Run in foreground... */
        fg = 1;
      
    •     disconnect = 0;
      
    •     close_all  = 0;
        break;
      
         case 'F' : /* Run in foreground, but disconnect from terminal... */
        fg = -1;
      
    •     close_all = 0;
        break;
      
         case 'h' : /* Show usage/help */
      

      @@ -232,10 +240,14 @@
      #ifdef HAVE_LAUNCHD
      Launchd = 1;
      fg = 1;

    •          close_all  = 0;
      
    •          disconnect = 0;
      

      #else
      _cupsLangPuts(stderr, _("cupsd: launchd(8) support not compiled "
      "in, running in normal mode."));
      fg = 0;

    •          disconnect = 1;
      
    •          close_all  = 1;
      

      #endif /* HAVE_LAUNCHD */
      break;

    @@ -244,6 +256,8 @@
    "use only!\n", stderr);
    stop_scheduler = 1;
    fg = 1;

    •     disconnect     = 0;
      
    •     close_all      = 0;
        break;
      
         case 'P' : /* Disable security profiles */
      

      @@ -286,6 +300,8 @@
      case 't' : /* Test the cupsd.conf file... */
      TestConfigFile = 1;
      fg = 1;

    •     disconnect     = 0;
      
    •     close_all      = 0;
        break;
      

      default : /* Unknown option */
      @@ -333,8 +349,57 @@
      free(filename);
      }

    • if (disconnect)

    • {

    • /*

    • * Make sure we aren't tying up any filesystems...

    • */

    • chdir("/");
    • /*
    • * Disconnect from the controlling terminal...
    • */
    • setsid();
    • }
    • if (close_all)
    • {
    • /*
    • * Close all open files...
    • */
    • getrlimit(RLIMIT_NOFILE, &limit);
    • for (i = 0; i < (int)limit.rlim_cur && i < 1024; i ++)
    •  close(i);
      
    • /*
    • * Redirect stdin/out/err to /dev/null...
    • */
    • if ((i = open("/dev/null", O_RDONLY)) != 0)
    • {
    •  dup2(i, 0);
      
    •  close(i);
      
    • }
    • if ((i = open("/dev/null", O_WRONLY)) != 1)
    • {
    •  dup2(i, 1);
      
    •  close(i);
      
    • }
    • if ((i = open("/dev/null", O_WRONLY)) != 2)
    • {
    •  dup2(i, 2);
      
    •  close(i);
      
    • }
    • }

    /*

    • * If the user hasn't specified "-f", run in the background...

      • Run in the background as needed...
        */

      if (!fg)
      @@ -409,74 +474,17 @@
      #endif /* OpenBSD && OpenBSD < 201211 */

      /*

    • * Since CoreFoundation and DBUS both create fork-unsafe data on execution of

    • * a program, and since this kind of really unfriendly behavior seems to be

    • * more common these days in system libraries, we need to re-execute the

    • * background cupsd with the "-C" option to avoid problems. Unfortunately,

    • * we also have to assume that argv[0] contains the name of the cupsd

    • * executable - there is no portable way to get the real pathname...

    • * Since many system libraries create fork-unsafe data on execution of a

    • * program, we need to re-execute the background cupsd with the "-C" and "-s"

    • * options to avoid problems. Unfortunately, we also have to assume that

    • * argv[0] contains the name of the cupsd executable - there is no portable

      • way to get the real pathname...
        */
    • execlp(argv[0], argv[0], "-C", ConfigurationFile, (char *)0);

    • execlp(argv[0], argv[0], "-C", ConfigurationFile, "-s", CupsFilesFile, (char *)0);
      exit(errno);
      }

    • if (fg < 1)

    • {

    • /*

    • * Make sure we aren't tying up any filesystems...

    - */

    - chdir("/");

    -#ifndef DEBUG

    • /*
    • * Disable core dumps...

    - */

    • getrlimit(RLIMIT_CORE, &limit);
    • limit.rlim_cur = 0;

    - setrlimit(RLIMIT_CORE, &limit);

    • /*
    • * Disconnect from the controlling terminal...

    - */

    - setsid();

    • /*
    • * Close all open files...

    - */

    - getrlimit(RLIMIT_NOFILE, &limit);

    • for (i = 0; i < limit.rlim_cur && i < 1024; i ++)

    - close(i);

    • /*
    • * Redirect stdin/out/err to /dev/null...

    - */

    • if ((i = open("/dev/null", O_RDONLY)) != 0)
    • {
    •  dup2(i, 0);
      
    •  close(i);
      

    - }

    • if ((i = open("/dev/null", O_WRONLY)) != 1)
    • {
    •  dup2(i, 1);
      
    •  close(i);
      

    - }

    • if ((i = open("/dev/null", O_WRONLY)) != 2)
    • {
    •  dup2(i, 2);
      
    •  close(i);
      
    • }
      -#endif /* DEBUG */

    - }

    /*

    • Set the timezone info...
      */
  11. michaelrsweet commented on Nov 13, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: alexk

    @@ -230,12 +238,16 @@

           case 'l' : /* Started by launchd/systemd... */
    

    #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)

    •     OnDemand = 1;
      
    •     fg       = 1;
      
    •     OnDemand   = 1;
      
    •     fg         = 1;
      
    •     close_all  = 0;
      
    •     disconnect = 0;
      

    CUPS 1.7.5 has Launchd = 1 here and in a few other places. Should OnDemand be renamed to LaunchD for 1.7.5 patch?

    Also, in the majority of updates fg retains its value, but in a couple of them it changes. It is expected and not a copy/paste error, right?

    •     fg           = -1;
      
    •     fg           = 1;
      
  12. michaelrsweet commented on Nov 13, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Yes, when we added support for systemd I changed "launchd" named variables to "ondemand" to make things more general purpose.

    As for the "fg" changes, yes I decided to clean that up because the different values were starting to get hard to track - instead it now just determines whether cupsd runs in the foreground, with the other variables tracking how things are initialized...

  13. michaelrsweet commented on Nov 17, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: odyx

    Hi Mike,

    given that Debian's now in freeze, I'd like to only import minimal changes; would the attached patch (none of the 'fg' changes) be working correctly on top of 1.7 ?

    TIA, cheers, OdyX

  14. michaelrsweet commented on Nov 17, 2014

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Looks good.

  15. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions