]> granicus.if.org Git - p11-kit/commitdiff
modules: Reset the init count on fork()
authorDaiki Ueno <dueno@redhat.com>
Thu, 22 Sep 2016 07:16:48 +0000 (09:16 +0200)
committerDaiki Ueno <ueno@gnu.org>
Mon, 31 Oct 2016 11:59:17 +0000 (12:59 +0100)
Reset mod->init_count when forkid has changed.  Otherwise C_Finalize
does not get called.

GCC's asan spotted this:
  Direct leak of 48 byte(s) in 1 object(s) allocated from:
      #0 0x7f89bc7bfe20 in malloc (/lib64/libasan.so.3+0xc6e20)
      #1 0x7f89bc47a1f1 in p11_dict_new ../common/dict.c:278
      #2 0x7f89bc42143d in managed_C_Initialize ../p11-kit/modules.c:1477
      #3 0x7f89bc464c72 in binding_C_Initialize ../p11-kit/virtual.c:121
      #4 0x7f89bc1b0a51 in ffi_closure_unix64_inner (/lib64/libffi.so.6+0x5a51)
      #5 0x7f89bc1b0dbf in ffi_closure_unix64 (/lib64/libffi.so.6+0x5dbf)
      #6 0x7f89bc44f9e8 in rpc_C_Initialize ../p11-kit/rpc-server.c:691

p11-kit/modules.c

index 4af2a83d61444bb3f884228312d0235df32ef15b..fc456ce7b7fb9be79ea0729b58f737ab42b926be 100644 (file)
@@ -658,6 +658,10 @@ initialize_module_inlock_reentrant (Module *mod, CK_C_INITIALIZE_ARGS *init_args
                /* Module was already initialized, we don't call C_Finalize */
                if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED)
                        rv = CKR_OK;
+
+               /* Matches the init count in finalize_module_inlock_reentrant() */
+               if (rv == CKR_OK)
+                       mod->init_count = 0;
        }
 
        p11_mutex_unlock (&mod->initialize_mutex);