From nobody Sun Nov 20 20:50:58 2022 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NFjNL45Nlz4hFFD for ; Sun, 20 Nov 2022 20:50:58 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NFjNK71tyz4dMb for ; Sun, 20 Nov 2022 20:50:57 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668977458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EhDBG/ysX3FwQfYF4FxssiEhupwl6IFifX2uqIBKLvY=; b=MxF76ditNsDk/1Bz1l1salO9Tghchu1Shw6cqE8Wuqhyus1Aj6JbxUscB/luSaVrcILJRN aptZYwJtNcMypvJwWPmJWIXI/faCQmn+w3verBZgjRt2aOXceXYWUQUYa4CK2FDwEsob6r 2si4yWHRofx4lig5TkOPrchPS9SyG66t0asjjLn1inBZD0C6t9L8DMyDn47mWZuq9+9lby WzIwcS0Uz5nBDwaI7Oto+PU2N7Cjizb1AgiyL6mh9vrDWQq+oo4gygRYTA5+0TFRBuOh/F zM/rkpT+E+Q4tJPPOrCOm5/vOI1SKXyF0KKR1bksF9k7FVXhRLU94cxusBVmHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668977458; a=rsa-sha256; cv=none; b=B3FL3YVZIwjvdoc+T6t+kf0wSknohXbLctb4NzEdpL9oeDCP11mg1IxQmSywJI10oSGjGf XjdfblxP8nNSiFTrZW4RE/nnq/hVT03ktgauVH25yTxjZZrJdUsAC3RsWCHn0XGPKeez5J e+a8utgABCSZf4YP66mE7twesV6+mhW1N6zMVHGpytrOoCFuEswCjinBvemKexSP5Urw4l 3DnPFlDxsggqwo93V2ysJW/lvS/PodkwYkb3ZcMEPMr3jiGE+67TgKQeCOdswlxslj+VfE RDREEiWZ9AUo5RuuCXEPHjD6eqeHnBJQIHH8GlkzAhirKc6OiHOvN47IABSD/A== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NFjNK65GqzdJd for ; Sun, 20 Nov 2022 20:50:57 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 2AKKovID052075 for ; Sun, 20 Nov 2022 20:50:57 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 2AKKovbV052074 for bugs@FreeBSD.org; Sun, 20 Nov 2022 20:50:57 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 267884] kadmind can read beyond the end of an incoming message's buffer Date: Sun, 20 Nov 2022 20:50:58 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: rtm@lcs.mit.edu X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.mimetype attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D267884 Bug ID: 267884 Summary: kadmind can read beyond the end of an incoming message's buffer Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu Attachment #238198 text/plain mime type: Created attachment 238198 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D238198&action= =3Dedit send a non-null-terminated appl_version to kadmind kadmind's handle_v5() calls krb_recvauth_match_version(), which contains: n =3D krb5_net_read (context, p_fd, &len, 4); ...; len =3D ntohl(len); her_appl_version =3D malloc (len); if (krb5_net_read (context, p_fd, her_appl_version, len) !=3D len || !(*match_appl_version)(match_data, her_appl_version)) { repl =3D 2; krb5_net_write (context, p_fd, &repl, 1); krb5_set_error_message(context, KRB5_SENDAUTH_BADAPPLVERS, N_("wrong sendauth version (%s)", ""), her_appl_version); The code does not check that the incoming message in her_appl_version is null terminated, which can cause trouble for match_appl_version()'s call to sscanf, and krb5_set_error_message's use of her_apply_version. This is with CURRENT source from today (Nov 20 2022). I've attached a demo. Since there's often a null somewhere soon after the end of the allocated buffer, the problem is only reliably visible with something like valgrind: # /usr/libexec/kadmind --version kadmind (Heimdal 1.5.2) Copyright 1995-2011 Kungliga Tekniska H=C3=83=C2=B6gskolan Send bug-reports to heimdal-bugs@h5l.org # valgrind /usr/libexec/kadmind --debug & # cc kadmind3a.c # ./a.out =3D=3D67648=3D=3D Memcheck, a memory error detector =3D=3D67648=3D=3D Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward = et al. =3D=3D67648=3D=3D Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyr= ight info =3D=3D67648=3D=3D Command: /usr/libexec/kadmind --debug =3D=3D67648=3D=3D=20 =3D=3D67648=3D=3D Invalid read of size 1 =3D=3D67648=3D=3D at 0x4852EE9: strlen (in /usr/local/libexec/valgrind/vgpreload_memcheck-amd64-freebsd.so) =3D=3D67648=3D=3D by 0x4A596BC: vsscanf (in /lib/libc.so.7) =3D=3D67648=3D=3D by 0x4A4C72C: sscanf (in /lib/libc.so.7) =3D=3D67648=3D=3D by 0x112677: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x4907BE6: krb5_recvauth_match_version (in /usr/lib/libkrb5.so.11) =3D=3D67648=3D=3D by 0x1114CD: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x112978: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x10D16C: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x4823007: ??? =3D=3D67648=3D=3D Address 0x5b463b6 is 0 bytes after a block of size 150 a= lloc'd =3D=3D67648=3D=3D at 0x484C8A4: malloc (in /usr/local/libexec/valgrind/vgpreload_memcheck-amd64-freebsd.so) =3D=3D67648=3D=3D by 0x4907BA9: krb5_recvauth_match_version (in /usr/lib/libkrb5.so.11) =3D=3D67648=3D=3D by 0x1114CD: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x112978: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x10D16C: ??? (in /usr/libexec/kadmind) =3D=3D67648=3D=3D by 0x4823007: ??? --=20 You are receiving this mail because: You are the assignee for the bug.=