From nobody Fri Jan 19 20:22:02 2024 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 4TGrcs5pBZz57Kp4; Fri, 19 Jan 2024 20:22:05 +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 4TGrcq3mdyz40H6; Fri, 19 Jan 2024 20:22:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705695723; 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=eS6ZIPe4U7zZ9arm28PP+34uxLMLhDV2Uxeal95T+mg=; b=fooMy/wHNgLvl8IhdCzGQNQBwWSU9HAjIX4im5kFZjyHpq8R2a0tDjZ7F/ex+o+S/+sg0n wy+F4isEwIHqGGeyBuG3QHx2O308Vey1OSCZoqaNHHomTCabMm+KGktIi9gAd6DvQeAZW4 DQ5lOwzNPWTUKFbwJU4wXs49TmQEzap5MbHrL2V9EFzL3Wy6WRDmhT3hPZXsfm15od1/PC w0PrSx4ID3MQ9Qw7UTOOX1vUgEFbJRZKGgJyPS1nQxrDdvWcHSo3smeEyt+3qo7XpIdkmD vHPLMdBF9tf6hMc3Bg8lIXinJdpcgSy4OzPZPCTfOpcm2gFaR3cK5tGx3y999A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705695723; 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=eS6ZIPe4U7zZ9arm28PP+34uxLMLhDV2Uxeal95T+mg=; b=Ao7vUwQ1szNLOZ8lDXI2GzDjGqJ/oNwHnxW74hAsdOmmt651Ydw2uB/wtAk7t4jz2r1CkH DGJpiVGPamKGAbsFeGuZK5eULJJt2MNka3aBFnRlgkrOMRrG8x+k1ngzQb7Z2bHRoVu9zy p9i1EW86eWflakdgQQLJ7k6fyX5nFDZc8aPzYWrSxjwIv0peH7M+lgIsHcmmzSKkRRPfyK Dv/3ujvXGxQ8lf+3wmx/5RSSpK9ffjhgvXJXiiXmbqZ35Yoo5MhvAW0CVMaytAPCCGdGiL 3rNoZGojW+mwoBlaFVwYgazMWBppPQ19uV3hWg7Uoq4gNQqldPJ3XzV9kWqVAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705695723; a=rsa-sha256; cv=none; b=WjurKei3ZbJadCbV+4rBhFb4grS73NjwPjLyKXcnUxbFdiN0XgBEUUnGHsyl4xU4ifJisC HAFQJJCjcbZqGwtN86iXavd4/hDe/VIVC/oxltt0pGMo9gUib07rNvcxq+ZD6I1bIXNK6C YIdBTIAZWYTXINegY0v4BrCCgaKnM4rQZoY/jHODi42BG39fawx16T9WkfjQo4Yl4WyH/v srBB18wVsvLIHVzM98IvZzwCO0bjBBkRtPFILbLd9hrVl9EEOynB+KGfdSGYpIUgRdtTWP UjsRkEqnzcxyzrXdJ+g1DhTnjNFog6/V+QcXHCDC+vO5jpfRwply69MWJ9t5xw== 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 4TGrcq11fPz15XF; Fri, 19 Jan 2024 20:22:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40JKM2M4016653; Fri, 19 Jan 2024 20:22:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40JKM2f2016650; Fri, 19 Jan 2024 20:22:02 GMT (envelope-from git) Date: Fri, 19 Jan 2024 20:22:02 GMT Message-Id: <202401192022.40JKM2f2016650@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: c2ec8038a7f1 - stable/13 - Fix multiple bugs with ctld's UCL parsing 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: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c2ec8038a7f1a52c013c2d4d215363ff906c6781 Auto-Submitted: auto-generated The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=c2ec8038a7f1a52c013c2d4d215363ff906c6781 commit c2ec8038a7f1a52c013c2d4d215363ff906c6781 Author: Alan Somers AuthorDate: 2023-10-09 18:26:25 +0000 Commit: Alan Somers CommitDate: 2024-01-19 20:21:40 +0000 Fix multiple bugs with ctld's UCL parsing * Don't segfault when parsing a misformatted auth-group section * If the config file specifies a chap section within a target but no auth-group, create a new anonymous auth-group. That matches the behavior with non-UCL config files. * Protect some potential segfaults with assertions PR: 274380 Sponsored by: Axcient Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D43198 (cherry picked from commit 2391e536c01cb51d2a2c11a0f5820481314e9ec2) --- usr.sbin/ctld/ctld.c | 1 + usr.sbin/ctld/uclparse.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index 2a69308ff067..f2b2de5b9a57 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -533,6 +533,7 @@ auth_group_find(const struct conf *conf, const char *name) { struct auth_group *ag; + assert(name != NULL); TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) { if (ag->ag_name != NULL && strcmp(ag->ag_name, name) == 0) return (ag); diff --git a/usr.sbin/ctld/uclparse.c b/usr.sbin/ctld/uclparse.c index f3f8df81e492..8bd1ca88d166 100644 --- a/usr.sbin/ctld/uclparse.c +++ b/usr.sbin/ctld/uclparse.c @@ -60,6 +60,7 @@ uclparse_chap(struct auth_group *auth_group, const ucl_object_t *obj) const struct auth *ca; const ucl_object_t *user, *secret; + assert(auth_group != NULL); user = ucl_object_find_key(obj, "user"); if (!user || user->type != UCL_STRING) { log_warnx("chap section in auth-group \"%s\" is missing " @@ -90,6 +91,7 @@ uclparse_chap_mutual(struct auth_group *auth_group, const ucl_object_t *obj) const ucl_object_t *user, *secret, *mutual_user; const ucl_object_t *mutual_secret; + assert(auth_group != NULL); user = ucl_object_find_key(obj, "user"); if (!user || user->type != UCL_STRING) { log_warnx("chap-mutual section in auth-group \"%s\" is missing " @@ -714,6 +716,8 @@ uclparse_target(const char *name, const ucl_object_t *top) } if (!strcmp(key, "auth-group")) { + const char *ag; + if (target->t_auth_group != NULL) { if (target->t_auth_group->ag_name != NULL) log_warnx("auth-group for target \"%s\" " @@ -725,8 +729,12 @@ uclparse_target(const char *name, const ucl_object_t *top) "target \"%s\"", target->t_name); return (1); } - target->t_auth_group = auth_group_find(conf, - ucl_object_tostring(obj)); + ag = ucl_object_tostring(obj); + if (!ag) { + log_warnx("auth-group must be a string"); + return (1); + } + target->t_auth_group = auth_group_find(conf, ag); if (target->t_auth_group == NULL) { log_warnx("unknown auth-group \"%s\" for target " "\"%s\"", ucl_object_tostring(obj), @@ -759,6 +767,20 @@ uclparse_target(const char *name, const ucl_object_t *top) } if (!strcmp(key, "chap")) { + if (target->t_auth_group != NULL) { + if (target->t_auth_group->ag_name != NULL) { + log_warnx("cannot use both auth-group " + "and chap for target \"%s\"", + target->t_name); + return (1); + } + } else { + target->t_auth_group = auth_group_new(conf, NULL); + if (target->t_auth_group == NULL) { + return (1); + } + target->t_auth_group->ag_target = target; + } if (uclparse_chap(target->t_auth_group, obj) != 0) return (1); }