From nobody Fri May 1 15:08:46 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 4g6ZDv28hmz6bcB5 for ; Fri, 01 May 2026 15:08:47 +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 4g6ZDt74kqz3bFk for ; Fri, 01 May 2026 15:08:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777648127; 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=qYkwMC/rMbtKz/RlrZvLMuUTLt8kbAwipjMXIqnyYpA=; b=oFfOcnms4hacLhC7x4UGxoOYu+DIQZvz9CtmI7gMAWsPrUZ/Y+1mrHnVV27HXYd9aphuBL /u/E4npAbc2Yj7bPG7xnZ4KUv4tmU0HtjHfFu6IfgAvqRPMX3ZhSv9tE6i6S3bmvTg5ZB4 rv+1GLyM93c+toz+8JGMHw0Mc/1RBoiHnr8tWU++eWRYFjjR57vZUzQAygPQ06+hPvLt13 1x7w/TCjg+CE2MdFgsOaMo80t0S89VKUJrOoiRWJ0OHgD43ipXrWerrVCG0lNN6YAmobaG hyWsM/ojVk+vt+Mnun0W9q/LLR29680eGoRyaZO8rdhWMO9jPLehs3RpRonNaA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777648127; a=rsa-sha256; cv=none; b=KooUJCFF7vQ2vV3HJrHqFZ5geJQE1bB3n7m31JdF+4PvzCC7+5iGn2TA6Ky23VEH/S0axj 0jJ/6MZeFVZCzvigP7X6TO7ZYdJRJXKbelC6J/MvdYn6ITjw9BinhWO1mctvDzRUwtdKBv JYUiIj1PTan/eZZTVShtCi4ZjWuXZmmnfAV4ekPy3GdlyyOO5JYgqzg5oPacSLRudVafkp 0nmPI++DGjDYMTml1VaMJFUYdui52dj7+/1q7n0qn/+2y1LfAHwHTVNTNKdvnqM0/udqYP akPThMybbf5ptB8Z/wQNNS0+lOxoV6Q5NPqr1+4gfjMu9GNA/faMcxFOP68tsA== 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=1777648127; 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=qYkwMC/rMbtKz/RlrZvLMuUTLt8kbAwipjMXIqnyYpA=; b=ua1r+nudStJNT/2fnlHLR9HIt2QPKYvHqezlq/905DrECV5ik1QK0MoSW3TGegRMYeijly vawp60JFcaqGfuHKVPB6x0NlWs/7T6J3vBBMGU09MJXJm5hifmZMSFvG4ratSnRW4lMkC9 gNqaFa+xE7nGoGObLFTLhxw/OcsWGyxNJOq752AtFrrDc8IiH9jpzP39bo362sikvmpM1r 31i41lIXkTTBTl77twPKYT01qymE/VxL6uJTBFJObxxmGuFAzKI7cEQAxQZ6j4y6qknjR3 pD+6K3x9AXpza/86UK4eSZETCamJcw2mZ2NehXQY+st/elLMY8pY4Y7h7g3N0Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g6ZDt6CcSz13js for ; Fri, 01 May 2026 15:08:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1979a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 01 May 2026 15:08:46 +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: dc8762cfb6e2 - releng/15.0 - 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/15.0 X-Git-Reftype: branch X-Git-Commit: dc8762cfb6e2794ec10873263fa606ff969b1905 Auto-Submitted: auto-generated Date: Fri, 01 May 2026 15:08:46 +0000 Message-Id: <69f4c1fe.1979a.6c0682b@gitrepo.freebsd.org> The branch releng/15.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=dc8762cfb6e2794ec10873263fa606ff969b1905 commit dc8762cfb6e2794ec10873263fa606ff969b1905 Author: Dag-Erling Smørgrav AuthorDate: 2026-04-30 16:45:35 +0000 Commit: Mark Johnston CommitDate: 2026-04-30 21:09:38 +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 252f603d1704044defb7695e707bc87c7f75483a) --- 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 f671b0ab9bed..695451088231 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1161,7 +1161,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); } @@ -1211,7 +1211,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. */ @@ -1219,39 +1219,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;