From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793208440; b=ym48pvYDstc+5IuMMZGQAn1IPFeiEXjTqLn0iU9m27Fek0fDTwHdTSoaucjepca4moP9 H0/btHlcyjfj2lbkBKQmb/ItTjqYo+h3gs651eSyenDrtYIG3prMxWsOt6fVgzUeAQ7zL 2rK+l7qpsJpIrTuXRLlLrTcRqiTZbP7iwNJnJHG8ElHJshhHxNIg3RlYFBW0Kzb619dL9 iJJQiPydJC39Y2HVjzaD5GyJ2CpqPZKBFY8wTu6AQ8y3LrC1WCQwUGPFn6e0Z2CP51qt6 pzUhb/vEY++bGZaW5c4h99EZwonfcDynZwH/jt5Afeq82M4T9Nk+PM9v5KYCT7bzXOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793208440; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=IketQeLb/pcA97i/01QugjYA3Ds4Hv+lLgmmxcMEio0=; b=TBINbNpy6XSP57XRgRD9388LZNQ8qXyiOEDuSia2Va5sPjcCWJykFwGrJcNSw4daA89y 5lOqQlh5Z99WEVDA07M1FGUr2X9HmIz4t1SnFnC02Xug4Bye2MXgX/lwSw2vT11nit8gj oKtod3HGWxmYruZPBeKJnWVHqp9hHFAUmsuwr8tTx0577/v70X3BNYKd2odYoBHq4ZoSl cfElr7XxiHn6O5vB8ANGkY+fRw+8QdNVbVL0nlsbtlYcFW8kXDgy1vi+RHeTMveVlTFPG Pxdal5Zk1+5+sQazE2rlj5FBXgu1N4kZvw5AKio8S0YNBMoD0/qJ+i9wnMlpIRnX04Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TWYpulE5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BFE6606A31A; Wed, 28 Oct 2026 17:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TWYpulE5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7372C1F01825; Wed, 28 Oct 2026 17:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793208440; bh=IketQeLb/pcA97i/01QugjYA3Ds4Hv+lLgmmxcMEio0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TWYpulE5gqkyxonUtdhHn2tO4WkgWxN6RPe/SRc6sjTJedyoA5ZsyRrHx5WRv5y5L Aty4NWhnCJ89uTmwx2hkuKpxcuT8Fwte7JwkHow021GsQQBxnnvLwAT9ZfKRGKez2i NfcIe8vApwV4Ub4FU6BI9MI/Lhm/G2mgJRB5M+UM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vega , Yuqi Xu , Ren Wei , Simon Horman , Paolo Abeni , Sasha Levin Subject: [PATCH 5.10 120/516] net: ipconfig: bound DHCP option construction Date: Wed, 28 Oct 2026 17:54:32 +0100 Message-ID: <20261028170006.359375429@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170003.522232767@linuxfoundation.org> References: <20261028170003.522232767@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuqi Xu [ Upstream commit e47a1958e12abc3a17b5231a4f21c8f1bf662e08 ] ic_dhcp_init_options() appends the hostname (option 12), vendor-class (option 60) and client-ID (option 61) options into the fixed 312-byte bootp_pkt.exten[] buffer. Only the client-ID branch checked the remaining space; the hostname and vendor-class writes were unbounded. A 64-byte hostname together with the maximum 252-byte dhcpclass= identifier needs 18 + (2 + 64) + (2 + 252) = 338 of the 312 available bytes even before the terminating END marker, so the vendor-class memcpy runs past the end of exten[]. With CONFIG_FORTIFY_SOURCE this is reported as a field-spanning write and, when the kernel is booted with panic_on_warn=1, aborts boot with a panic. Route the optional options through a common helper that makes sure the option, its 2-byte header and the END marker all fit and drops an option that would not. Configurations with short options keep sending exactly the same bytes as before. Fixes: 130c0f47fdf9 ("ipconfig: send host-name in DHCP requests") Cc: stable@vger.kernel.org Reported-by: Vega Assisted-by: LLM Signed-off-by: Yuqi Xu Reviewed-by: Ren Wei Reviewed-by: Simon Horman Link: https://patch.msgid.link/7808dfbfa2162dfd0b19f59aff5742d6e0db2abb.1789798023.git.xuyuqiabc@gmail.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/ipv4/ipconfig.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index 986d469651d2e..8e24dc3c326bb 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c @@ -649,6 +649,24 @@ static const u8 ic_bootp_cookie[4] = { 99, 130, 83, 99 }; #ifdef IPCONFIG_DHCP +static bool __init +ic_dhcp_add_option(u8 **options, const u8 *end, u8 type, const void *value, + int len) +{ + u8 *e = *options; + + /* leave room for the option header and the END marker */ + if (len > U8_MAX || end - e < len + 3) + return false; + + *e++ = type; + *e++ = len; + memcpy(e, value, len); + *options = e + len; + + return true; +} + static void __init ic_dhcp_init_options(u8 *options, struct ic_device *d) { @@ -664,6 +682,7 @@ ic_dhcp_init_options(u8 *options, struct ic_device *d) 42, /* NTP servers */ }; u8 mt = (ic_servaddr == NONE) ? DHCPDISCOVER : DHCPREQUEST; + u8 *end = options + sizeof(((struct bootp_pkt *)0)->exten); u8 *e = options; int len; @@ -694,31 +713,19 @@ ic_dhcp_init_options(u8 *options, struct ic_device *d) e += sizeof(ic_req_params); if (ic_host_name_set) { - *e++ = 12; /* host-name */ len = strlen(utsname()->nodename); - *e++ = len; - memcpy(e, utsname()->nodename, len); - e += len; + ic_dhcp_add_option(&e, end, 12, utsname()->nodename, len); } if (*vendor_class_identifier) { - pr_info("DHCP: sending class identifier \"%s\"\n", - vendor_class_identifier); - *e++ = 60; /* Class-identifier */ len = strlen(vendor_class_identifier); - *e++ = len; - memcpy(e, vendor_class_identifier, len); - e += len; + if (ic_dhcp_add_option(&e, end, 60, vendor_class_identifier, len)) + pr_info("DHCP: sending class identifier \"%s\"\n", + vendor_class_identifier); } len = strlen(dhcp_client_identifier + 1); - /* 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; - } + /* the minimum length of identifier is 2, include 1 byte type */ + if (len >= 1) + ic_dhcp_add_option(&e, end, 61, dhcp_client_identifier, len + 1); *e++ = 255; /* End of the list */ } -- 2.53.0