From nobody Sun Nov 27 02:44:05 2022 X-Original-To: dev-commits-src-all@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 4NKXx208jtz4hmJ1; Sun, 27 Nov 2022 02:44:06 +0000 (UTC) (envelope-from git@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 4NKXx16fSrz3Qqb; Sun, 27 Nov 2022 02:44:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669517045; 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=B1jvyo9OjWuXgihAIarLOwMogB1fAb/UjCzQFJ8uoXQ=; b=CZ5UBetrUnkgofDFaDgN0Up51HE6nskX5UNwn9UrXLZRwGc4O5BJMqEieQ7dkDFBl/zzaM kxeZPDVZ+SVCOmw1nKZG5H80HHgj+fp2UVq8TVRHUpXzZCe+z/tY/hAbVvd4ci6q4WZVYs UTR1E/1AUCUiV2tZcHChLBFgL9fQH8cenXbnDVDD8oAlelCq7RhVlgXJ/73wUZfenfoVn7 0DZx0+EUmCi3typI142+KIm/jh+shfA0/1saM6LbQGtUpA+qc86O2RKXg2PxcWpQP+AH40 S+g6DsQzvKrGPhYi3BkOrYjYeBXjmPYbi/S1U53AfRI37KzbpOJt8XWTcrDLyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669517045; 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=B1jvyo9OjWuXgihAIarLOwMogB1fAb/UjCzQFJ8uoXQ=; b=AIpXEwXEjiV5fzi+6zKlU39MBH3r+XHOlE+dcZTU3Z46lUl57fKqDwEdI2xjcIAs8dGCBC B9gfuIzmK1wpH3KrazhSRtR8GXD+7ZkWD8WkFvnJwWjykVpUOGhCmSXdgzDiACeBV8k4vM oAWKBMnoNiV1a8XM8xJJ3C58p4bgE3d4bkCB92/0+IOAlFGx+QKAvNxN5GSx/1m8NlTwsF +67fhKfhDD9l5ZG9saWSELl3I/O+vv0aHDANItH1yQTjSuobQDRcy/1hcQOLB0ZBjXD9dx PYQ6Gh4r2y/wzbVDxD71sTvgFpbz038VTZHVJSpz3eI0BGVQ0EEz7ItzvzWW6w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669517045; a=rsa-sha256; cv=none; b=OhiUMG6i5iFpq1W1q6IU1ZG4vVWAKY4K/5zHQjxWDQhNhtajT+ixWcm+G3Yx/lnIEBEsSI bcufmjgChW69mPrNxMhl0wT1biW1KRN3SPY6XCzB8kvVqLGGFLsz3etjKQoO9ym96gZSIb HsMJdqkhi+T09PrtGJDzFouV1rugyf2r3/CTJ5nbxBEHA7hpOE5zumYkBmap0i/Upp+3Pe PuD/bytTGM5ZPby8wYCXs5Gcx4wogdnstZ1BD3xdg7ZowLVHSo7cso2WNRT1KsiZPFAbG+ e90WsM6eCFJR3eX73w/E6CpOzmKUxoFSj0Wqos7p8Fyy0HA1/VPFRRQTpqe6Kw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 4NKXx15kW5zjVs; Sun, 27 Nov 2022 02:44:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AR2i5gK088296; Sun, 27 Nov 2022 02:44:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AR2i5p4088295; Sun, 27 Nov 2022 02:44:05 GMT (envelope-from git) Date: Sun, 27 Nov 2022 02:44:05 GMT Message-Id: <202211270244.2AR2i5p4088295@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: 80999dcd5bde - main - heimdal: Add missing kadmind error checks List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 80999dcd5bdebd0beb2591a1de3f6db9767c0066 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=80999dcd5bdebd0beb2591a1de3f6db9767c0066 commit 80999dcd5bdebd0beb2591a1de3f6db9767c0066 Author: Cy Schubert AuthorDate: 2022-11-26 17:48:31 +0000 Commit: Cy Schubert CommitDate: 2022-11-27 02:41:52 +0000 heimdal: Add missing kadmind error checks Inspired by: Heimdal commmit 1b213c1082be4ef5a1c23928d614c762f837dbe7 MFC after: 3 days --- crypto/heimdal/kadmin/server.c | 108 ++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/crypto/heimdal/kadmin/server.c b/crypto/heimdal/kadmin/server.c index 2800a2e1fc29..ed6ba5a1f790 100644 --- a/crypto/heimdal/kadmin/server.c +++ b/crypto/heimdal/kadmin/server.c @@ -38,7 +38,8 @@ static kadm5_ret_t kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, krb5_data *in, krb5_data *out) { - kadm5_ret_t ret; + kadm5_ret_t ret = 0; + kadm5_ret_t ret_sp = 0; int32_t cmd, mask, tmp; kadm5_server_context *contextp = kadm_handlep; char client[128], name[128], name2[128]; @@ -50,16 +51,23 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, int n_keys; char **princs; int n_princs; - krb5_storage *sp; + krb5_storage *rsp = NULL; /* response goes here */ + krb5_storage *sp = NULL; - krb5_unparse_name_fixed(contextp->context, contextp->caller, + memset(&ent, 0, sizeof(ent)); + krb5_data_zero(out); + ret = krb5_unparse_name_fixed(contextp->context, contextp->caller, client, sizeof(client)); sp = krb5_storage_from_data(in); if (sp == NULL) krb5_errx(contextp->context, 1, "out of memory"); - krb5_ret_int32(sp, &cmd); + ret = krb5_ret_int32(sp, &cmd); + if (ret) { + krb5_storage_free(sp); + goto fail; + } switch(cmd){ case kadm_get:{ op = "GET"; @@ -72,9 +80,10 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, goto fail; } mask |= KADM5_PRINCIPAL; - krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); + ret = krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_GET, princ); + if (ret == 0) + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_GET, princ); if(ret){ krb5_free_principal(contextp->context, princ); goto fail; @@ -95,9 +104,10 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, ret = krb5_ret_principal(sp, &princ); if(ret) goto fail; - krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); + ret = krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_DELETE, princ); + if (ret == 0) + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_DELETE, princ); if(ret){ krb5_free_principal(contextp->context, princ); goto fail; @@ -124,10 +134,11 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, kadm5_free_principal_ent(contextp->context, &ent); goto fail; } - krb5_unparse_name_fixed(contextp->context, ent.principal, + ret = krb5_unparse_name_fixed(contextp->context, ent.principal, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_ADD, + if (ret == 0) + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_ADD, ent.principal); if(ret){ kadm5_free_principal_ent(contextp->context, &ent); @@ -155,10 +166,11 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, kadm5_free_principal_ent(contextp, &ent); goto fail; } - krb5_unparse_name_fixed(contextp->context, ent.principal, + ret = krb5_unparse_name_fixed(contextp->context, ent.principal, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_MODIFY, + if (ret == 0) + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_MODIFY, ent.principal); if(ret){ kadm5_free_principal_ent(contextp, &ent); @@ -181,11 +193,13 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, krb5_free_principal(contextp->context, princ); goto fail; } - krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); - krb5_unparse_name_fixed(contextp->context, princ2, name2, sizeof(name2)); + ret = krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); + if (ret == 0) + ret = krb5_unparse_name_fixed(contextp->context, princ2, name2, sizeof(name2)); krb5_warnx(contextp->context, "%s: %s %s -> %s", client, op, name, name2); - ret = _kadm5_acl_check_permission(contextp, + if (ret == 0) + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_ADD, princ2) || _kadm5_acl_check_permission(contextp, @@ -214,7 +228,7 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, krb5_free_principal(contextp->context, princ); goto fail; } - krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); + ret = krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); /* @@ -227,26 +241,28 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, * c) the user is on the CPW ACL. */ - if (krb5_config_get_bool_default(contextp->context, NULL, TRUE, - "kadmin", "allow_self_change_password", NULL) - && initial - && krb5_principal_compare (contextp->context, contextp->caller, - princ)) - { - krb5_data pwd_data; - const char *pwd_reason; - - pwd_data.data = password; - pwd_data.length = strlen(password); - - pwd_reason = kadm5_check_password_quality (contextp->context, - princ, &pwd_data); - if (pwd_reason != NULL) - ret = KADM5_PASS_Q_DICT; - else - ret = 0; - } else - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_CPW, princ); + if (ret == 0) { + if (krb5_config_get_bool_default(contextp->context, NULL, TRUE, + "kadmin", "allow_self_change_password", NULL) + && initial + && krb5_principal_compare (contextp->context, contextp->caller, + princ)) + { + krb5_data pwd_data; + const char *pwd_reason; + + pwd_data.data = password; + pwd_data.length = strlen(password); + + pwd_reason = kadm5_check_password_quality (contextp->context, + princ, &pwd_data); + if (pwd_reason != NULL) + ret = KADM5_PASS_Q_DICT; + else + ret = 0; + } else + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_CPW, princ); + } if(ret) { krb5_free_principal(contextp->context, princ); @@ -304,7 +320,7 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, } } - krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); + ret = krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); /* @@ -312,7 +328,8 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, * this it to force password quality check on the user. */ - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_CPW, princ); + if (ret == 0) + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_CPW, princ); if(ret) { int16_t dummy = n_key_data; @@ -339,7 +356,7 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, ret = krb5_ret_principal(sp, &princ); if(ret) goto fail; - krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); + ret = krb5_unparse_name_fixed(contextp->context, princ, name, sizeof(name)); krb5_warnx(contextp->context, "%s: %s %s", client, op, name); /* * The change is allowed if at least one of: @@ -347,13 +364,14 @@ kadmind_dispatch(void *kadm_handlep, krb5_boolean initial, * b) the user is on the CPW ACL. */ - if (initial - && krb5_principal_compare (contextp->context, contextp->caller, + if (ret == 0) { + if (initial + && krb5_principal_compare (contextp->context, contextp->caller, princ)) - ret = 0; - else - ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_CPW, princ); - + ret = 0; + else + ret = _kadm5_acl_check_permission(contextp, KADM5_PRIV_CPW, princ); + } if(ret) { krb5_free_principal(contextp->context, princ); goto fail;