From nobody Fri May 1 15:08:19 2026 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 4g6ZDS4L4Sz6bc9m for ; Fri, 01 May 2026 15:08:24 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g6ZDS3SK4z3ZHp for ; Fri, 01 May 2026 15:08:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777648104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BoHhQNmuW0dXD3mAVl1NgsOlZsthK4+/VNTCYgZHNu8=; b=YLzhOK771XWSsAHyVzDGvB6lUVDa7GfFuqUiys/sivhtUfwhTJTBMTM45bM0j9rnV+Y+Zq gck0t5MekAlUTnSliNmK7HjfnxaQh4+IeijZRkACor707BhJlzFKFwgoBcZ2T9hIVLAgWm iGjXxf5Zokr+oTI/UolGIU/ZT4RQFENhPiZiKzF4wkitpDlGbh5CcvKawvawYgaYNq9jek fMox0CMI5dc2D+6RSxW2NgKJySTwGJBJ7I9AtuImb11eKMNRbj6i2pEQHLJhAPTmPcwO77 bufwXNPhYUkuOu0SejQvrAXaFSjj6NhKFXLC630Les21IuZVdQ8YifvoA8OCWg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777648104; a=rsa-sha256; cv=none; b=Z+pTjS0KnW42C+4CGNnQmbQ3+kHIPIoQBmYZNRoV2OaLjoPH8sGG1DqrWKTNRLxPXp07ZE PQrmiCAPXSn6/lldT5ahByWB0/8B3DBtNqVve/RXJh+RMIz4X7VTChaPOR6FoDXoUSJpBO rzRcfHylsTIh11WlVC/UDxGc9sDGuxb0c9tFyYOMpSQDAwxVce5D61nh4TawiiIVrdPM4h I8tN6R0mc/Sbk3kscMfhZLpEeE5tNaf1AC23vsydut49fjeTfyRANyv4Et13q+UV2Uwd9s sFMDCo18prDavz6kb4mwJgp5mhgTbNeUZT3DdJg++pQogDoY+7wBTD4SWkzxdw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777648104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BoHhQNmuW0dXD3mAVl1NgsOlZsthK4+/VNTCYgZHNu8=; b=wXoTrKLoPtu6WfNaipsRccKkqzPYnHiVc5AONfxygljNewykEus30aEvO/GQn7yXtFKRfq o4uXdyQKpMr2KDbPxwpcEWh0UhnyaCg8vWLg1XCGjl4x3HraD3a8lvHciE4qPLDNo1XHbA TMEib6NXodNNXVtEY5j1wp7mWXoKSjFyR2m+v5y/bAZeYF1pKtErAV0dCCZEaMfF+eB7Ct whRGvnXUtOnAWCam8ufLR51KqLZtoE9huxIghRMv6W+kGUCYAnKUl9uQ2caME5B2qzzJ6I EzFdhNR7LUUX7E5LArbkqJAcmwiv6DVm2pOet+Ee0ZG+3kUfKip99snrMoAqJA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g6ZDS2x1Cz13jk for ; Fri, 01 May 2026 15:08:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 190a1 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 01 May 2026 15:08:19 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav From: Mark Johnston Subject: git: b362b6b6c8f2 - releng/13.5 - dhclient: Improve server and filename validation 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.5 X-Git-Reftype: branch X-Git-Commit: b362b6b6c8f28c1ff545bf7c6cdd09388879d1d8 Auto-Submitted: auto-generated Date: Fri, 01 May 2026 15:08:19 +0000 Message-Id: <69f4c1e3.190a1.6c8060e7@gitrepo.freebsd.org> The branch releng/13.5 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b362b6b6c8f28c1ff545bf7c6cdd09388879d1d8 commit b362b6b6c8f28c1ff545bf7c6cdd09388879d1d8 Author: Dag-Erling Smørgrav AuthorDate: 2026-04-30 16:45:35 +0000 Commit: Mark Johnston CommitDate: 2026-04-30 21:20:57 +0000 dhclient: Improve server and filename validation * Don't iterate over each string three times; once is enough. * Reject control characters (anything below space) in addition to the double quote and backslash. * If an unsafe character is encountered, discard the string instead of rejecting the entire lease. * If backslashes are encountered in the file name option, convert them to forward slashes instead of rejecting the option. * Tweak the warning messages a bit. Looking through the rest of the code, it seems to me that notes generally end with a period while warnings generally don't. Approved by: so Security: FreeBSD-EN-26:11.dhclient Fixes: 8008e4b88daf ("dhclient: Check for unexpected characters in some DHCP server options") PR: 294886 MFC after: 1 week Reviewed by: brooks, markj Differential Revision: https://reviews.freebsd.org/D56740 (cherry picked from commit 873a195ba63575e46686cfd6ea9670a0ca340fa0) (cherry picked from commit b1ece85741db0db60ce68daca564f03dc711fe30) --- sbin/dhclient/dhclient.c | 75 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index e8fcdb133dc4..afb37a79d9fc 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1167,7 +1167,7 @@ packet_to_lease(struct packet *packet) lease = malloc(sizeof(struct client_lease)); if (!lease) { - warning("dhcpoffer: no memory to record lease."); + warning("dhcpoffer: no memory to record lease"); return (NULL); } @@ -1208,7 +1208,7 @@ packet_to_lease(struct packet *packet) /* If the server name was filled out, copy it. Do not attempt to validate the server name as a host name. - RFC 2131 merely states that sname is NUL-terminated (which do + RFC 2131 merely states that sname is NUL-terminated (which we do not assume) and that it is the server's host name. Since the ISC client and server allow arbitrary characters, we do as well. */ @@ -1216,39 +1216,72 @@ packet_to_lease(struct packet *packet) !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) && packet->raw->sname[0]) { lease->server_name = malloc(DHCP_SNAME_LEN + 1); - if (!lease->server_name) { - warning("dhcpoffer: no memory for server name."); + if (lease->server_name == NULL) { + warning("dhcpoffer: no memory for server name"); free_client_lease(lease); return (NULL); } - memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN); - lease->server_name[DHCP_SNAME_LEN]='\0'; - if (strchr(lease->server_name, '"') != NULL || - strchr(lease->server_name, '\\') != NULL) { - warning("dhcpoffer: server name contains invalid characters."); - free_client_lease(lease); - return (NULL); + for (i = 0; i < DHCP_SNAME_LEN; i++) { + if (packet->raw->sname[i] == '\0') { + break; + } + if (packet->raw->sname[i] < ' ' || + packet->raw->sname[i] == '"' || + packet->raw->sname[i] == '\\') { + warning("dhcpoffer: server name contains " + "unsafe characters"); + free(lease->server_name); + lease->server_name = NULL; + break; + } + lease->server_name[i] = packet->raw->sname[i]; + } + /* Terminate and zero-pad */ + if (lease->server_name != NULL) { + while (i < DHCP_SNAME_LEN + 1) { + lease->server_name[i++] = '\0'; + } } } - /* Ditto for the filename. */ + /* Ditto for the file name. */ if ((!packet->options[DHO_DHCP_OPTION_OVERLOAD].len || !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) && packet->raw->file[0]) { /* Don't count on the NUL terminator. */ lease->filename = malloc(DHCP_FILE_LEN + 1); - if (!lease->filename) { - warning("dhcpoffer: no memory for filename."); + if (lease->filename == NULL) { + warning("dhcpoffer: no memory for file name"); free_client_lease(lease); return (NULL); } - memcpy(lease->filename, packet->raw->file, DHCP_FILE_LEN); - lease->filename[DHCP_FILE_LEN]='\0'; - if (strchr(lease->filename, '"') != NULL || - strchr(lease->filename, '\\') != NULL) { - warning("dhcpoffer: filename contains invalid characters."); - free_client_lease(lease); - return (NULL); + for (i = 0; i < DHCP_FILE_LEN; i++) { + if (packet->raw->file[i] == '\0') { + break; + } + if (packet->raw->file[i] < ' ' || + packet->raw->file[i] == '"') { + warning("dhcpoffer: file name contains " + "unsafe characters"); + free(lease->filename); + lease->filename = NULL; + break; + } + if (packet->raw->file[i] == '\\') { + /* + * This is common in Windows-centric + * environments. Instead of rejecting, + * silently convert to forward slash. + */ + packet->raw->file[i] = '/'; + } + lease->filename[i] = packet->raw->file[i]; + } + /* Terminate and zero-pad */ + if (lease->filename != NULL) { + while (i < DHCP_FILE_LEN + 1) { + lease->filename[i++] = '\0'; + } } } return lease;