lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250612191726.2a226cdf@kernel.org>
Date: Thu, 12 Jun 2025 19:17:26 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Petr Zejdl <petr.zejdl@...n.ch>
Cc: "David S. Miller" <davem@...emloft.net>, David Ahern
 <dsahern@...nel.org>, Eric Dumazet <edumazet@...gle.com>, "Paolo Abeni"
 <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
 <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] net: ipv4: ipconfig: Support RFC 4361/3315 DHCP client
 ID in hex format

On Tue, 10 Jun 2025 16:35:03 +0200 Petr Zejdl wrote:
> -		len = strlen(dhcp_client_identifier + 1);

maybe keep using len here? Assign dhcp_client_identifier_len to it?
I don't think switching to dhcp_client_identifier_len improves the
readability and it inflates the diff.

>  		/* the minimum length of identifier is 2, include 1 byte type,
>  		 * and can not be larger than the length of options
>  		 */
> -		if (len >= 1 && len < 312 - (e - options) - 1) {
> -			*e++ = 61;
> -			*e++ = len + 1;
> -			memcpy(e, dhcp_client_identifier, len + 1);
> -			e += len + 1;
> +		if (dhcp_client_identifier_len >= 2) {
> +			if (dhcp_client_identifier_len <= 312 - (e - options) - 3) {
> +				pr_debug("DHCP: sending client identifier %*phC\n",
> +					 dhcp_client_identifier_len,
> +					 dhcp_client_identifier);
> +				*e++ = 61;
> +				*e++ = dhcp_client_identifier_len;
> +				memcpy(e, dhcp_client_identifier,
> +				       dhcp_client_identifier_len);
> +				e += dhcp_client_identifier_len;
> +			} else {
> +				pr_warn("DHCP: client identifier doesn't fit in the packet\n");
> +			}
>  		}
>  	}
>  
> @@ -1661,6 +1669,33 @@ static int __init ip_auto_config(void)
>  
>  late_initcall(ip_auto_config);
>  
> +#ifdef CONFIG_IP_PNP_DHCP
> +/*
> + *  Parses DHCP Client ID in the hex form "XX:XX ... :XX" (like MAC address).
> + *  Returns the length (min 2, max 253) or -EINVAL on parsing error.
> + */
> +static int __init parse_client_id(const char *s, u8 *buf)
> +{
> +	int slen = strlen(s);
> +	int len = (slen + 1) / 3;
> +	int i;
> +
> +	/* Format: XX:XX ... :XX */
> +	if (len * 3 - 1 != slen || len < 2 || len > 253)
> +		return -EINVAL;
> +
> +	for (i = 0; i < len; i++) {
> +		if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
> +			return -EINVAL;
> +		if (i != len - 1 && s[i * 3 + 2] != ':')
> +			return -EINVAL;
> +
> +		buf[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
> +	}
> +
> +	return i;
> +}

Feels like this helper should live in lib/net_utils.c or lib/hexdump.c
as a generic thing?
-- 
pw-bot: cr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ