From nobody Fri May 1 15:08:30 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 4g6ZDZ5ZsTz6bc5c for ; Fri, 01 May 2026 15:08:30 +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 4g6ZDZ4yj8z3Zv6 for ; Fri, 01 May 2026 15:08:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777648110; 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=BJSs/FJ84PpkMdKi4Yo1fe5zIkEE4HMBfjdH4YKnGBs=; b=b0th03o2A+zBUE+1efELMuqFL5CCrxraTpt7ZSE/s9etgBlyqdaOHs9kFGTkcLjcOcqhIh 2Juq0LEsfgFcG0mRe1a9F0g8IDzZ+6cREZo0fGQqpzw8QOxuY1g28lcrzFaEGyR1IxB+N3 5VtyKGjftHHNbBpU8C3RmXwj27RXjsx/Wqthmpmp7A7FUmaaIHHZ7T8Fgk9ymU5U+O3xpg /88WFjp75CVr7XQIYx6DDrQfM3FojqiIjpaJ/Acxd1ySXlqnv6uAN37aTufUMpL6WKOt4G HkYMuSYvxGIME11giKKTowIfvNW4n+yaLtnUiIYQSPSx4J1K/4yz7/NCyOku4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777648110; a=rsa-sha256; cv=none; b=mEgJ14E1WFE/yZdVGTE74FZNt1i8SDGB1H8JdK4nk0rAenvZeuy1yCUWW2RZXaneeq2WjZ WhV5ceInS0+UiCwdnVL41+0KidVfStQEsctNAwdyv+jSEhnZz9oTOiIfZjCfFFau2/iKgh CTZViOlbybliDl8OodqDIfNpOOwHZR9hF3BqyLU19FwEQX4TwUzCJaB4BFPmWWP+mzPBm+ MiV7hSx7mnSU9y85rFkJv+7odC3CiTFMkrSw2ijPe6uMLN587Z/Fw8wcZEh189nUx78rNT bgueMfXy5Bj8qZt6eFkLqgXMNdRy1xOs145Aq1AlYpws8P5x7vQumOg54jvrow== 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=1777648110; 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=BJSs/FJ84PpkMdKi4Yo1fe5zIkEE4HMBfjdH4YKnGBs=; b=HtYYxXhEaYtX31jINe8lYFblE3UpVIFRfq0DmZgBRWlvukTiLaoFbvJQAM083MVapJp3NJ DdbZ7JCB4lGTacj8VH5MXIqAw62FeYDz2sC3esn97WBYe+R+2+G3LjZVcdGm6SWO+zmbBz 08PkomLO9gsapDUpNbOFpODYCmzlJundkSBWXbTD9iMpiU+rRm0mMQV43RbDm00QYKigKJ v3+xbO1U0eotf3BKPDuMsRmWCjy1AeUCw0YJqdIGyIzQb3YGqlcKmWaVTBkAnmHVLfSGiq SQG1o+RJ64FXDlIpOKPaw9NJL1F2xfcxAPKVE5g/bZwLa33anxwZWcnRR43reQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g6ZDZ48lzz13Zw for ; Fri, 01 May 2026 15:08:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 47a29 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 01 May 2026 15:08:30 +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: 5bad905eb37f - releng/14.3 - 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/14.3 X-Git-Reftype: branch X-Git-Commit: 5bad905eb37f69a8ac90f5e10c07527aded70b5b Auto-Submitted: auto-generated Date: Fri, 01 May 2026 15:08:30 +0000 Message-Id: <69f4c1ee.47a29.589e6ad0@gitrepo.freebsd.org> The branch releng/14.3 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5bad905eb37f69a8ac90f5e10c07527aded70b5b commit 5bad905eb37f69a8ac90f5e10c07527aded70b5b Author: Dag-Erling Smørgrav AuthorDate: 2026-04-30 16:45:35 +0000 Commit: Mark Johnston CommitDate: 2026-04-30 21:21:27 +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 2f9478ad42c442c49a7eff60227148bf2b90b48c) --- 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 c7a7fcca06ff..0c9ead7dedbb 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;