Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C83653655CD for ; Wed, 30 Sep 2026 02:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790735651; cv=none; b=GFka+xMqTH0hVfVfe42eW0TNF+U9S8WscLXH/mPo0ggjn/qs3z1gTQyLM1prPTg63xK4LTTA4KB62A3G0DpSlrpnsDlka7QS1Hbg7b1qe0XOAeW2UjqPAF6pz3trcfVsEnLvLmUyjwTkX4QEWWOQQLT2lN1sYxx0Z9rQI/jpA9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790735651; c=relaxed/simple; bh=l3Qhl6KM+yg7TNLNm/IjyCdj3vooAsQFAWouQJSEwBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J04zjaHrF/1rXIsKQixxHWRxxWG13LgPpsMBCDcSpClRaRCMe6QPMhGqVcv86l4nfWo5lZ9JD+j7C3F2iAMnjbtXgdtueo5Q0jN75oboldoDNxvkEUfBG9yX67VB7cPkCG8+LFrwMLH/eR/WOhCtezIiYBPsTgYWQ3IRFzn3ZPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TojfaKut; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TojfaKut" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EC251F00898; Wed, 30 Sep 2026 02:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790735641; bh=U21+rRPH7DB0SGmwl1Ipz1smPwTV5HenDBy4ARUBc+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TojfaKutev7YOQ6HhjkYisgBpYwcWoPyPc096ezGgx2oqiC1GIEUuTOeaAzLfXAmN lf/N0qZMFsE6GIAu3ccjzW1of/rHge2wnydgaY9XXDUZXOlWH5hA9tq+LetwSezbO3 2nGo++YYu1ufmv4B8V9MADtykzrmTVN191Diyrkv8ywDD+5sVgNIbky5weBX/szT6H qZGYexNePzD2ZrM7Br5FaujhXl3+N4cEhipAmzfcTl3yhEwSTt7X6cb3LK4Zx/cifx Oxb8k3vBN3+UBBYov+Uggmz0//g6BNePefmR7iueiASBiopHVMqiL/GRVXDs0ho4S2 yGvQepS7jrqkA== From: Sasha Levin To: stable@vger.kernel.org Cc: Yuqi Xu , Vega , Ren Wei , Simon Horman , Paolo Abeni , Sasha Levin Subject: [PATCH 5.15.y 2/2] net: ipconfig: bound DHCP option construction Date: Tue, 29 Sep 2026 22:33:58 -0400 Message-ID: <20260930023358.3420548-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930023358.3420548-1-sashal@kernel.org> References: <2026092953-nature-scientist-fa0d@gregkh> <20260930023358.3420548-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 083782a4e010d..eae75cd120858 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c @@ -665,6 +665,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) { @@ -680,6 +698,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; @@ -710,31 +729,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