NetBSD Problem Report #61084

From www@netbsd.org  Fri Nov 27 21:08:18 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8E8B91A923B
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 27 Nov 2026 21:08:18 +0000 (UTC)
Message-Id: <20261127210816.F098E1A923D@mollari.NetBSD.org>
Date: Fri, 27 Nov 2026 21:08:16 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: kinit: krb5_init_context failed: 6
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         61084
>Category:       lib
>Synopsis:       kinit: krb5_init_context failed: 6
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    riastradh
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 27 21:10:01 +0000 2026
>Closed-Date:    
>Last-Modified:  Tue Dec 01 10:35:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, ...
>Organization:
The NetBSD Kerberotion, Inc.
>Environment:
>Description:

	With no /etc/krb5.conf or ~/.krb5/config (or KRB5_CONFIG
	pointing at a nonempty config file):

	$ kinit riastradh@NETBSD.ORG
	kinit: krb5_init_context failed: 6

	This makes it troublesome to just use krb5 for client-side
	single-sign-on out of the box on systems that aren't kerberized
	themselves, e.g. NetBSD developers using their personal laptops
	for access to the NETBSD.ORG realm.

	We put this in a long time ago as a local patch in NetBSD,
	presumably to avoid annoying login delays out of the box
	arising from trying krb5 DNS autoconfiguration -- which is
	neither sensible nor safe to try by default:

> revision 1.2
> date: 2000-07-16 18:27:53 +0000;  author: thorpej;  state: Exp;  lines: +5 -2;
> Return failure if there is no Kerberos 5 configuration file.

	https://cvsweb.netbsd.org/bsdweb.cgi/src/crypto/dist/heimdal/lib/krb5/Attic/context.c#rev1.2

> revision 1.2
> date: 2011-04-14 18:02:07 +0000;  author: elric;  state: Exp;  lines: +2 -2;
> branches:  1.2.4;  1.2.6;  1.2.10;  1.2.12;  1.2.20;
> Turn on the hack which disables Kerberos if there is no /etc/krb5.conf.
> We should review this logic and come up with a better way to do this as
> now that there are DNS SRV RRs for locating KDCs, the lack of a config
> does not imply that Kerberos should be turned off.

	https://cvsweb.netbsd.org/bsdweb.cgi/src/crypto/external/bsd/heimdal/dist/lib/krb5/context.c#rev1.2

	The change made login(1) and su(1) use the existence of a
	nonempty /etc/krb5.conf as an indicator for whether to verify a
	password by acquiring a krb5 ticket with it: no /etc/krb5.conf,
	no krb5 paths in login(1) or su(1).

	This is a bad system for several reasons:

	1. A krb5.conf is not enough to make this secure.  Without a
	   keytab, the verification process used by login(1) and su(1)
	   is vulnerable to a MITM on the network spoofing the KDC.  So
	   simply creating a stub /etc/krb5.conf file has the effect of
	   making the system configuration more vulnerable, and not
	   creating it makes the system less usable.

	   Instead, the Kerberos paths of login(1) and su(1) should
	   check for a keytab first and require having a keytab to
	   verify the tickets, like pam_krb5(8) does:

	   https://mail-index.netbsd.org/source-changes/2023/06/20/msg145461.html

	2. The default builds all use MKKERBEROS=yes MKPAM=yes, under
	   which settings the relevant paths in login(1) and su(1)
	   aren't even built -- they are only built if MKKERBEROS=yes
	   MKPAM=no (which, frankly, I expect is an extremely obscure
	   configuration!).  In the default builds, we already have
	   pam_krb5(8) and pam_ksu(8) disabled by default for other
	   reasons:

	   https://mail-index.netbsd.org/source-changes/2023/06/20/msg145459.html
	   https://ftp.netbsd.org/pub/NetBSD/security/advisories/NetBSD-SA2023-005.txt.asc
	   https://ftp.netbsd.org/pub/NetBSD/security/advisories/NetBSD-SA2023-006.txt.asc

	3. This obscure `krb5_init_context failed: 6' error message
	   makes people think krb5 is weird and hard to use and
	   configure, that aspect of it is a purely self-inflicted
	   mistake in NetBSD.

	See also:

	PR bin/57470: su hangs on network access via pam_ksu even if it
	will never succeed
	https://gnats.NetBSD.org/57470

>How-To-Repeat:

	Try to use krb5 purely for client-side SSO:

	$ kinit jrandomdev@NETBSD.ORG
	kinit: krb5_init_context failed: 6

>Fix:

	1. Fix the login(1) and su(1) paths under MKKERBEROS=yes so
	   that they require a keytab like pam_krb5(8) and pam_ksu(8)
	   do.

	   (In principle this could break the configurations either
	   with a local KDC or by operators who don't care about
	   vulnerability to a MITM spoofing the KDC.  But that seems
	   unlikely and such configurations can use pam with the
	   allow_kdc_spoof option, which is better for usability too
	   because it gets a ticket in addition to verifying a
	   password.)

	2. Verify there are no other users of krb5_verify_user* or
	   krb5_get_init_creds_password that could be affected by this;
	   make sure they all require a keytab and verify the ticket
	   with it.

	3. Change krb5_init_context to not fail with ENXIO when there's
	   no config.  I.e., put the #if 1 back to #if 0 in the
	   one-line changes quoted above:

--- src/crypto/external/bsd/heimdal/dist/lib/krb5/context.c:1.1	Wed Apr 13 18:15:32 2011
+++ src/crypto/external/bsd/heimdal/dist/lib/krb5/context.c	Thu Apr 14 18:02:07 2011
@@ -612,7 +612,7 @@ krb5_set_config_files(krb5_context conte
 	}
 	filenames++;
     }
-#if 0
+#if 1
     /* with this enabled and if there are no config files, Kerberos is
        considererd disabled */
     if(tmp == NULL)

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: lib-bug-people->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Sun, 29 Nov 2026 03:42:26 +0000
Responsible-Changed-Why:
I'm working on drafting patches for login(1) and su(1) to check for a
keytab up front before trying any krb5-related network traffic, and to
make validating the ticket they get with a keytab mandatory for
success.

And then we can flip the libkrb5 switch.


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/usr.bin/su
Date: Tue, 1 Dec 2026 10:25:16 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:25:16 UTC 2026

 Modified Files:
 	src/usr.bin/su: su.c

 Log Message:
 su(1): Quietly check for service key before trying krb5 password.

 Don't provoke any Kerberos-related network traffic until we confirm
 that we have a service key in the default keytab for host/$(hostname)
 in some realm; without any such service key, we have no hope of
 authenticating a service ticket, so there is no point in even trying
 to verify the target user's password by acquiring Kerberos with it.

 This way, simply having a krb5.conf -- or removing our local Heimdal
 patch to make krb5_init_context fail when there is no krb5.conf --
 won't cause su(1) to be subject to Kerberos-induced network delays
 unless you _also_ configure a host service key for it to use.

 This change applies only to the MKPAM=no MKKERBEROS=yes case.

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.76 -r1.77 src/usr.bin/su/su.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/usr.bin/login
Date: Tue, 1 Dec 2026 10:25:33 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:25:33 UTC 2026

 Modified Files:
 	src/usr.bin/login: k5login.c

 Log Message:
 login(1): Require keytab in kerberized login with MKPAM=no.

 The kerberized login procedure works as follows:

 1. User enters a password.
 2. login(1) tries to get a ticket-granting ticket with that password,
    which may entail:
    (a) ask DNS for realm of this hostname
    (b) ask DNS for KDC of this realm
    (c) send KDC an AS-REQ
    If no TGT, fail.
 3. login(1) tries to get a service ticket for host/<hostname>.
 4. login(1) tries to verify the service ticket with the service key
    for host/<hostname>.

 If there is no keytab having the service key of host/<hostname>, step
 (4) won't work.  Previously, this path would fail open: if there is
 no keytab and service key, a fraudulent KDC could enable an attacker
 to log in with a password of their choice.

 To paper over this vulnerability, we long ago patched Heimdal's
 krb5_init_context to fail if there is no /etc/krb5.conf, so the
 vulnerability only happens between the time that you create
 /etc/krb5.conf and populate /etc/krb5.keytab, more or less.  But:

 (a) there's still an unnecessary window of vulnerability (which we
     assigned NetBSD-SA2023-006 for its manifestation in pam_krb5,
     which unlike kerberized login(1) is in the default build), and
 (b) that patch has the side effect of creating a terrible user
     experience for client-side SSO, which shouldn't be tangled up in
     how login(1) works.

 So just make the service key mandatory.

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.33 -r1.34 src/usr.bin/login/k5login.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/usr.bin/login
Date: Tue, 1 Dec 2026 10:25:51 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:25:50 UTC 2026

 Modified Files:
 	src/usr.bin/login: k5login.c login.c

 Log Message:
 login(1): Quietly check for service key before trying krb5 password.

 Don't provoke any Kerberos-related network traffic until we confirm
 that we have a service key in the default keytab for host/$(hostname)
 in some realm; without any such service key, we have no hope of
 authenticating a service ticket, so there is no point in even trying
 to verify the user's password by acquiring Kerberos with it.

 This way, simply having a krb5.conf -- or removing our local Heimdal
 patch to make krb5_init_context fail when there is no krb5.conf --
 won't cause login(1) to be subject to Kerberos-induced network delays
 unless you _also_ configure a host service key for it to use.

 This change applies only to the MKPAM=no MKKERBEROS=yes case.

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.34 -r1.35 src/usr.bin/login/k5login.c
 cvs rdiff -u -r1.105 -r1.106 src/usr.bin/login/login.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/usr.bin/login
Date: Tue, 1 Dec 2026 10:26:06 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:26:06 UTC 2026

 Modified Files:
 	src/usr.bin/login: k5login.c

 Log Message:
 login(1): Minor tidying in kerberized path.

 Avoid some leaks.  Followup for:

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.35 -r1.36 src/usr.bin/login/k5login.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/lib/libpam/modules/pam_krb5
Date: Tue, 1 Dec 2026 10:26:22 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:26:22 UTC 2026

 Modified Files:
 	src/lib/libpam/modules/pam_krb5: pam_krb5.c

 Log Message:
 pam_krb5(8): Check for service keys without talking to the network.

 This way, testing whether it is reasonable to even try krb5 auth
 won't incur any network-related delays on systems that still have
 pam_krb5 enabled by default in /etc/pam.d/system, when we remove the
 patch to krb5_init_context that makes it fail without /etc/krb5.conf,
 for the benefit of client-side SSO.

 This should have no security impact because we still verify
 everything the same way later on, in the conditions under which
 pam_krb5 could allow the user in anyway.

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.32 -r1.33 src/lib/libpam/modules/pam_krb5/pam_krb5.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/lib/libpam/modules/pam_ksu
Date: Tue, 1 Dec 2026 10:26:39 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:26:39 UTC 2026

 Modified Files:
 	src/lib/libpam/modules/pam_ksu: pam_ksu.c

 Log Message:
 pam_ksu(8): Check for service keys without talking to the network.

 This way, testing whether it is reasonable to even try krb5 auth
 won't incur any network-related delays on systems that still have
 pam_ksu enabled by default in /etc/pam.d/su, when we remove the patch
 to krb5_init_context that makes it fail without /etc/krb5.conf, for
 the benefit of client-side SSO.

 This should have no security impact because we still verify
 everything the same way later on, in the conditions under which
 pam_ksu could allow the user switch anyway.

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.11 -r1.12 src/lib/libpam/modules/pam_ksu/pam_ksu.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/lib/libpam/modules/pam_ksu
Date: Tue, 1 Dec 2026 10:27:15 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:27:14 UTC 2026

 Modified Files:
 	src/lib/libpam/modules/pam_ksu: pam_ksu.c

 Log Message:
 pam_ksu(8): Fix memory leaks in error branches.

 Cleanup prompted by:

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.12 -r1.13 src/lib/libpam/modules/pam_ksu/pam_ksu.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 01 Dec 2026 10:33:33 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-11 and pullup-10


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/61084 CVS commit: src/crypto/external/bsd/heimdal/dist/lib/krb5
Date: Tue, 1 Dec 2026 10:30:48 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Dec  1 10:30:48 UTC 2026

 Modified Files:
 	src/crypto/external/bsd/heimdal/dist/lib/krb5: context.c

 Log Message:
 heimdal: Stop requiring a config file to use krb5.

 With this change, you can now do `kinit jrandomuser@EXAMPLE.COM' to
 log into client-side single-sign-on out of the box, no configuration
 required.

 We had previously been carrying this local patch for decades in order
 to paper over bad user experience (as well as what is essentially a
 vulnerability) in kerberized non-pam login(1) and su(1), where they
 would wait for network delays for Kerberos DNS autoconfiguration even
 if they have no Kerberos service key to actually do any meaningful
 authentication checks -- the local patch turned the existence of
 /etc/krb5.conf into a systemwide knob for whether any application is
 allowed to try Kerberos at all.

 Unfortunately, that systemwide knob also affects client-side SSO
 applications, not just system verification of user credentials.

 To make sure that reverting this local patch doesn't create new
 security vulnerabilities or stupid network delays on non-kerberized
 systems, I have also adapted login(1), su(1), pam_krb5(8), and
 pam_ksu(8) to quietly (without any log messages or network traffic)
 verify that they have a Kerberos service key before they try to
 verify passwords with Kerberos.  These are all the callers in src of:

 - krb5_verify_user*
 - krb5_verify_init_creds*
 - krb5_rd_req on a packet obtained by krb5_mk_req from a ticket just
   obtained with krb5_get_init_creds

 Exceptions:

 - openldap's slapd kerberos.c module, which we don't build or ship
 - openssh's KerberosAuthentication, which is default off on the
   server and has been for a very long time if not always

 (Most of these paths -- except for non-pam login(1), which was a
 straggler from NetBSD-SA2023-006 -- already required a service key to
 verify the ticket; they just triggered unnecessary network traffic
 and delays before checking for a service key first.)

 PR lib/61084: kinit: krb5_init_context failed: 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 \
     src/crypto/external/bsd/heimdal/dist/lib/krb5/context.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.