Greg Hudson [Tue, 28 Jun 2016 16:28:11 +0000 (12:28 -0400)]
Fix leak in gss_display_name() for non-MN names
RFC 2744 states that the gss_display_name() output_name_type result is
"a pointer into static storage, and should be treated as read-only by
the caller (in particular, the application should not attempt to free
it)". For non-mechanism names, we were making a copy of the name type
from the union name structure, causing a memory leak; stop doing that.
Greg Hudson [Mon, 27 Jun 2016 23:38:36 +0000 (19:38 -0400)]
Fix leak in k5_free_cammac()
free_vmac(), a helper function used by k5_free_cammac(), must free its
val pointer as well as the contents; otherwise the krb5_verifier_mac
container is leaked.
Greg Hudson [Mon, 27 Jun 2016 21:49:57 +0000 (17:49 -0400)]
Fix leaks on error in krb5 gss_acquire_cred()
In acquire_cred_context(), when releasing the partially constructed
cred on error, make sure to free the password and impersonator fields,
and to destroy the ccache if we created it.
Greg Hudson [Mon, 27 Jun 2016 04:21:30 +0000 (00:21 -0400)]
Fix memory leak in old gssrpc authentication
auth_gssapi_create(), which is now only used to connect to ancient
servers, can leak memory on error or when multiple GSSAPI_INIT calls
are required. Ensure that call_res is freed along all exit paths and
before each repeat clnt_call() invocation.
Greg Hudson [Fri, 24 Jun 2016 16:33:05 +0000 (12:33 -0400)]
Fix memory leak in db2 policy DB initialization
osa_adb_init_db() maintains a static linked list mapping filenames to
lock structures. Entries are never removed from the list; when their
reference counts hit 0, the lockfile is closed but the filename
remains allocated. However, the filename is allocated each time the
lockfile is re-opened, leaking the old value. Fix this leak by moving
filename initialization to entry creation.
Greg Hudson [Mon, 27 Jun 2016 17:13:47 +0000 (13:13 -0400)]
Update libev sources to 4.22
This update fixes a memory leak when freeing null pointers using
ev_realloc_emul(). In 4.04, that function assumed that realloc(x, 0)
is equivalent to free(x) under glibc, but in at least some versions of
glibc, realloc(NULL, 0) behaves like malloc(0) rather than free(NULL)
and allocates memory.
Sarah Day [Tue, 19 Jan 2016 14:50:33 +0000 (09:50 -0500)]
Add unit tests for k5_parse_host_string
Make is_string_numeric() visible outside of parse_host_string.c as
k5_is_string_numeric() so it can be tested. Make
k5_parse_host_string() return an error when address begins with ':',
for consistency with APR's apr_parse_addr_port().
[ghudson@mit.edu: squashed three commits; added t_parse_host_string to
.gitignore and clean rule; clarified commit message]
When encrypted timestamp pre-authentication fails, respond with error
code KDC_ERR_PREAUTH_FAILED, rather than KRB_AP_ERR_BAD_INTEGRITY, for
consistency with other Kerberos implementations.
[ghudson@mit.edu: clarified commit message and comment]
Greg Hudson [Sun, 7 Aug 2016 04:02:00 +0000 (00:02 -0400)]
Fix and simplify locate_kdc.c port byte order
Commit c89587b4476139f05f34aa2323bd7c7db348c44c introduced a bug in
the handling of KDC specifications using the default port, by passing
it to k5_parse_host_string() in network byte order. Fix this by
removing all of the port byte order transformations in locate_kdc.c,
and storing the struct serverlist port field in host byte order.
Adjust other consumers of struct serverlist to expect the port to be
in host field to be in host byte order.
Tom Yu [Wed, 3 Aug 2016 21:00:05 +0000 (17:00 -0400)]
Warn about dump -recurse nonfunctionality
kdb5_util dump -recurse hasn't behaved as documented since krb5-1.5,
when the DAL was integrated. Restoring it is a nontrivial amount of
work, so just document it for now.
Change the build system to descend into every directory where we
create a Makefile, but not to build or run anything during "make all"
and "make check" in directories we previously didn't visit. Document
specific build targets that can be used in those directories.
Do not generate a Makefile for the securid_sam2 module unless we are
building it, for consistency with other conditionally built
directories.
Double-colon rules allow the flexibility to specify commands in
multiple places, but they also make the order of commands and
dependencies dependent on the order of declarations in the Makefile.
Convert all of our double-colon rules to single-colon rules, with the
exception of "clean-unix" and "clean-windows" which have commands
defined in both post.in and in numerous Makefile.in files.
Sarah Day [Wed, 27 Jul 2016 16:44:49 +0000 (12:44 -0400)]
Move CFLAGS and CPPFLAGS after local includes
The gss-kernel-lib Makefile overrides ALL_CFLAGS. It was setting
the CFLAGS and CPPFLAGS to occur before local includes, which
causes some compilers to include system header files before the
local header files. Moving the CPPFLAGS and CFLAGS to the end of
ALL_CFLAGS corrects this behavior.
Tom Yu [Wed, 27 Jul 2016 17:19:51 +0000 (13:19 -0400)]
Rename k5-queue.h macros
Some BSD-derived systems (e.g., FreeBSD and Mac OS X) inappropriately
include sys/queue.h from some non-kernel network-related headers that
we include (net/if.h is one example). Because our k5-queue.h is a
copy from a BSD sys/queue.h, many compilers will warn about macro
redefinitions on those systems. Rename the queue macros to have a K5_
prefix.
Also delete the QUEUEDEBUG macros because they are only useful for
kernel use on the BSD systems where this header originated.
kinit currently outputs "Password incorrect" if it sees a
bad-integrity error code, which results if the KDC reply couldn't be
decrypted, or when encrypted timestamp preauth fails against an MIT
krb5 1.14 or earlier KDC. Expand this check to include general
preauth failures reported by the KDC, but only if a password was
prompted for.
Will Fiveash [Wed, 20 Jul 2016 00:20:51 +0000 (19:20 -0500)]
Better handle failures to resolve client keytab
In krb5_gss_acquire_cred(), treat failure to resolve the client keytab
similarly to a client keytab which resolves but does not exist or has
no entries. The client keytab could fail to resolve if its name
contains %{username} and the current process is acting on behalf of
the NSS system.
[ghudson@mit.edu: rewrote commit message; changed tracing call to use
a macro; cleared error message when ignoring krb5_kt_client_default()
error; added test case]
Greg Hudson [Thu, 16 Jun 2016 20:38:07 +0000 (16:38 -0400)]
Minimize timing leaks in PKINIT decryption
pkcs7_dataDecode() is derived from OpenSSL's PKCS7_datadecode() and is
used by PKINIT clients to decrypt ReplyKeyPack values in RSA mode.
The upstream function was changed for CVE-2012-0884 to minimize the
timing difference when RSA decryption results in the wrong padding.
Although the impact on Kerberos is negligible (because clients do not
ordinarily choose to use RSA mode, and cannot easily be induced to
make many thousands of requests with the same key), change
pkcs7_dataDecode() to match the upstream change, generating a random
symmetric key and using it when RSA decryption fails. Also rename
"tmp" and "tmp_len" to "ek" and "eklen" to match the more descriptive
upstream variable names.
Greg Hudson [Thu, 16 Jun 2016 17:54:01 +0000 (13:54 -0400)]
Simplify pkcs7_dataDecode() in PKINIT
RFC 4556 requires that the EnvelopedData in the encKeyPack contain
only one RecipientInfo. Take advantage of this constraint to simplify
pkcs7_dataDecode().
In validate_as_request(), when enforcing restrict_anonymous_to_tgt,
use client.princ instead of request->client; the latter is NULL when
validating S4U2Self requests.
CVE-2016-3120:
In MIT krb5 1.9 and later, an authenticated attacker can cause krb5kdc
to dereference a null pointer if the restrict_anonymous_to_tgt option
is set to true, by making an S4U2Self request.
Commit 632260bd1fccfb420f0827b59c85c329203eafc9 (ticket #7517) allows
better error reporting for some client pre-authentication failures.
However, it breaks an assumption in the S4U2Self code that such errors
can be recognized by the KRB5_PREAUTH_FAILED error code. Instead of
passing through the error code reported by the first real preauth
module, wrap that error and return KRB5_PREAUTH_FAILED.
Matt Rogers [Fri, 15 Jul 2016 14:17:45 +0000 (10:17 -0400)]
Add the kprop-port option to kadmind
The -k option for kadmind sets the port number that kprop is spawned
with during an iprop full resync. Fall back to checking the
KPROP_PORT environment variable if the option is not set.
Sarah Day [Wed, 23 Dec 2015 20:01:44 +0000 (15:01 -0500)]
Allow user to restrict KDC to specific addresses
krb5kdc has always only supported binding to the wildcard addresses.
Add two configuration options to allow specifying the address/port
that krb5kdc listens on for UDP and TCP connections.
[ghudson@mit.edu: edited documentation; preserved kdc_ports = ""
behavior; made kdc_ports and kdc_tcp_ports continue to work in
kdcdefaults section]
Sarah Day [Wed, 23 Dec 2015 17:11:34 +0000 (12:11 -0500)]
Allow user to restrict kadmind bind addresses
kadmind has always only supported binding to the wildcard addresses.
Add three configuration options to allow specifying the address/port
that kadmind listens on for kpasswd, kadmin, and iprop connections.
[ghudson@mit.edu: edited documentation; minimized changes to
setup_loop(); added iprop_listen]
Sarah Day [Mon, 21 Dec 2015 19:07:49 +0000 (14:07 -0500)]
Add ability to bind addresses to the net-server
The net-server.c logic can accept individual addresses to bind to
using the standard host:port string format, in a list with a comma
delimiter.
Since pktinfo support was removed, users with systems lacking
pktinfo that have multiple NICs may specify each of the local
addresses directly that kadmind or krb5kdc should listen on in
kdc.conf.
[ghudson@mit.edu: edited comments and variable names; simplified
setup_socket()]
Sarah Day [Mon, 21 Mar 2016 20:35:15 +0000 (16:35 -0400)]
Remove workaround when pktinfo is unsupported
Currently if the system doesn't support pktinfo and kadmind or
krb5kdc are binding to a UDP address, then the net server binds to
all the local addresses. Currently most systems support pktinfo,
so the workaround isn't really required anymore. Removing the
workaround will only affect systems that don't have pktinfo
support, have multiple NICs, and are listening on a wildcard
address.
The KDC now needs write access to the LDAP KDB, unless password
lockout and tracking of the last successful authentication time are
disabled. Update the example LDAP access control configuration in
conf_ldap.rst to reflect this, add a note that only read access is
required if lockout is disabled, and add a section to lockout.rst
calling out the need for write access. Reported by Will Fiveash.
Matt Rogers [Tue, 26 Jan 2016 19:59:43 +0000 (14:59 -0500)]
Add hints for -A flag to kdestroy
When using a collection ccache, a user accustomed to the FILE ccache
behavior may not be aware of all active caches, and the default
kdestroy command could make it seem like there is no active cache
left. Print a warning to use -A after kdestroy if there are other
caches.
Greg Hudson [Thu, 23 Jun 2016 16:01:56 +0000 (12:01 -0400)]
Fix profile_flush_to_file() state corruption
In write_data_to_file(), do not clear the profile data object's flags.
If the call to this function resulted from profile_flush_to_file(), we
do not want to clear the DIRTY flag, and we especially do not want to
clear the SHARED flag for a data object which is part of
g_shared_trees. Instead, clear the DIRTY flag in
profile_flush_file_data().
Add a test case to prof_test1 to exercise the bug in unfixed code.
Also modify test1 to abandon the altered profile after flushing it to
a file, to preserve the external behavior of the script before this
fix.
When the default realm name is unspecified, and none was set in the
krb5_context object, return KRB5_CONFIG_NODEFREALM from libkdb5
instead of the confusing KRB5_KDB_DBTYPE_NOTFOUND. To accomplish
this, make kdb_get_library_name() return a krb5_error_code.
Greg Hudson [Tue, 21 Jun 2016 22:46:28 +0000 (18:46 -0400)]
Fix recent memory leak in locate_kdc.c
Commit ce112dec844e4650b5ad174bd40f21c32aebe1d1 introduced a memory
leak in locate_srv_conf_1() by moving the free(realmstr) call to the
cleanup handler, because there was an early return after realmstr is
allocated. Convert that early return to a goto.
Before this patch libkrad would always subtract the existing buffer
length from pktlen before passing it to recv(). In the case of stream
sockets, this is incorrect since krad_packet_bytes_needed() already
performs this calculation. Subtracting the buffer length twice could
cause integer underflow on the len parameter to recv().
Greg Hudson [Tue, 21 Jun 2016 22:29:00 +0000 (18:29 -0400)]
Fix and simplify auth-indicator authdata module
Remove the authind_context count field. The indicators list must be
null-terminated because it is freed with k5_free_data_ptr_list().
authind_internalize() didn't null-terminate the list, and the presence
of the count field made it appear that this wasn't a bug. Use a
different scheme for setting *more in authind_get_attribute() to avoid
requiring an element count.
Also check more thoroughly for errors in authind_externalize() and
authind_internalize(), and remove some unnecessary pointer casts.
Dmitry Kalinkin [Fri, 17 Jun 2016 17:52:23 +0000 (13:52 -0400)]
Fix Makefile for paths containing '+' character
include/Makefile uses a regex to perform variable substitution with '+'
as the sed delimiter. Paths containing " are already invalid in this
approach, so it is better to use " as the delimiter instead of any
other rare symbol.
Matt Rogers [Fri, 13 May 2016 00:36:41 +0000 (20:36 -0400)]
Fail on error when processing KDC-issued authdata
Have k5_get_kdc_issued_authdata() return 0 on a verification failure and
non-zero for other failures, rather than call assert(). Check the
return value when called in krb5int_authdata_verify().
Matt Rogers [Fri, 13 May 2016 00:06:42 +0000 (20:06 -0400)]
Add auth indicator authdata module
This authdata module makes the 'auth-indicator' attribute available to
the GSSAPI name extension functions. The auth indicator values are UTF8
strings imported during AP_REQ processing.
Matt Rogers [Thu, 12 May 2016 23:43:55 +0000 (19:43 -0400)]
Add libkrb5 CAMMAC and auth-indicator functions
Add k5_unwrap_cammac_svc() and k5_authind_decode() internal functions
to libkrb5, for use by test programs and the forthcoming
auth-indicator authdata module. Remove the unused
cammac_check_svcver() from the KDC code. Modify tests/adata.c to use
the new functions, and add a test case to t_authdata.py for multiple
indicator values.
[ghudson@mit.edu: squash three commits; make k5_cammac_check_svcver()
a static helper]
Matt Rogers [Fri, 22 Apr 2016 16:23:37 +0000 (12:23 -0400)]
Add kprop and iprop default_realm tests
Add tests to t_iprop.py and t_kprop.py that exercise cases where
default_realm and domain_realm maps differ, as well as overriding the
default realm with the -r argument. This includes the testing of -r
with kadmind, and an update of expected ulog numbers for tests following
the addition of an incremental test. Also refactor some common code in
t_kprop.py to use in the new tests.
Matt Rogers [Thu, 25 Feb 2016 15:38:07 +0000 (10:38 -0500)]
Fix kprop and kpropd realm handling
Add the sn2princ_with_realm() helper function (currently duplicated in
kprop.c and kpropd.c) to simplify principal realm substitution. Use
sn2princ_with_realm() in kprop.c and kpropd.c in place of
krb5_sname_to_principal(), with the default realm if -r is not provided.
If a realm is given to kpropd, set it as the default realm on the
kpropd_context, allowing a later call of ulog_replay() to open the
correct database.
Remove referral realm code in kprop.c and kpropd.c. Pass the realm
(default or provided) to the kdb5_util and kprop commands called by
kadmind.
Greg Hudson [Thu, 9 Jun 2016 17:23:48 +0000 (13:23 -0400)]
Fix use_master handling with KDC hook reply
A post-receive KDC hook may synthesize a reply if k5_sendto() returns
an error. If this happens, krb5_sendto_kdc() must not use server_used
to check if the reply came from a master KDC, as it does not have a
valid value. Preemptively set *use_master to 1 in this case to bypass
the check.
Greg Hudson [Wed, 8 Jun 2016 04:00:55 +0000 (00:00 -0400)]
Fix kadmin min_life check with nonexistent policy
In kadmind, self-service key changes require a check against the
policy's min_life field. If the policy does not exist, this check
should succeed according to the semantics introduced by ticket #7385.
Fix check_min_life() to return 0 if kadm5_get_policy() returns
KADM5_UNK_POLICY. Reported by John Devitofranceschi.
Greg Hudson [Thu, 2 Jun 2016 15:58:35 +0000 (11:58 -0400)]
Fix bugs in recent locate_kdc.c change
The most recent change to locate_srv_conf_1() introduced a possible
double-free bug (detected by Coverity), and also broke MS-KKDCP
support. Separate the three uses of the "host" variable: the C string
copy of the realm name (now "realmstr"), the pointer to the hostname
or hostname:port specification in the profile values array (now
"hostspec"), and the hostname result of k5_parse_host_string() (still
"host"). Pass the correct pointer to k5_parse_host_string() if the
profile value is a URI.
Sarah Day [Tue, 19 Jan 2016 14:47:10 +0000 (09:47 -0500)]
Add k5_parse_host_string()
Add a helper function k5_parse_host_string() containing the
hostname-and-port parsing logic currently inlined into
locate_srv_conf_1(). The new function will also accept a port number
without hostname, for parsing listener addresses.
[ghudson@mit.edu: simplified parsing code and better handle edge
cases; split into two commits]
Greg Hudson [Mon, 9 May 2016 17:45:06 +0000 (13:45 -0400)]
Fix unlikely pointer error in get_in_tkt.c
In add_padata(), reset the caller's pointer and ensure the list is
terminated as soon as realloc() succeeds; otherwise, the old pointer
could be left behind if a later allocation fails.
Tom Yu [Fri, 27 May 2016 19:19:43 +0000 (15:19 -0400)]
Relax t_sn2princ.py reverse resolution test
Relax t_sn2princ.py check of the reverse resolution of the test
hostname. The new requirement is that it be different from the
forward resolved hostname. (There is also an existing implicit
requirement that it be in the mit.edu domain.) This makes
t_sn2princ.py more robust against changes in the reverse resolution of
the test hostname.
Simo Sorce [Wed, 30 Mar 2016 17:00:19 +0000 (13:00 -0400)]
Add SPNEGO special case for NTLMSSP+MechListMIC
MS-SPNG section 3.3.5.1 documents an odd behavior the SPNEGO layer
needs to implement specifically for the NTLMSSP mechanism. This is
required for compatibility with Windows services.
In otp_client_process(), call cb->set_as_key() later in the function
after the OTP request has been created. The previous position of this
call caused the AS key to be replaced even when later code in the
function failed, preventing other preauth mechanisms from retrieving
the correct AS key.
Robbie Harwood [Fri, 20 May 2016 00:31:38 +0000 (20:31 -0400)]
Do not indicate deprecated GSS mechanisms
The mechanisms themeselves will continue to work if requested, but will
not be included in the gss_indicate_mech() list. This works around a
bug in some legacy applications that cannot cope with deprecated mechs
being returned.
Greg Hudson [Thu, 12 May 2016 20:03:06 +0000 (16:03 -0400)]
Check princ length in krb5_sname_match()
krb5_sname_match() can read past the end of princ's component array in
some circumstances (typically when a keytab contains both "x" and
"x/y" principals). Add a length check. Reported by Spencer Jackson.
Greg Hudson [Tue, 17 May 2016 23:28:25 +0000 (19:28 -0400)]
Simplify principal and policy manipulation code
Now that principal entry and policy fields are allocated using the
malloc visible to the krb5 libraries, we don't need to use
krb5_db_alloc() and krb5_db_free() when modifying them within our
code.
Greg Hudson [Tue, 17 May 2016 02:54:06 +0000 (22:54 -0400)]
Use library malloc for principal, policy entries
Alter the KDB module contract to require that KDB modules use an
allocator compatible with the malloc() seen by libkrb5 and libkdb5.
Change krb5_db_alloc() and krb5_db_free() to provide access to this
allocator. Remove free_principal, free_policy, alloc, and free from
the KDB interface and from all in-tree KDB modules.
Sarah Day [Fri, 29 Apr 2016 14:26:31 +0000 (10:26 -0400)]
Implement principal renaming in LDAP
The generic method of renaming principals (by adding a new entry and
deleting the old one) does not work in LDAP. Add an LDAP
implementation of rename that properly renames the DN and attributes
when necessary.
[ghudson@mit.edu: minor naming changes and code simplifications]
Sarah Day [Thu, 31 Mar 2016 21:49:55 +0000 (17:49 -0400)]
Add new DAL function for renaming principals
Previously libkadm5srv renamed principals by getting the principal
entry, renaming the entry, putting it in the DB, then deleting the old
one. This does not work in certain KDB modules such as LDAP. A new
DAL function is necessary to support all KDB modules. Add a new DAL
function to support custom renames in all KDB modules, with a default
implementation that performs the previous functionality of adding and
deleting the principal entry.
NOTE: if the default rename function isn't used and iprop logging is
enabled, iprop would fail since it doesn't formally support renaming.
In that case, the call to krb5_db_rename_principal() will fail with
the code KRB5_PLUGIN_OP_NOTSUPP.
Greg Hudson [Mon, 2 May 2016 16:51:03 +0000 (12:51 -0400)]
Fix cstyle-file.py when emacs is not installed
emacs_reindent() is intended to fail gracefully when emacs is not
installed, but instead subprocess.call() throws an OSError. Check for
this error and return normally.