]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Correctly handle fallback in KDC OTP callback 801/head
authorRobbie Harwood <rharwood@redhat.com>
Tue, 3 Oct 2017 18:28:47 +0000 (14:28 -0400)
committerGreg Hudson <ghudson@mit.edu>
Thu, 21 Jun 2018 19:16:05 +0000 (15:16 -0400)
In otp_state.c:callback(), avoid invoking the failure callback when we
fall back to the next token.  Since request_send() consumes the
request, don't try to free it.

[ghudson@mit.edu: added test case; edited commit message]

ticket: 8708
tags: pullup
target_version: 1.16-next
target_version: 1.15-next

src/plugins/preauth/otp/otp_state.c
src/tests/t_otp.py

index 5ba3d917aff17edb028dfb6f97b7efa1830b13fc..93ba6c04ae131286c17c9a775032d568cd3e06ab 100644 (file)
@@ -649,6 +649,7 @@ callback(krb5_error_code retval, const krad_packet *rqst,
 
     /* Try the next token. */
     request_send(req);
+    return;
 
 error:
     req->cb(req->data, retval, otp_response_fail, NULL);
index 1142fc799ad0aafcef6ea3b9e9a55eb3d036e4f4..2bbc9a117be580c4fd3835f22251fd43a1575f23 100755 (executable)
@@ -149,17 +149,23 @@ def verify(daemon, queue, reply, usernm, passwd):
     assert data['pass'] == [passwd]
     daemon.join()
 
-def otpconfig(toktype, username=None, indicators=None):
-    val = '[{"type": "%s"' % toktype
+# Compose a single token configuration.
+def otpconfig_1(toktype, username=None, indicators=None):
+    val = '{"type": "%s"' % toktype
     if username is not None:
         val += ', "username": "%s"' % username
     if indicators is not None:
         qind = ['"%s"' % s for s in indicators]
         jsonlist = '[' + ', '.join(qind) + ']'
         val += ', "indicators":' + jsonlist
-    val += '}]'
+    val += '}'
     return val
 
+# Compose a token configuration list suitable for the "otp" string
+# attribute.
+def otpconfig(toktype, username=None, indicators=None):
+    return '[' + otpconfig_1(toktype, username, indicators) + ']'
+
 prefix = "/tmp/%d" % os.getpid()
 secret_file = prefix + ".secret"
 socket_file = prefix + ".socket"
@@ -244,4 +250,20 @@ realm.run([kadminl, 'setstr', realm.user_princ, 'otp', otpconfig('unix')])
 realm.kinit(realm.user_princ, 'accept', flags=flags)
 verify(daemon, queue, True, realm.user_princ, 'accept')
 
+## Regression test for #8708: test with the standard username and two
+## tokens configured, with the first rejecting and the second
+## accepting.  With the bug, the KDC incorrectly rejects the request
+## and then performs invalid memory accesses, most likely crashing.
+daemon1 = UDPRadiusDaemon(args=(server_addr, secret_file, 'accept1', queue))
+daemon2 = UnixRadiusDaemon(args=(socket_file, '', 'accept2', queue))
+daemon1.start()
+queue.get()
+daemon2.start()
+queue.get()
+oconf = '[' + otpconfig_1('udp') + ', ' + otpconfig_1('unix') + ']'
+realm.run([kadminl, 'setstr', realm.user_princ, 'otp', oconf])
+realm.kinit(realm.user_princ, 'accept2', flags=flags)
+verify(daemon1, queue, False, realm.user_princ.split('@')[0], 'accept2')
+verify(daemon2, queue, True, realm.user_princ, 'accept2')
+
 success('OTP tests')