Ken Raeburn [Thu, 18 Jun 2009 23:25:25 +0000 (23:25 +0000)]
reduce some mutex performance problems in profile library
In profile_node_iterator we unlock a mutex in order to call
profile_update_file_data, which wants to lock that mutex itself, and
then when it returns we re-lock the mutex. (We don't use recursive
mutexes, and I would continue to argue that we shouldn't.) On the
Mac, when running multiple threads, it appears that this results in
very poor peformance, and much system and user CPU time is spent
working with the locks. (Linux doesn't seem to suffer as much.)
So: Split profile_update_file_data into a locking wrapper, and an
inner routine that does the real work but requires that the lock be
held on entry. Call the latter from profile_node_iterator *without*
unlocking first, and only unlock if there's an error. This doesn't
move any significant amount of work into the locking region; it pretty
much just joins locking regions that were disjoint for no good reason.
On my tests on an 8-core Mac, in a test program running
gss_init_sec_context in a loop in 6 threads, this brought CPU usage
per call down by 40%, and improved wall-clock time even more.
Single-threaded performance improved very slightly, probably in the
noise.
Linux showed modest improvement (5% or less) in CPU usage in a
3-thread test on a 4-core system.
Similar tests with gss_accept_sec_context showed similar contention
around the profile-library mutexes, but I haven't analyzed the
performance changes there from this patch.
Ken Raeburn [Thu, 18 Jun 2009 21:56:48 +0000 (21:56 +0000)]
minor memory leak in 'none' replay cache type
The replay cache type implementations are responsible for freeing the
main rcache structure when the cache handle is closed. The 'none'
rcache type wasn't doing this, resulting in a small memory leak each
time such a cache was opened and closed. Not a big deal for a server
process servicing a single client, but it could accumulate (very very
slowly) for a long-running server.
Greg Hudson [Thu, 18 Jun 2009 17:34:17 +0000 (17:34 +0000)]
Remove the new configure option --enable-static-only, and instead
require --enable-static --disable-shared for the same effect. Error
out if only one of those two is specified.
While here, remove an unnecessary clause in the --disable-rpath block,
and make the notices consistent when using shared and static
libraries.
Ezra Peisach [Thu, 11 Jun 2009 17:01:13 +0000 (17:01 +0000)]
krb5int_yarrow_final could deref NULL if out of memory
krb5int_yarrow_final tests if the Yarrow_CTX* is valid (not NULL) -
and if not - signals and error for return - but still invokes
mem_zero (memset) with it as an argument. This will only happen in
an out-of-memory situation.
Ezra Peisach [Wed, 10 Jun 2009 02:55:22 +0000 (02:55 +0000)]
krb5int_rd_chpw_rep could call krb5_free_error with random value
clang picked up on a path in which krberror is not set and passed as
an argument to krb5_free_error(). Essentially if the clearresult
length < 2 but everything decodes - you can hit this path...
Greg Hudson [Mon, 8 Jun 2009 10:01:57 +0000 (10:01 +0000)]
Restore limited support for static linking
Add enough static linking support to run the test suite without shared
libraries, to facilitate gcov and other kinds of instrumentation. The
necessary changes include:
* Undo some of the changes which removed static linking support,
and cannibalize the defunct krb5_force_static conditional block
in aclocal.m4.
* Add --enable-static-only configure option.
* For plugins, use a different symbol name for static and dynamic
builds, via a macro in k5plugin.h.
* Add build machinery for building static libraries for plugins
(somewhat grotty due to the difference in names).
* Move plugin subdirs earlier in SUBDIRS in src/Makefile.in.
* Make the in-tree KDB5 plugins dependencies of libkdb5 in a static
build (aclocal.m4 has to know what they are).
* In kdb5.c, cannibalize the broken _KDB5_STATIC_LINK support to
allow "loading" of statically linked plugin libraries.
Preauth, authdata, locate, and GSSAPI plugins are not handled by this
change, as they are not currently necessary to the test suite.
Supporting GSSAPI plugins may be a bit tricky but the others should be
straightforward if they become needed.
$(STLIBEXT) changes from .a-nobuild to .a in a normal shared build as
a result of these changes (except on AIX where aclocal.m4 changes it).
This does not seem to be important as we avoid selecting the static
library for building via other means.
Greg Hudson [Mon, 8 Jun 2009 09:43:45 +0000 (09:43 +0000)]
libkdb5 now depends on libgssrpc. So when linking kpropd, specify
$(KDB5_LIB) before $(KADMCLNT_LIBS) to get the link order right.
Unimportant for dynamic linking in most environments, but relevant for
static linking.
Greg Hudson [Mon, 8 Jun 2009 09:41:55 +0000 (09:41 +0000)]
Don't build the kadm5/unit-test test programs during "make all"; build
them during "make check" via test dependencies for consistency with
the way we handle other test programs. (Also means we don't need
libraries to be linkable until later in the build process.)
Ezra Peisach [Sat, 6 Jun 2009 13:46:06 +0000 (13:46 +0000)]
kadmind is parsing acls good deref NULL pointer on error
In kadm5int_acl_parse_line, if you setup an acl w/ restrictions
(i.e. the four argument acl format) - but have an error parsing the
first few fields, acle is NULLed out, and is then derefed.
This adds a conditional and indents according to the krb5 c-style...
Ezra Peisach [Sat, 6 Jun 2009 03:55:44 +0000 (03:55 +0000)]
kadm5int_acl_parse_restrictions could ref uninitialized variable
The variable sp is never initialized. If the first argument to the
function is null, the code falls through to freeing sp if valid.
However, sp is never set.
Greg Hudson [Mon, 1 Jun 2009 22:39:31 +0000 (22:39 +0000)]
Make results of krb5_db_def_fetch_mkey more predictable
krb5_db_def_fetch_mkey tries the stash file as a keytab, then falls
back to the old stash file format. If the stash file was in keytab
format, but didn't contain the desired master key, we would try to
read a keytab file as a stash file. This could succeed or fail
depending on byte order and other unpredictable factors. The upshot
was that one of the libkadm5 unit tests (init 108) was getting a
different error code on different platforms.
To fix this, only try the stash file format if we get
KRB5_KEYTAB_BADVNO trying the keytab format. This requires reworking
the error handling logic.
Ken Raeburn [Wed, 27 May 2009 20:03:46 +0000 (20:03 +0000)]
fix t_prf test code properly
Correction to patch in r22364: "i" was used in two places, one of
which required an int-sized value and the other of which required a
size_t. Instead of changing the type, split the two uses into
separate variables.
Greg Hudson [Mon, 25 May 2009 16:40:00 +0000 (16:40 +0000)]
Temporarily disable FAST PKINIT for 1.7 release
There are protocol issues and implementation defects surrounding the
combination of FAST an PKINIT currently. To avoid impacting the 1.7
scheduled and to avoid creating interoperability problems later,
disable the combination until the problems are resolved.
Greg Hudson [Sun, 24 May 2009 15:53:51 +0000 (15:53 +0000)]
Fix vector initialization error in KDC preauth code
In the KDC, get_preauth_hint_list had two bugs initializing the
preauth array. It was allocating 21 extra entries instead of two due
to a typo (harmless), and it was only zeroing up through one extra
entry (harmful). Adjust the code to use calloc to avoid further
disagreements of this nature.
Greg Hudson [Sun, 24 May 2009 00:48:31 +0000 (00:48 +0000)]
Fix test rules for non-gmake make versions
The build rules for the new t_ad_fx_armor and t_authdata test programs
used $<, which is only portable for implicit rules (but is valid in
gmake for all rules). Stop using $< in those rules so that "make
check" works with System V make.
Greg Hudson [Sat, 23 May 2009 00:09:58 +0000 (00:09 +0000)]
In krb5_ktfileint_write_entry, add a no-op fseek in between reading
EOF and writing the placeholder length field. Otherwise we can run
into an apparent bug in the Solaris 10 stdio library which causes the
next no-op fseek after the fwrite to fail with EINVAL.
Greg Hudson [Fri, 22 May 2009 14:08:25 +0000 (14:08 +0000)]
Remove spurious assertion in handle_authdata
In handle_authdata in the KDC, remove a spurious assertion (added in
r21566 on the mskrb-integ branch) that authdata starts out empty.
authdata can be legitimately added by check_padata, which precedes
handle_authdata, and this happens with pkinit.
Greg Hudson [Tue, 19 May 2009 23:17:49 +0000 (23:17 +0000)]
When using keyed checksum types with TGS subkeys, Microsoft AD 2003
verifies the checksum using the subkey, whereas MIT and Heimdal verify
it using the TGS session key. (RFC 4120 is actually silent on which
is correct; RFC 4757 specifies the TGS session key.) To sidestep this
interop issue, don't use keyed checksum types with RC4 keys without
explicit configuration in krb5.conf. Using keyed checksum types with
AES is fine since, experimentally, AD 2008 accepts checksums keyed
with the TGS session key.
Sam Hartman [Mon, 18 May 2009 19:08:29 +0000 (19:08 +0000)]
Document use of key fields in GSS context
The addition of etype negotiation has made the meanings of the various
keys in the GSS-API context structure more complicated. Document them
to aid in code understanding.
Greg Hudson [Thu, 14 May 2009 16:50:52 +0000 (16:50 +0000)]
gss_krb5int_export_lucid_sec_context was erroneously copying the first
sizeof(void *) bytes of the context into data_set, instead of the
pointer to the context.
ticket: 6488
status: open
tags: pullup
target_version: 1.7
Greg Hudson [Thu, 14 May 2009 16:16:32 +0000 (16:16 +0000)]
UCS2 support doesn't handle upper half of BMP
Make krb5_ucs2 an unsigned type. Eliminate the need for distinguished
values for ucs2 and ucs4 characters by changing the API of the single-
character conversion routines.
Tom Yu [Wed, 13 May 2009 20:41:37 +0000 (20:41 +0000)]
In util/support/utf8_conv.c, the SWAP16 macro is invoked with an
argument that has side effects. On platforms where SWAP16 can
evaluate its argument twice (including platforms where utf8_conv.c
creates a fallback definition for the SWAP16 macro), this can cause a
read overrun by a factor of two.
Rearrange the data flow to avoid calling SWAP16 with an argument that
has side effects.
Greg Hudson [Mon, 11 May 2009 16:57:45 +0000 (16:57 +0000)]
Refactor rule_an_to_ln, creating a new helper function to handle the
selection string specifier. Eliminate two (safe) uses of sscanf in
the process. Add a test case including literal text in the selection
string specifier.
Sam Hartman [Thu, 7 May 2009 20:35:28 +0000 (20:35 +0000)]
Try decrypting using session key if subkey fails in tgs rep handling
Heimdal at least up through 1.2 incorrectly encrypts the TGS response
in the session key not the subkey when a subkey is supplied. See RFC
4120 page 35. Work around this by trying decryption using the session
key after the subkey fails.
* decode_kdc_rep.c: rename to krb5int_decode_tgs_rep; only used for
TGS and now needs to take keyusage
* gc_via_tkt: pass in session key and appropriate usage if subkey
fails.
Note that the dead code to process AS responses in decode_kdc_rep is
not removed by this commit. That will be removed as FAST TGS client
support is integrated post 1.7.
Greg Hudson [Tue, 5 May 2009 16:55:58 +0000 (16:55 +0000)]
In pa_sam_2, free scratch in a couple of error-handling blocks where
it was live and not freed. The function should be reorganized to use
a cleanup handler, but (I believe) is not covered by the test suite
and should not undergo such major surgery until it is.
Greg Hudson [Tue, 5 May 2009 16:00:40 +0000 (16:00 +0000)]
Fix a case in the krb5_rd_rep error handler (introduced in the last
commit) where scratch.data could be indirected through even if it
wasn't allocated successfully.
Greg Hudson [Mon, 4 May 2009 16:08:03 +0000 (16:08 +0000)]
krb5_rd_rep could leak memory through its output parameter on error.
Adjust the flow control so that *repl is NULL on error and the memory
allocated by decode_krb5_ap_rep_enc_part is freed.
Greg Hudson [Sat, 2 May 2009 04:58:19 +0000 (04:58 +0000)]
Fix a memory leak in krb5int_rd_chpw_rep in a block of code handling
buggy MS KDC behavior. It's not entirely clear what should happen in
the case where memory was leaked (error packet received containing
e_data) so pick a conservative option.
Greg Hudson [Fri, 1 May 2009 20:19:43 +0000 (20:19 +0000)]
Fix a memory leak by reorganizing krb5_principal_internalize to use
the recommended flow control for error handling. Also initialize the
output parameter so that it is set in case of error.
Sam Hartman [Thu, 30 Apr 2009 20:17:42 +0000 (20:17 +0000)]
Implement DES and 3DES PRF. Patch fromKAMADA Ken'ichi
Currently the DES and 3DES PRF output 16-byte results. This is
consistent with RFC 3961, but we need to confirm it is consistent with
Heimdal and WG decisions. See IETF 74 minutes for some discussion of
the concern as it applies to AES and thus possibly all simplified
profile enctypes.
In ktfile_common_resolve, set the output pointer to NULL on error, and
use a cleanup label instead of freeing the same resources in multiple
error handling blocks.
Fix a memory leak by reorganizing krb5_ktf_keytab_internalize to use
the recommended exception-handling flow control. Eliminate the check
for ktdata being null after resolution because that's not possible.
Add a check for the resolved keytab being of a different type, since
that would result in data structure corruption.
Sam Hartman [Thu, 30 Apr 2009 00:38:48 +0000 (00:38 +0000)]
Do not return PREAUTH_FAILED on unknown preauth
If the KDC receives unknown pre-authentication data then ignore it.
Do not get into a case where PREAUTH_FAILED is returned because of
unknown pre-authentication. The main AS loop will cause
PREAUTH_REQUIRED to be returned if the preauth_required flag is set
and no valid preauth is found.
If DEBUG_ERROR_LOCATIONS is defined, replace uses of
krb5_set_error_message and krb5int_set_error with calls to the new
_fl variants of those functions, and include filename and line number
information in the calls. Requires C99-style variadic macros if
defined.
Fix handling of RET_SEQUENCE flag in mk_priv/mk_ncred
Regularize the handling of KRB5_AUTH_CONTEXT_RET_SEQUENCE in
krb5_mk_safe, krb5_mk_priv, and krb5_mk_ncred, using krb5_mk_safe as
a baseline. RET_SEQUENCE now implies DO_SEQUENCE for all three
functions, the sequence number is always incremented if it is used,
and outdata->seq is always set if RET_SEQUENCE is passed.
Note that in the corresponding rd_ functions, RET_SEQUENCE and
DO_SEQUENCE are independent flags, which is not consistent with the
above. This compromise is intended to preserve compatibility with
any working code which might exist using the RET_SEQUENCE flag.
Fix a few memory leaks in krb5_mk_ncred. Also tighten up the error
handling of the sequence number, only decreasing it if it was
increased. The handling of DO_SEQUENCE and RET_SEQUENCE may still be
flawed in some cases.
Move KRB5_KDB_OK_AS_DELEGATE from kdb_ext.h to kdb.h. Add kadmin
support for the flag. In the KDC, remove the restriction on returning
the flag on cross-realm TGTs since there is now a defined meaning for
that (it allows ok-as-delegate to be honored on the foreign realm's
service tickets).
Ken Raeburn [Sat, 25 Apr 2009 09:36:11 +0000 (09:36 +0000)]
make installed headers C++-safe
Now that we're installing the kadm5 headers, they should be C++-safe
like the others. Wrap the content in 'extern "C"' if compiling as
C++. New test program to verify.