Merge lp:~adam-stokes/ubuntu/quantal/libgcrypt11/libgcrypt-fix-423252 into lp:ubuntu/quantal/libgcrypt11

Proposed by Adam Stokes
Status: Merged
Merge reported by: Adam Conrad
Merged at revision: not available
Proposed branch: lp:~adam-stokes/ubuntu/quantal/libgcrypt11/libgcrypt-fix-423252
Merge into: lp:ubuntu/quantal/libgcrypt11
Diff against target: 1188 lines (+1133/-2)
8 files modified
.pc/.quilt_patches (+1/-0)
.pc/.quilt_series (+1/-0)
.pc/applied-patches (+1/-0)
.pc/no-global-init-thread-callbacks.diff/src/global.c (+1112/-0)
debian/changelog (+6/-0)
debian/patches/no-global-init-thread-callbacks.diff (+11/-0)
debian/patches/series (+1/-0)
src/global.c (+0/-2)
To merge this branch: bzr merge lp:~adam-stokes/ubuntu/quantal/libgcrypt11/libgcrypt-fix-423252
Reviewer Review Type Date Requested Status
Brian Murray Needs Fixing
Review via email: mp+105863@code.launchpad.net

Description of the change

[Impact]
As heavily outlined in the amount of comments in this bug the impact is detrimental to both community and enterprise users alike.

[Development Fix]
Howard Chu released a patch in #73 which was later confirmed in #106 & #108 as a resolution. The patch has since then made its way into the latest development tree.

[Stable Fix]
Patch from #73 can be applied cleanly to Lucid and new distributions.

[Test Case]
On Karmic (alpha 4 plus updates), changing the nsswitch.conf 'passwd' field to anything with 'ldap' as the first item breaks the ability to become root using 'su' and 'sudo' as anyone but root.

Default nsswitch.conf:

passwd: compat
group: compat
shadow: compat

matt@box:~$ sudo uname -a
[sudo] password for matt:
Linux box 2.6.31-9-server #29-Ubuntu SMP Sun Aug 30 18:37:42 UTC 2009 x86_64 GNU/Linux

matt@box:~$ su -
Password:
root@box:~#

Modified nsswitch.conf with 'ldap' before 'compat':

passwd: ldap compat
group: ldap compat
shadow: ldap compat

matt@box:~$ sudo uname -a
sudo: setreuid(ROOT_UID, user_uid): Operation not permitted

matt@box:~$ su -
Password:
setgid: Operation not permitted

Modified nsswitch.conf with 'ldap' after 'compat':

passwd: compat ldap
group: compat ldap
shadow: compat ldap

matt@box:~$ sudo uname -a
[sudo] password for matt:
Linux box 2.6.31-9-server #29-Ubuntu SMP Sun Aug 30 18:37:42 UTC 2009 x86_64 GNU/Linux

matt@box:~$ su -
Password:
root@box:~#

The same arrangements in nsswitch.conf work as expected in Jaunty and earlier releases.

[Regression Potential]
This should be minimal as the code change only addresses the duplicating global_init during thread callbacks.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

The debian changelog should reference the bug number via (LP: #423252), the distribution should be quantal not unstable, the package version number should be Ubuntu specific.

review: Needs Fixing
34. By Adam Stokes

Fix changelog output to ubuntu versioning, quantal release, and correct LP tag

Revision history for this message
Adam Stokes (adam-stokes) wrote :

> The debian changelog should reference the bug number via (LP: #423252), the
> distribution should be quantal not unstable, the package version number should
> be Ubuntu specific.

Addressed these issues in latest commit.

Thanks!

Revision history for this message
Adam Conrad (adconrad) wrote :

Looks like you forgot to run "update-maintainer" after making the ubuntu-specific changes. I've done that for you and uploaded.

Also, merge proposals (and diffs in general) that include the .pc mess are slightly painful to work with. ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.pc/.quilt_patches'
2--- .pc/.quilt_patches 1970-01-01 00:00:00 +0000
3+++ .pc/.quilt_patches 2012-05-15 18:22:18 +0000
4@@ -0,0 +1,1 @@
5+debian/patches
6
7=== added file '.pc/.quilt_series'
8--- .pc/.quilt_series 1970-01-01 00:00:00 +0000
9+++ .pc/.quilt_series 2012-05-15 18:22:18 +0000
10@@ -0,0 +1,1 @@
11+series
12
13=== modified file '.pc/applied-patches'
14--- .pc/applied-patches 2011-09-01 18:53:49 +0000
15+++ .pc/applied-patches 2012-05-15 18:22:18 +0000
16@@ -1,1 +1,2 @@
17 12_lessdeps_libgcrypt-config.diff
18+no-global-init-thread-callbacks.diff
19
20=== added directory '.pc/no-global-init-thread-callbacks.diff'
21=== added file '.pc/no-global-init-thread-callbacks.diff/.timestamp'
22=== added directory '.pc/no-global-init-thread-callbacks.diff/src'
23=== added file '.pc/no-global-init-thread-callbacks.diff/src/global.c'
24--- .pc/no-global-init-thread-callbacks.diff/src/global.c 1970-01-01 00:00:00 +0000
25+++ .pc/no-global-init-thread-callbacks.diff/src/global.c 2012-05-15 18:22:18 +0000
26@@ -0,0 +1,1112 @@
27+/* global.c - global control functions
28+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
29+ * 2004, 2005, 2006, 2008, 2011 Free Software Foundation, Inc.
30+ *
31+ * This file is part of Libgcrypt.
32+ *
33+ * Libgcrypt is free software; you can redistribute it and/or modify
34+ * it under the terms of the GNU Lesser general Public License as
35+ * published by the Free Software Foundation; either version 2.1 of
36+ * the License, or (at your option) any later version.
37+ *
38+ * Libgcrypt is distributed in the hope that it will be useful,
39+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
40+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41+ * GNU Lesser General Public License for more details.
42+ *
43+ * You should have received a copy of the GNU Lesser General Public
44+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
45+ */
46+
47+#include <config.h>
48+
49+#include <stdio.h>
50+#include <stdlib.h>
51+#include <string.h>
52+#include <stdarg.h>
53+#include <ctype.h>
54+#include <limits.h>
55+#include <errno.h>
56+#include <unistd.h>
57+#ifdef HAVE_SYSLOG
58+# include <syslog.h>
59+#endif /*HAVE_SYSLOG*/
60+
61+#include "g10lib.h"
62+#include "cipher.h"
63+#include "stdmem.h" /* our own memory allocator */
64+#include "secmem.h" /* our own secmem allocator */
65+#include "ath.h"
66+
67+
68
69+
70+/****************
71+ * flag bits: 0 : general cipher debug
72+ * 1 : general MPI debug
73+ */
74+static unsigned int debug_flags;
75+
76+/* gcry_control (GCRYCTL_SET_FIPS_MODE), sets this flag so that the
77+ initialization code switched fips mode on. */
78+static int force_fips_mode;
79+
80+/* Controlled by global_init(). */
81+static int any_init_done;
82+
83+/* A table to map hardware features to a string. */
84+static struct
85+{
86+ unsigned int flag;
87+ const char *desc;
88+} hwflist[] =
89+ {
90+ { HWF_PADLOCK_RNG, "padlock-rng" },
91+ { HWF_PADLOCK_AES, "padlock-aes" },
92+ { HWF_PADLOCK_SHA, "padlock-sha" },
93+ { HWF_PADLOCK_MMUL,"padlock-mmul"},
94+ { HWF_INTEL_AESNI, "intel-aesni" },
95+ { 0, NULL}
96+ };
97+
98+/* A bit vector with the hardware features which shall not be used.
99+ This variable must be set prior to any initialization. */
100+static unsigned int disabled_hw_features;
101+
102+
103+/* Memory management. */
104+
105+static gcry_handler_alloc_t alloc_func;
106+static gcry_handler_alloc_t alloc_secure_func;
107+static gcry_handler_secure_check_t is_secure_func;
108+static gcry_handler_realloc_t realloc_func;
109+static gcry_handler_free_t free_func;
110+static gcry_handler_no_mem_t outofcore_handler;
111+static void *outofcore_handler_value;
112+static int no_secure_memory;
113+
114+
115+
116
117+
118+
119+/* This is our handmade constructor. It gets called by any function
120+ likely to be called at startup. The suggested way for an
121+ application to make sure that this has been called is by using
122+ gcry_check_version. */
123+static void
124+global_init (void)
125+{
126+ gcry_error_t err = 0;
127+
128+ if (any_init_done)
129+ return;
130+ any_init_done = 1;
131+
132+ /* Initialize our portable thread/mutex wrapper. */
133+ err = ath_init ();
134+ if (err)
135+ goto fail;
136+
137+ /* See whether the system is in FIPS mode. This needs to come as
138+ early as possible put after the ATH has been initialized. */
139+ _gcry_initialize_fips_mode (force_fips_mode);
140+
141+ /* Before we do any other initialization we need to test available
142+ hardware features. */
143+ _gcry_detect_hw_features (disabled_hw_features);
144+
145+ err = _gcry_cipher_init ();
146+ if (err)
147+ goto fail;
148+ err = _gcry_md_init ();
149+ if (err)
150+ goto fail;
151+ err = _gcry_pk_init ();
152+ if (err)
153+ goto fail;
154+#if 0
155+ /* Hmmm, as of now ac_init does nothing. */
156+ if ( !fips_mode () )
157+ {
158+ err = _gcry_ac_init ();
159+ if (err)
160+ goto fail;
161+ }
162+#endif
163+
164+ return;
165+
166+ fail:
167+ BUG ();
168+}
169+
170+
171+/* This function is called by the macro fips_is_operational and makes
172+ sure that the minimal initialization has been done. This is far
173+ from a perfect solution and hides problems with an improper
174+ initialization but at least in single-threaded mode it should work
175+ reliable.
176+
177+ The reason we need this is that a lot of applications don't use
178+ Libgcrypt properly by not running any initialization code at all.
179+ They just call a Libgcrypt function and that is all what they want.
180+ Now with the FIPS mode, that has the side effect of entering FIPS
181+ mode (for security reasons, FIPS mode is the default if no
182+ initialization has been done) and bailing out immediately because
183+ the FSM is in the wrong state. If we always run the init code,
184+ Libgcrypt can test for FIPS mode and at least if not in FIPS mode,
185+ it will behave as before. Note that this on-the-fly initialization
186+ is only done for the cryptographic functions subject to FIPS mode
187+ and thus not all API calls will do such an initialization. */
188+int
189+_gcry_global_is_operational (void)
190+{
191+ if (!any_init_done)
192+ {
193+#ifdef HAVE_SYSLOG
194+ syslog (LOG_USER|LOG_WARNING, "Libgcrypt warning: "
195+ "missing initialization - please fix the application");
196+#endif /*HAVE_SYSLOG*/
197+ global_init ();
198+ }
199+ return _gcry_fips_is_operational ();
200+}
201+
202+
203+
204+
205
206+/* Version number parsing. */
207+
208+/* This function parses the first portion of the version number S and
209+ stores it in *NUMBER. On success, this function returns a pointer
210+ into S starting with the first character, which is not part of the
211+ initial number portion; on failure, NULL is returned. */
212+static const char*
213+parse_version_number( const char *s, int *number )
214+{
215+ int val = 0;
216+
217+ if( *s == '0' && isdigit(s[1]) )
218+ return NULL; /* leading zeros are not allowed */
219+ for ( ; isdigit(*s); s++ ) {
220+ val *= 10;
221+ val += *s - '0';
222+ }
223+ *number = val;
224+ return val < 0? NULL : s;
225+}
226+
227+/* This function breaks up the complete string-representation of the
228+ version number S, which is of the following struture: <major
229+ number>.<minor number>.<micro number><patch level>. The major,
230+ minor and micro number components will be stored in *MAJOR, *MINOR
231+ and *MICRO.
232+
233+ On success, the last component, the patch level, will be returned;
234+ in failure, NULL will be returned. */
235+
236+static const char *
237+parse_version_string( const char *s, int *major, int *minor, int *micro )
238+{
239+ s = parse_version_number( s, major );
240+ if( !s || *s != '.' )
241+ return NULL;
242+ s++;
243+ s = parse_version_number( s, minor );
244+ if( !s || *s != '.' )
245+ return NULL;
246+ s++;
247+ s = parse_version_number( s, micro );
248+ if( !s )
249+ return NULL;
250+ return s; /* patchlevel */
251+}
252+
253+/* If REQ_VERSION is non-NULL, check that the version of the library
254+ is at minimum the requested one. Returns the string representation
255+ of the library version if the condition is satisfied; return NULL
256+ if the requested version is newer than that of the library.
257+
258+ If a NULL is passed to this function, no check is done, but the
259+ string representation of the library is simply returned. */
260+const char *
261+gcry_check_version( const char *req_version )
262+{
263+ const char *ver = VERSION;
264+ int my_major, my_minor, my_micro;
265+ int rq_major, rq_minor, rq_micro;
266+ const char *my_plvl;
267+
268+ /* Initialize library. */
269+ global_init ();
270+
271+ if ( !req_version )
272+ /* Caller wants our version number. */
273+ return ver;
274+
275+ /* Parse own version number. */
276+ my_plvl = parse_version_string( ver, &my_major, &my_minor, &my_micro );
277+ if ( !my_plvl )
278+ /* very strange our own version is bogus. Shouldn't we use
279+ assert() here and bail out in case this happens? -mo. */
280+ return NULL;
281+
282+ /* Parse requested version number. */
283+ if (!parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro))
284+ return NULL; /* req version string is invalid, this can happen. */
285+
286+ /* Compare version numbers. */
287+ if ( my_major > rq_major
288+ || (my_major == rq_major && my_minor > rq_minor)
289+ || (my_major == rq_major && my_minor == rq_minor && my_micro > rq_micro)
290+ || (my_major == rq_major && my_minor == rq_minor
291+ && my_micro == rq_micro))
292+ {
293+ return ver;
294+ }
295+
296+ return NULL;
297+}
298+
299+
300+static void
301+print_config ( int (*fnc)(FILE *fp, const char *format, ...), FILE *fp)
302+{
303+ unsigned int hwf;
304+ int i;
305+
306+ fnc (fp, "version:%s:\n", VERSION);
307+ fnc (fp, "ciphers:%s:\n", LIBGCRYPT_CIPHERS);
308+ fnc (fp, "pubkeys:%s:\n", LIBGCRYPT_PUBKEY_CIPHERS);
309+ fnc (fp, "digests:%s:\n", LIBGCRYPT_DIGESTS);
310+ fnc (fp, "rnd-mod:"
311+#if USE_RNDEGD
312+ "egd:"
313+#endif
314+#if USE_RNDLINUX
315+ "linux:"
316+#endif
317+#if USE_RNDUNIX
318+ "unix:"
319+#endif
320+#if USE_RNDW32
321+ "w32:"
322+#endif
323+ "\n");
324+ fnc (fp, "mpi-asm:%s:\n", _gcry_mpi_get_hw_config ());
325+ hwf = _gcry_get_hw_features ();
326+ fnc (fp, "hwflist:");
327+ for (i=0; hwflist[i].desc; i++)
328+ if ( (hwf & hwflist[i].flag) )
329+ fnc (fp, "%s:", hwflist[i].desc);
330+ fnc (fp, "\n");
331+ /* We use y/n instead of 1/0 for the simple reason that Emacsen's
332+ compile error parser would accidently flag that line when printed
333+ during "make check" as an error. */
334+ fnc (fp, "fips-mode:%c:%c:\n",
335+ fips_mode ()? 'y':'n',
336+ _gcry_enforced_fips_mode ()? 'y':'n' );
337+}
338+
339+
340+
341
342+
343+/* Command dispatcher function, acting as general control
344+ function. */
345+gcry_error_t
346+_gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr)
347+{
348+ static int init_finished = 0;
349+ gcry_err_code_t err = 0;
350+
351+ switch (cmd)
352+ {
353+ case GCRYCTL_ENABLE_M_GUARD:
354+ _gcry_private_enable_m_guard ();
355+ break;
356+
357+ case GCRYCTL_ENABLE_QUICK_RANDOM:
358+ _gcry_enable_quick_random_gen ();
359+ break;
360+
361+ case GCRYCTL_FAKED_RANDOM_P:
362+ /* Return an error if the RNG is faked one (e.g. enabled by
363+ ENABLE_QUICK_RANDOM. */
364+ if (_gcry_random_is_faked ())
365+ err = GPG_ERR_GENERAL; /* Use as TRUE value. */
366+ break;
367+
368+ case GCRYCTL_DUMP_RANDOM_STATS:
369+ _gcry_random_dump_stats ();
370+ break;
371+
372+ case GCRYCTL_DUMP_MEMORY_STATS:
373+ /*m_print_stats("[fixme: prefix]");*/
374+ break;
375+
376+ case GCRYCTL_DUMP_SECMEM_STATS:
377+ _gcry_secmem_dump_stats ();
378+ break;
379+
380+ case GCRYCTL_DROP_PRIVS:
381+ global_init ();
382+ _gcry_secmem_init (0);
383+ break;
384+
385+ case GCRYCTL_DISABLE_SECMEM:
386+ global_init ();
387+ no_secure_memory = 1;
388+ break;
389+
390+ case GCRYCTL_INIT_SECMEM:
391+ global_init ();
392+ _gcry_secmem_init (va_arg (arg_ptr, unsigned int));
393+ if ((_gcry_secmem_get_flags () & GCRY_SECMEM_FLAG_NOT_LOCKED))
394+ err = GPG_ERR_GENERAL;
395+ break;
396+
397+ case GCRYCTL_TERM_SECMEM:
398+ global_init ();
399+ _gcry_secmem_term ();
400+ break;
401+
402+ case GCRYCTL_DISABLE_SECMEM_WARN:
403+ _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
404+ | GCRY_SECMEM_FLAG_NO_WARNING));
405+ break;
406+
407+ case GCRYCTL_SUSPEND_SECMEM_WARN:
408+ _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
409+ | GCRY_SECMEM_FLAG_SUSPEND_WARNING));
410+ break;
411+
412+ case GCRYCTL_RESUME_SECMEM_WARN:
413+ _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
414+ & ~GCRY_SECMEM_FLAG_SUSPEND_WARNING));
415+ break;
416+
417+ case GCRYCTL_USE_SECURE_RNDPOOL:
418+ global_init ();
419+ _gcry_secure_random_alloc (); /* Put random number into secure memory. */
420+ break;
421+
422+ case GCRYCTL_SET_RANDOM_SEED_FILE:
423+ _gcry_set_random_seed_file (va_arg (arg_ptr, const char *));
424+ break;
425+
426+ case GCRYCTL_UPDATE_RANDOM_SEED_FILE:
427+ if ( fips_is_operational () )
428+ _gcry_update_random_seed_file ();
429+ break;
430+
431+ case GCRYCTL_SET_VERBOSITY:
432+ _gcry_set_log_verbosity (va_arg (arg_ptr, int));
433+ break;
434+
435+ case GCRYCTL_SET_DEBUG_FLAGS:
436+ debug_flags |= va_arg (arg_ptr, unsigned int);
437+ break;
438+
439+ case GCRYCTL_CLEAR_DEBUG_FLAGS:
440+ debug_flags &= ~va_arg (arg_ptr, unsigned int);
441+ break;
442+
443+ case GCRYCTL_DISABLE_INTERNAL_LOCKING:
444+ /* Not used anymore. */
445+ global_init ();
446+ break;
447+
448+ case GCRYCTL_ANY_INITIALIZATION_P:
449+ if (any_init_done)
450+ err = GPG_ERR_GENERAL;
451+ break;
452+
453+ case GCRYCTL_INITIALIZATION_FINISHED_P:
454+ if (init_finished)
455+ err = GPG_ERR_GENERAL; /* Yes. */
456+ break;
457+
458+ case GCRYCTL_INITIALIZATION_FINISHED:
459+ /* This is a hook which should be used by an application after
460+ all initialization has been done and right before any threads
461+ are started. It is not really needed but the only way to be
462+ really sure that all initialization for thread-safety has
463+ been done. */
464+ if (! init_finished)
465+ {
466+ global_init ();
467+ /* Do only a basic random initialization, i.e. init the
468+ mutexes. */
469+ _gcry_random_initialize (0);
470+ init_finished = 1;
471+ /* Force us into operational state if in FIPS mode. */
472+ (void)fips_is_operational ();
473+ }
474+ break;
475+
476+ case GCRYCTL_SET_THREAD_CBS:
477+ err = ath_install (va_arg (arg_ptr, void *), any_init_done);
478+ if (! err)
479+ global_init ();
480+ break;
481+
482+ case GCRYCTL_FAST_POLL:
483+ /* We need to do make sure that the random pool is really
484+ initialized so that the poll function is not a NOP. */
485+ _gcry_random_initialize (1);
486+
487+ if ( fips_is_operational () )
488+ _gcry_fast_random_poll ();
489+ break;
490+
491+ case GCRYCTL_SET_RNDEGD_SOCKET:
492+#if USE_RNDEGD
493+ err = _gcry_rndegd_set_socket_name (va_arg (arg_ptr, const char *));
494+#else
495+ err = gpg_error (GPG_ERR_NOT_SUPPORTED);
496+#endif
497+ break;
498+
499+ case GCRYCTL_SET_RANDOM_DAEMON_SOCKET:
500+ _gcry_set_random_daemon_socket (va_arg (arg_ptr, const char *));
501+ break;
502+
503+ case GCRYCTL_USE_RANDOM_DAEMON:
504+ /* We need to do make sure that the random pool is really
505+ initialized so that the poll function is not a NOP. */
506+ _gcry_random_initialize (1);
507+ _gcry_use_random_daemon (!! va_arg (arg_ptr, int));
508+ break;
509+
510+ /* This command dumps information pertaining to the
511+ configuration of libgcrypt to the given stream. It may be
512+ used before the initialization has been finished but not
513+ before a gcry_version_check. */
514+ case GCRYCTL_PRINT_CONFIG:
515+ {
516+ FILE *fp = va_arg (arg_ptr, FILE *);
517+ print_config (fp?fprintf:_gcry_log_info_with_dummy_fp, fp);
518+ }
519+ break;
520+
521+ case GCRYCTL_OPERATIONAL_P:
522+ /* Returns true if the library is in an operational state. This
523+ is always true for non-fips mode. */
524+ if (_gcry_fips_test_operational ())
525+ err = GPG_ERR_GENERAL; /* Used as TRUE value */
526+ break;
527+
528+ case GCRYCTL_FIPS_MODE_P:
529+ if (fips_mode ()
530+ && !_gcry_is_fips_mode_inactive ()
531+ && !no_secure_memory)
532+ err = GPG_ERR_GENERAL; /* Used as TRUE value */
533+ break;
534+
535+ case GCRYCTL_FORCE_FIPS_MODE:
536+ /* Performing this command puts the library into fips mode. If
537+ the library has already been initialized into fips mode, a
538+ selftest is triggered. It is not possible to put the libraty
539+ into fips mode after having passed the initialization. */
540+ if (!any_init_done)
541+ {
542+ /* Not yet intialized at all. Set a flag so that we are put
543+ into fips mode during initialization. */
544+ force_fips_mode = 1;
545+ }
546+ else
547+ {
548+ /* Already initialized. If we are already operational we
549+ run a selftest. If not we use the is_operational call to
550+ force us into operational state if possible. */
551+ if (_gcry_fips_test_error_or_operational ())
552+ _gcry_fips_run_selftests (1);
553+ if (_gcry_fips_is_operational ())
554+ err = GPG_ERR_GENERAL; /* Used as TRUE value */
555+ }
556+ break;
557+
558+ case GCRYCTL_SELFTEST:
559+ /* Run a selftest. This works in fips mode as well as in
560+ standard mode. In contrast to the power-up tests, we use an
561+ extended version of the selftests. Returns 0 on success or an
562+ error code. */
563+ global_init ();
564+ err = _gcry_fips_run_selftests (1);
565+ break;
566+
567+#if _GCRY_GCC_VERSION >= 40600
568+# pragma GCC diagnostic push
569+# pragma GCC diagnostic ignored "-Wswitch"
570+#endif
571+ case 58: /* Init external random test. */
572+ {
573+ void **rctx = va_arg (arg_ptr, void **);
574+ unsigned int flags = va_arg (arg_ptr, unsigned int);
575+ const void *key = va_arg (arg_ptr, const void *);
576+ size_t keylen = va_arg (arg_ptr, size_t);
577+ const void *seed = va_arg (arg_ptr, const void *);
578+ size_t seedlen = va_arg (arg_ptr, size_t);
579+ const void *dt = va_arg (arg_ptr, const void *);
580+ size_t dtlen = va_arg (arg_ptr, size_t);
581+ if (!fips_is_operational ())
582+ err = fips_not_operational ();
583+ else
584+ err = _gcry_random_init_external_test (rctx, flags, key, keylen,
585+ seed, seedlen, dt, dtlen);
586+ }
587+ break;
588+ case 59: /* Run external random test. */
589+ {
590+ void *ctx = va_arg (arg_ptr, void *);
591+ void *buffer = va_arg (arg_ptr, void *);
592+ size_t buflen = va_arg (arg_ptr, size_t);
593+ if (!fips_is_operational ())
594+ err = fips_not_operational ();
595+ else
596+ err = _gcry_random_run_external_test (ctx, buffer, buflen);
597+ }
598+ break;
599+ case 60: /* Deinit external random test. */
600+ {
601+ void *ctx = va_arg (arg_ptr, void *);
602+ _gcry_random_deinit_external_test (ctx);
603+ }
604+ break;
605+ case 61: /* RFU */
606+ break;
607+ case 62: /* RFU */
608+ break;
609+#if _GCRY_GCC_VERSION >= 40600
610+# pragma GCC diagnostic pop
611+#endif
612+
613+ case GCRYCTL_DISABLE_HWF:
614+ {
615+ const char *name = va_arg (arg_ptr, const char *);
616+ int i;
617+
618+ for (i=0; hwflist[i].desc; i++)
619+ if (!strcmp (hwflist[i].desc, name))
620+ {
621+ disabled_hw_features |= hwflist[i].flag;
622+ break;
623+ }
624+ if (!hwflist[i].desc)
625+ err = GPG_ERR_INV_NAME;
626+ }
627+ break;
628+
629+ default:
630+ /* A call to make sure that the dummy code is linked in. */
631+ _gcry_compat_identification ();
632+ err = GPG_ERR_INV_OP;
633+ }
634+
635+ return gcry_error (err);
636+}
637+
638+
639+/* Command dispatcher function, acting as general control
640+ function. */
641+gcry_error_t
642+gcry_control (enum gcry_ctl_cmds cmd, ...)
643+{
644+ gcry_error_t err;
645+ va_list arg_ptr;
646+
647+ va_start (arg_ptr, cmd);
648+ err = _gcry_vcontrol (cmd, arg_ptr);
649+ va_end(arg_ptr);
650+ return err;
651+}
652+
653+
654+
655+/* Return a pointer to a string containing a description of the error
656+ code in the error value ERR. */
657+const char *
658+gcry_strerror (gcry_error_t err)
659+{
660+ return gpg_strerror (err);
661+}
662+
663+/* Return a pointer to a string containing a description of the error
664+ source in the error value ERR. */
665+const char *
666+gcry_strsource (gcry_error_t err)
667+{
668+ return gpg_strsource (err);
669+}
670+
671+/* Retrieve the error code for the system error ERR. This returns
672+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
673+ this). */
674+gcry_err_code_t
675+gcry_err_code_from_errno (int err)
676+{
677+ return gpg_err_code_from_errno (err);
678+}
679+
680+
681+/* Retrieve the system error for the error code CODE. This returns 0
682+ if CODE is not a system error code. */
683+int
684+gcry_err_code_to_errno (gcry_err_code_t code)
685+{
686+ return gpg_err_code_from_errno (code);
687+}
688+
689+
690+/* Return an error value with the error source SOURCE and the system
691+ error ERR. */
692+gcry_error_t
693+gcry_err_make_from_errno (gpg_err_source_t source, int err)
694+{
695+ return gpg_err_make_from_errno (source, err);
696+}
697+
698+
699+/* Return an error value with the system error ERR. */
700+gcry_err_code_t
701+gcry_error_from_errno (int err)
702+{
703+ return gcry_error (gpg_err_code_from_errno (err));
704+}
705+
706+
707+/* Set custom allocation handlers. This is in general not useful
708+ * because the libgcrypt allocation functions are guaranteed to
709+ * provide proper allocation handlers which zeroize memory if needed.
710+ * NOTE: All 5 functions should be set. */
711+void
712+gcry_set_allocation_handler (gcry_handler_alloc_t new_alloc_func,
713+ gcry_handler_alloc_t new_alloc_secure_func,
714+ gcry_handler_secure_check_t new_is_secure_func,
715+ gcry_handler_realloc_t new_realloc_func,
716+ gcry_handler_free_t new_free_func)
717+{
718+ global_init ();
719+
720+ if (fips_mode ())
721+ {
722+ /* We do not want to enforce the fips mode, but merely set a
723+ flag so that the application may check whether it is still in
724+ fips mode. */
725+ _gcry_inactivate_fips_mode ("custom allocation handler");
726+ }
727+
728+ alloc_func = new_alloc_func;
729+ alloc_secure_func = new_alloc_secure_func;
730+ is_secure_func = new_is_secure_func;
731+ realloc_func = new_realloc_func;
732+ free_func = new_free_func;
733+}
734+
735+
736+
737+/****************
738+ * Set an optional handler which is called in case the xmalloc functions
739+ * ran out of memory. This handler may do one of these things:
740+ * o free some memory and return true, so that the xmalloc function
741+ * tries again.
742+ * o Do whatever it like and return false, so that the xmalloc functions
743+ * use the default fatal error handler.
744+ * o Terminate the program and don't return.
745+ *
746+ * The handler function is called with 3 arguments: The opaque value set with
747+ * this function, the requested memory size, and a flag with these bits
748+ * currently defined:
749+ * bit 0 set = secure memory has been requested.
750+ */
751+void
752+gcry_set_outofcore_handler( int (*f)( void*, size_t, unsigned int ),
753+ void *value )
754+{
755+ global_init ();
756+
757+ if (fips_mode () )
758+ {
759+ log_info ("out of core handler ignored in FIPS mode\n");
760+ return;
761+ }
762+
763+ outofcore_handler = f;
764+ outofcore_handler_value = value;
765+}
766+
767+/* Return the no_secure_memory flag. */
768+static int
769+get_no_secure_memory (void)
770+{
771+ if (!no_secure_memory)
772+ return 0;
773+ if (_gcry_enforced_fips_mode ())
774+ {
775+ no_secure_memory = 0;
776+ return 0;
777+ }
778+ return no_secure_memory;
779+}
780+
781+
782+static gcry_err_code_t
783+do_malloc (size_t n, unsigned int flags, void **mem)
784+{
785+ gcry_err_code_t err = 0;
786+ void *m;
787+
788+ if ((flags & GCRY_ALLOC_FLAG_SECURE) && !get_no_secure_memory ())
789+ {
790+ if (alloc_secure_func)
791+ m = (*alloc_secure_func) (n);
792+ else
793+ m = _gcry_private_malloc_secure (n);
794+ }
795+ else
796+ {
797+ if (alloc_func)
798+ m = (*alloc_func) (n);
799+ else
800+ m = _gcry_private_malloc (n);
801+ }
802+
803+ if (!m)
804+ {
805+ /* Make sure that ERRNO has been set in case a user supplied
806+ memory handler didn't it correctly. */
807+ if (!errno)
808+ gpg_err_set_errno (ENOMEM);
809+ err = gpg_err_code_from_errno (errno);
810+ }
811+ else
812+ *mem = m;
813+
814+ return err;
815+}
816+
817+void *
818+gcry_malloc (size_t n)
819+{
820+ void *mem = NULL;
821+
822+ do_malloc (n, 0, &mem);
823+
824+ return mem;
825+}
826+
827+void *
828+gcry_malloc_secure (size_t n)
829+{
830+ void *mem = NULL;
831+
832+ do_malloc (n, GCRY_ALLOC_FLAG_SECURE, &mem);
833+
834+ return mem;
835+}
836+
837+int
838+gcry_is_secure (const void *a)
839+{
840+ if (get_no_secure_memory ())
841+ return 0;
842+ if (is_secure_func)
843+ return is_secure_func (a) ;
844+ return _gcry_private_is_secure (a);
845+}
846+
847+void
848+_gcry_check_heap( const void *a )
849+{
850+ (void)a;
851+
852+ /* FIXME: implement this*/
853+#if 0
854+ if( some_handler )
855+ some_handler(a)
856+ else
857+ _gcry_private_check_heap(a)
858+#endif
859+}
860+
861+void *
862+gcry_realloc (void *a, size_t n)
863+{
864+ void *p;
865+
866+ /* To avoid problems with non-standard realloc implementations and
867+ our own secmem_realloc, we divert to malloc and free here. */
868+ if (!a)
869+ return gcry_malloc (n);
870+ if (!n)
871+ {
872+ gcry_free (a);
873+ return NULL;
874+ }
875+
876+ if (realloc_func)
877+ p = realloc_func (a, n);
878+ else
879+ p = _gcry_private_realloc (a, n);
880+ if (!p && !errno)
881+ gpg_err_set_errno (ENOMEM);
882+ return p;
883+}
884+
885+void
886+gcry_free (void *p)
887+{
888+ int save_errno;
889+
890+ if (!p)
891+ return;
892+
893+ /* In case ERRNO is set we better save it so that the free machinery
894+ may not accidently change ERRNO. We restore it only if it was
895+ already set to comply with the usual C semantic for ERRNO. */
896+ save_errno = errno;
897+ if (free_func)
898+ free_func (p);
899+ else
900+ _gcry_private_free (p);
901+
902+ if (save_errno)
903+ gpg_err_set_errno (save_errno);
904+}
905+
906+void *
907+gcry_calloc (size_t n, size_t m)
908+{
909+ size_t bytes;
910+ void *p;
911+
912+ bytes = n * m; /* size_t is unsigned so the behavior on overflow is
913+ defined. */
914+ if (m && bytes / m != n)
915+ {
916+ gpg_err_set_errno (ENOMEM);
917+ return NULL;
918+ }
919+
920+ p = gcry_malloc (bytes);
921+ if (p)
922+ memset (p, 0, bytes);
923+ return p;
924+}
925+
926+void *
927+gcry_calloc_secure (size_t n, size_t m)
928+{
929+ size_t bytes;
930+ void *p;
931+
932+ bytes = n * m; /* size_t is unsigned so the behavior on overflow is
933+ defined. */
934+ if (m && bytes / m != n)
935+ {
936+ gpg_err_set_errno (ENOMEM);
937+ return NULL;
938+ }
939+
940+ p = gcry_malloc_secure (bytes);
941+ if (p)
942+ memset (p, 0, bytes);
943+ return p;
944+}
945+
946+
947+/* Create and return a copy of the null-terminated string STRING. If
948+ it is contained in secure memory, the copy will be contained in
949+ secure memory as well. In an out-of-memory condition, NULL is
950+ returned. */
951+char *
952+gcry_strdup (const char *string)
953+{
954+ char *string_cp = NULL;
955+ size_t string_n = 0;
956+
957+ string_n = strlen (string);
958+
959+ if (gcry_is_secure (string))
960+ string_cp = gcry_malloc_secure (string_n + 1);
961+ else
962+ string_cp = gcry_malloc (string_n + 1);
963+
964+ if (string_cp)
965+ strcpy (string_cp, string);
966+
967+ return string_cp;
968+}
969+
970+
971+void *
972+gcry_xmalloc( size_t n )
973+{
974+ void *p;
975+
976+ while ( !(p = gcry_malloc( n )) )
977+ {
978+ if ( fips_mode ()
979+ || !outofcore_handler
980+ || !outofcore_handler (outofcore_handler_value, n, 0) )
981+ {
982+ _gcry_fatal_error (gpg_err_code_from_errno (errno), NULL);
983+ }
984+ }
985+ return p;
986+}
987+
988+void *
989+gcry_xrealloc( void *a, size_t n )
990+{
991+ void *p;
992+
993+ while ( !(p = gcry_realloc( a, n )) )
994+ {
995+ if ( fips_mode ()
996+ || !outofcore_handler
997+ || !outofcore_handler (outofcore_handler_value, n,
998+ gcry_is_secure(a)? 3:2 ) )
999+ {
1000+ _gcry_fatal_error (gpg_err_code_from_errno (errno), NULL );
1001+ }
1002+ }
1003+ return p;
1004+}
1005+
1006+void *
1007+gcry_xmalloc_secure( size_t n )
1008+{
1009+ void *p;
1010+
1011+ while ( !(p = gcry_malloc_secure( n )) )
1012+ {
1013+ if ( fips_mode ()
1014+ || !outofcore_handler
1015+ || !outofcore_handler (outofcore_handler_value, n, 1) )
1016+ {
1017+ _gcry_fatal_error (gpg_err_code_from_errno (errno),
1018+ _("out of core in secure memory"));
1019+ }
1020+ }
1021+ return p;
1022+}
1023+
1024+
1025+void *
1026+gcry_xcalloc( size_t n, size_t m )
1027+{
1028+ size_t nbytes;
1029+ void *p;
1030+
1031+ nbytes = n * m;
1032+ if (m && nbytes / m != n)
1033+ {
1034+ gpg_err_set_errno (ENOMEM);
1035+ _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL );
1036+ }
1037+
1038+ p = gcry_xmalloc ( nbytes );
1039+ memset ( p, 0, nbytes );
1040+ return p;
1041+}
1042+
1043+void *
1044+gcry_xcalloc_secure( size_t n, size_t m )
1045+{
1046+ size_t nbytes;
1047+ void *p;
1048+
1049+ nbytes = n * m;
1050+ if (m && nbytes / m != n)
1051+ {
1052+ gpg_err_set_errno (ENOMEM);
1053+ _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL );
1054+ }
1055+
1056+ p = gcry_xmalloc_secure ( nbytes );
1057+ memset ( p, 0, nbytes );
1058+ return p;
1059+}
1060+
1061+char *
1062+gcry_xstrdup (const char *string)
1063+{
1064+ char *p;
1065+
1066+ while ( !(p = gcry_strdup (string)) )
1067+ {
1068+ size_t n = strlen (string);
1069+ int is_sec = !!gcry_is_secure (string);
1070+
1071+ if (fips_mode ()
1072+ || !outofcore_handler
1073+ || !outofcore_handler (outofcore_handler_value, n, is_sec) )
1074+ {
1075+ _gcry_fatal_error (gpg_err_code_from_errno (errno),
1076+ is_sec? _("out of core in secure memory"):NULL);
1077+ }
1078+ }
1079+
1080+ return p;
1081+}
1082+
1083+
1084+int
1085+_gcry_get_debug_flag (unsigned int mask)
1086+{
1087+ if ( fips_mode () )
1088+ return 0;
1089+ return (debug_flags & mask);
1090+}
1091+
1092+
1093+
1094
1095+/* It is often useful to get some feedback of long running operations.
1096+ This function may be used to register a handler for this.
1097+ The callback function CB is used as:
1098+
1099+ void cb (void *opaque, const char *what, int printchar,
1100+ int current, int total);
1101+
1102+ Where WHAT is a string identifying the the type of the progress
1103+ output, PRINTCHAR the character usually printed, CURRENT the amount
1104+ of progress currently done and TOTAL the expected amount of
1105+ progress. A value of 0 for TOTAL indicates that there is no
1106+ estimation available.
1107+
1108+ Defined values for WHAT:
1109+
1110+ "need_entropy" X 0 number-of-bytes-required
1111+ When running low on entropy
1112+ "primegen" '\n' 0 0
1113+ Prime generated
1114+ '!'
1115+ Need to refresh the prime pool
1116+ '<','>'
1117+ Number of bits adjusted
1118+ '^'
1119+ Looking for a generator
1120+ '.'
1121+ Fermat tests on 10 candidates failed
1122+ ':'
1123+ Restart with a new random value
1124+ '+'
1125+ Rabin Miller test passed
1126+ "pk_elg" '+','-','.','\n' 0 0
1127+ Only used in debugging mode.
1128+ "pk_dsa"
1129+ Only used in debugging mode.
1130+*/
1131+void
1132+gcry_set_progress_handler (void (*cb)(void *,const char*,int, int, int),
1133+ void *cb_data)
1134+{
1135+#if USE_DSA
1136+ _gcry_register_pk_dsa_progress (cb, cb_data);
1137+#endif
1138+#if USE_ELGAMAL
1139+ _gcry_register_pk_elg_progress (cb, cb_data);
1140+#endif
1141+ _gcry_register_primegen_progress (cb, cb_data);
1142+ _gcry_register_random_progress (cb, cb_data);
1143+}
1144
1145=== modified file 'debian/changelog'
1146--- debian/changelog 2011-09-01 18:53:49 +0000
1147+++ debian/changelog 2012-05-15 18:22:18 +0000
1148@@ -1,3 +1,9 @@
1149+libgcrypt11 (1.5.0-3ubuntu1) quantal; urgency=low
1150+
1151+ * Do not call global_init when setting thread callbacks (LP: #423252)
1152+
1153+ -- Adam Stokes <adam.stokes@canonical.com> Tue, 15 May 2012 13:56:17 -0400
1154+
1155 libgcrypt11 (1.5.0-3) unstable; urgency=low
1156
1157 * Upload to unstable.
1158
1159=== added file 'debian/patches/no-global-init-thread-callbacks.diff'
1160--- debian/patches/no-global-init-thread-callbacks.diff 1970-01-01 00:00:00 +0000
1161+++ debian/patches/no-global-init-thread-callbacks.diff 2012-05-15 18:22:18 +0000
1162@@ -0,0 +1,11 @@
1163+--- a/src/global.c
1164++++ b/src/global.c
1165+@@ -445,8 +445,6 @@
1166+
1167+ case GCRYCTL_SET_THREAD_CBS:
1168+ err = ath_install (va_arg (arg_ptr, void *), any_init_done);
1169+- if (! err)
1170+- global_init ();
1171+ break;
1172+
1173+ case GCRYCTL_FAST_POLL:
1174
1175=== modified file 'debian/patches/series'
1176--- debian/patches/series 2011-09-01 18:53:49 +0000
1177+++ debian/patches/series 2012-05-15 18:22:18 +0000
1178@@ -1,1 +1,2 @@
1179 12_lessdeps_libgcrypt-config.diff
1180+no-global-init-thread-callbacks.diff
1181
1182=== modified file 'src/global.c'
1183--- src/global.c 2011-07-02 12:09:09 +0000
1184+++ src/global.c 2012-05-15 18:22:18 +0000
1185@@ -445,8 +445,6 @@
1186
1187 case GCRYCTL_SET_THREAD_CBS:
1188 err = ath_install (va_arg (arg_ptr, void *), any_init_done);
1189- if (! err)
1190- global_init ();
1191 break;
1192
1193 case GCRYCTL_FAST_POLL:

Subscribers

People subscribed via source and target branches

to all changes: