gpg crashes when it receives a SIGTERM while it's cleaning up
Closed, ResolvedPublic

Description

It just happened to me that gpg crashed:

#0  0x00007f53f8a54b88 in _gcry_secmem_term () at secmem.c:707
  [Error: secmem.c was not found in source tree]
#1  0x00007f53f8a4f4a6 in _gcry_vcontrol (cmd=<optimized out>,
arg_ptr=arg_ptr@entry=0x7ffc8ec64650) at global.c:397
  [Error: global.c was not found in source tree]
#2  0x00007f53f8a4bf99 in gcry_control (cmd=<optimized out>) at visibility.c:79
  [Error: visibility.c was not found in source tree]
#3  0x0000564693438eb6 in got_fatal_signal (sig=11) at signal.c:109
  104:   if (caught_fatal_sig)
  105:     raise (sig);
  106:   caught_fatal_sig = 1;
  107: 
  108:   if (cleanup_fnc)
  109:     cleanup_fnc ();
  110:   /* Better don't translate these messages. */
  111:   (void)write (2, "\n", 1 );
  112:   s = log_get_prefix (NULL);
  113:   if (s)
  114:     (void)write(2, s, strlen (s));
#4  <signal handler called>
#5  0x00007f53f8a54b88 in _gcry_secmem_term () at secmem.c:707
  [Error: secmem.c was not found in source tree]
#6  0x00007f53f8a4f4a6 in _gcry_vcontrol (cmd=<optimized out>,
arg_ptr=arg_ptr@entry=0x7ffc8ec64d90) at global.c:397
  [Error: global.c was not found in source tree]
#7  0x00007f53f8a4bf99 in gcry_control (cmd=<optimized out>) at visibility.c:79
  [Error: visibility.c was not found in source tree]
#8  0x0000564693438eb6 in got_fatal_signal (sig=15) at signal.c:109
  104:   if (caught_fatal_sig)
  105:     raise (sig);
  106:   caught_fatal_sig = 1;
  107: 
  108:   if (cleanup_fnc)
  109:     cleanup_fnc ();
  110:   /* Better don't translate these messages. */
  111:   (void)write (2, "\n", 1 );
  112:   s = log_get_prefix (NULL);
  113:   if (s)
  114:     (void)write(2, s, strlen (s));
#9  <signal handler called>
#10 0x00007f53f810de87 in munmap () at ../sysdeps/unix/syscall-template.S:84
  [Error: syscall-template.S was not found in source tree]
#11 0x00007f53f8a54d4d in _gcry_secmem_term () at secmem.c:713
  [Error: secmem.c was not found in source tree]
#12 0x00007f53f8a4f4a6 in _gcry_vcontrol (cmd=<optimized out>,
arg_ptr=arg_ptr@entry=0x7ffc8ec654d0) at global.c:397
  [Error: global.c was not found in source tree]
#13 0x00007f53f8a4bf99 in gcry_control (cmd=<optimized out>) at visibility.c:79
  [Error: visibility.c was not found in source tree]
#14 0x00005646933ad54e in emergency_cleanup () at gpg.c:4652
  4647: 
  4648: /* Note: This function is used by signal handlers!. */
  4649: static void
  4650: emergency_cleanup (void)
  4651: {
  4652:   gcry_control (GCRYCTL_TERM_SECMEM );
  4653: }
  4654: 
  4655: 
  4656: void
  4657: g10_exit( int rc )
#15 g10_exit (rc=0) at gpg.c:4672
  4667:       gcry_control (GCRYCTL_DUMP_RANDOM_STATS);
  4668:     }
  4669:   if (opt.debug)
  4670:     gcry_control (GCRYCTL_DUMP_SECMEM_STATS );
  4671: 
  4672:   emergency_cleanup ();
  4673: 
  4674:   rc = rc? rc : log_get_errorcount(0)? 2 : g10_errors_seen? 1 : 0;
  4675:   exit (rc);
  4676: }
  4677: 
#16 0x00005646933a9b24 in main (argc=0, argv=0x7ffc8ec65be8) at gpg.c:4643
  4638:     gpg_deinit_default_ctrl (ctrl);
  4639:     xfree (ctrl);
  4640:     release_armor_context (afx);
  4641:     FREE_STRLIST(remusr);
  4642:     FREE_STRLIST(locusr);
  4643:     g10_exit(0);
  4644:     return 8; /*NEVER REACHED*/
  4645: }
  4646: 
  4647: 
  4648: /* Note: This function is used by signal handlers!. */

Turns out that Evolution is calling gpg2 and it sends SIGTERM when it feels like
aborting the operation:
https://git.gnome.org/browse/evolution-data-server/tree/src/camel/camel-gpg-context.c#n1279

Related Objects

4tmuelle set Version to 2.1.Oct 11 2016, 2:26 PM
4tmuelle added a project: Bug Report.
4tmuelle added a subscriber: 4tmuelle.
marcus updated the task description. (Show Details)Jul 24 2017, 7:24 PM
marcus added a subscriber: marcus.Jul 25 2017, 5:46 PM

What catches my eye is that emergency_cleanup() is not guarded from being invoked twice in the way that got_fatal_signal() is.

gniibe claimed this task.Jun 4 2019, 6:43 AM
gniibe closed this task as Resolved.
gniibe added a subscriber: gniibe.

Fixed in master. Closing.