From nobody Wed Nov 23 10:43:20 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 4NHHls2d4mz4jL12 for ; Wed, 23 Nov 2022 10:43:21 +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 4NHHlr62KWz4Mcf for ; Wed, 23 Nov 2022 10:43:20 +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=1669200200; 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=m8D1p29TQFqCIzaZoAe4Yiw0nU03x9C1kMFL0Kt/0Ok=; b=T4cg9EMyQn2evwcKerzhsivNUHgI34HFRdQ079QM8pkB9phqSJ5mC7IZAZJd7oy76+Ck/c S2sTZM6flBLu2UBQd394RBY7D063BxUAP/U5eh3cVnR1FHrXQvRcqHI+7xpRdriJOippkc QoRe+dbgL/8uEKCrxYYBaFzXJIUKlWC5yC+vi69RaX+9rJquThGWSBNEP+8z57wWohyJVF L8+ZVq/8bXEbNDEkhTXCDKEpL95wv8mvCVfpIKRbPIyHsq2rhSszeccLsX1ZGEefe7fT6x /mOrVjhkXDHN6jCARwuqraaKBuKgzKs3hxKZZvuuWEcmq5W0BqNBKaDR5wwkKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669200200; a=rsa-sha256; cv=none; b=Pava+50MQz6gSgRe/ZZOOf4OXmM4xccsAZTW5Gmic/Ydk5zTnFwgVVIB2JrgVWFoxQfAmh fF180cu0SWooFwW2pkiXzI/9Rm8+nC9mIenoCjehNePJ8VfrIpcagaOwHXnvRSPsAft5hD Z+uvM+pRaiBU3kqrV6HQoVZJDNyMxXikxZvFYm/XpcHi6b171P4UKHbq9xEyMkeMvRBBb7 oNnltKqqzCOb3HXYzoIejad1fQle0h/9geUG9UlwcevybZTGNj7gXPc/MxTWL9jeJN51xd ReRW/emd3dO/AxTsTxQ4naPGsTiCeyA2Fr038rnDlZKoH78P0suW5wZOzAKBtA== 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 4NHHlr55MwzKhW for ; Wed, 23 Nov 2022 10:43:20 +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 2ANAhKPA000267 for ; Wed, 23 Nov 2022 10:43:20 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 2ANAhKdT000266 for bugs@FreeBSD.org; Wed, 23 Nov 2022 10:43:20 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 267944] free() of uninitialized pointer from kadmind_dispatch() and ret_principal_ent() Date: Wed, 23 Nov 2022 10:43:20 +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 Only Me 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=3D267944 Bug ID: 267944 Summary: free() of uninitialized pointer from kadmind_dispatch() and ret_principal_ent() Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu Attachment #238276 text/plain mime type: Created attachment 238276 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D238276&action= =3Dedit provoke a free() of an uninitialized pointer in kadmin kadmind_dispatch() says: kadm5_principal_ent_rec ent; ...; case kadm_create:{ ret =3D kadm5_ret_principal_ent(sp, &ent); ...; ret =3D krb5_ret_int32(sp, &mask); if(ret){ kadm5_free_principal_ent(contextp->context, &ent); kadm5_free_pincipal_ent(hand, princ) frees ent.mod_name (and in particular ent->mod_name->name.name_string.val): if(princ->mod_name) krb5_free_principal(context->context, princ->mod_name); However, certain client messages can cause princ->mod_name to be uninitialized (and contain a non-NULL garbage value). kadmind_dispatch() doesn't zero out ent. ret_principal_ent() in lib/kadm5/marshall.c is in charge of setting all fields from values sent by the client. For mod_name: if (mask & KADM5_MOD_NAME) { krb5_ret_int32(sp, &tmp); if(tmp) krb5_ret_principal(sp, &princ->mod_name); else princ->mod_name =3D NULL; } In this situation the mask bit is always set. krb5_ret_principal() can return an error for some client inputs -- but ret_principal_ent() ignores the error, and on such a code path mode_name is never set, and continues to hold the uninitialized value. One way this can happen is if the client message is too short, so that krb5_ret_principal() hits the end before it has read everything it needs. I've attached a demo; kdc and kadmind should be running, and the user must have kerberos tickets. # cc kadmind14a.c -lkrb5 # ./a.out A backtrace from kadmind. valgrind also sees the bad free(). #0 der_free_general_string (str=3D0x11ad9e1000000000) at /usr/rtm/symbsd/src/crypto/heimdal/lib/asn1/der_free.c:43 #1 0x000000070731254c in free_PrincipalName (data=3D0x67fafadac ) at asn1_krb5_asn1.c:961 #2 0x00000007073129ae in free_Principal (data=3D0x67fafadac ) at asn1_krb5_asn1.c:1122 #3 0x0000000704e6919c in krb5_free_principal (context=3D,=20 p=3D0x67fafadac ) at /usr/rtm/symbsd/src/crypto/heimdal/lib/krb5/principal.c:84 #4 0x0000000701eaff68 in kadm5_free_principal_ent (server_handle=3D0x711ad= 9e10,=20 princ=3D0x7009e6390) at /usr/rtm/symbsd/src/crypto/heimdal/lib/kadm5/free.c:66 #5 0x000000067faf6146 in kadmind_dispatch (kadm_handlep=3D0x711b1f4c0,=20 initial=3D0, in=3D, out=3D0x7009e6568) at /usr/rtm/symbsd/src/crypto/heimdal/kadmin/server.c:122 #6 0x000000067faf5f16 in v5_loop (contextp=3D,=20 ac=3D, initial=3D, kadm_handlep=3D,=20 fd=3D) at /usr/rtm/symbsd/src/crypto/heimdal/kadmin/server.c:459 #7 0x000000067faf5dea in handle_v5 (contextp=3D0x711ad9e10,=20 keytab=3D, fd=3D) at /usr/rtm/symbsd/src/crypto/heimdal/kadmin/server.c:551 #8 0x000000067faf5cf2 in kadmind_loop (contextp=3D0x711ad9e10, --=20 You are receiving this mail because: You are the assignee for the bug.=