* [PATCH 0/2] dhcp: Harden DNS search domain option handling
@ 2026-11-17 12:06 Anshu Kumari
2026-11-17 12:06 ` [PATCH 1/2] dhcp: Use unsigned int for opts[].slen Anshu Kumari
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Anshu Kumari @ 2026-11-17 12:06 UTC (permalink / raw)
To: sbrivio, passt-dev, eonzylakshitha; +Cc: anskuma
Lakshitha Perera reported a potential out-of-bounds write in
opt_set_dns_search() at revision f8df3f1, where an excessively long
DNS search domain list configured via --dhcp-search could overflow the
opts[119].s buffer.
The original root cause (slen initialised to -1 inflating the max_len
counter) was already eliminated by commit 64e69136ecbc ("dhcp: Add
option configuration tracking with enum opt_conf"). These two patches
address the remaining robustness concerns:
1/2: Change opts[].slen from int to unsigned int, now that negative
value is no longer used.
2/2: Add an explicit bounds check against sizeof(opts[119].s) before
the memcpy() in opt_set_dns_search().
Reported-by: Lakshitha Perera <eonzylakshitha@gmail.com>
*** BLURB HERE ***
Anshu Kumari (2):
dhcp: Use unsigned int for opts[].slen
dhcp: Add bounds check on DNS search domain option buffer
dhcp.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] dhcp: Use unsigned int for opts[].slen
2026-11-17 12:06 [PATCH 0/2] dhcp: Harden DNS search domain option handling Anshu Kumari
@ 2026-11-17 12:06 ` Anshu Kumari
2026-11-17 12:06 ` [PATCH 2/2] dhcp: Add bounds check on DNS search domain option buffer Anshu Kumari
2026-11-17 12:22 ` [PATCH 0/2] dhcp: Harden DNS search domain option handling Stefano Brivio
2 siblings, 0 replies; 4+ messages in thread
From: Anshu Kumari @ 2026-11-17 12:06 UTC (permalink / raw)
To: sbrivio, passt-dev, eonzylakshitha; +Cc: anskuma
Now that negative value (-1) is no longer used to do the
opts[].slen initialization (removed by commit 64e69136ecbc,
"dhcp: Add option configuration tracking with enum opt_conf"),
change slen from int to unsigned int. Hence, removed the
explicit (size_t) casts in comparisons.
Reported-by: Lakshitha Perera <eonzylakshitha@gmail.com>
Signed-off-by: Anshu Kumari <anskuma@redhat.com>
---
dhcp.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/dhcp.c b/dhcp.c
index a081e34f..de6b133b 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -70,7 +70,7 @@ enum opt_conf {
*/
struct opt {
int sent;
- int slen;
+ unsigned int slen;
int clen;
enum opt_conf conf;
uint8_t c[255];
@@ -529,13 +529,13 @@ static size_t fill_split_areas(struct msg *m, size_t opt_size, int o,
written = fill_split(m->o, opt_size, o, opt_off,
opts[o].s, opts[o].slen, dry_run);
- if (written < (size_t)opts[o].slen && !has_bootfile) {
+ if (written < opts[o].slen && !has_bootfile) {
written += fill_split(m->file, sizeof(m->file) - 1, o,
file_off,
opts[o].s + written,
opts[o].slen - written, dry_run);
}
- if (written < (size_t)opts[o].slen) {
+ if (written < opts[o].slen) {
written += fill_split(m->sname, sizeof(m->sname) - 1, o,
sname_off,
opts[o].s + written,
@@ -610,7 +610,7 @@ static int fill(struct msg *m, bool has_bootfile)
&dry_sname_off,
has_bootfile, true);
- if (total < (size_t)opts[o].slen) {
+ if (total < opts[o].slen) {
debug("DHCP: skipping option %i (no space)", o);
continue;
}
@@ -620,7 +620,7 @@ static int fill(struct msg *m, bool has_bootfile)
&offset, &file_off, &sname_off,
has_bootfile, false);
- if (written >= (size_t)opts[o].slen)
+ if (written >= opts[o].slen)
opts[o].sent = 1;
}
@@ -690,7 +690,7 @@ static int opt_dns_search_dup_ptr(unsigned char *buf, const char *cmp,
static void opt_set_dns_search(const struct ctx *c, size_t max_len)
{
char buf[NS_MAXDNAME];
- int i;
+ unsigned int i;
opts[119].slen = 0;
@@ -954,8 +954,8 @@ int dhcp(const struct ctx *c, struct iov_tail *data)
/* RFC 2132, Section 9.5: put boot file name in the 'file' header
* field. Reserve the file field from overload.
*/
- has_bootfile = opts[67].slen > 0 &&
- (size_t)opts[67].slen < sizeof(reply.file);
+ has_bootfile = opts[67].slen &&
+ opts[67].slen < sizeof(reply.file);
dlen = offsetof(struct msg, o) + fill(&reply, has_bootfile);
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] dhcp: Add bounds check on DNS search domain option buffer
2026-11-17 12:06 [PATCH 0/2] dhcp: Harden DNS search domain option handling Anshu Kumari
2026-11-17 12:06 ` [PATCH 1/2] dhcp: Use unsigned int for opts[].slen Anshu Kumari
@ 2026-11-17 12:06 ` Anshu Kumari
2026-11-17 12:22 ` [PATCH 0/2] dhcp: Harden DNS search domain option handling Stefano Brivio
2 siblings, 0 replies; 4+ messages in thread
From: Anshu Kumari @ 2026-11-17 12:06 UTC (permalink / raw)
To: sbrivio, passt-dev, eonzylakshitha; +Cc: anskuma
Add an explicit check that the encoded DNS search domain data
does not exceed the capacity of opts[119].s before each memcpy()
in opt_set_dns_search().
Reported-by: Lakshitha Perera <eonzylakshitha@gmail.com>
Signed-off-by: Anshu Kumari <anskuma@redhat.com>
---
dhcp.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/dhcp.c b/dhcp.c
index de6b133b..81833368 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -728,6 +728,9 @@ static void opt_set_dns_search(const struct ctx *c, size_t max_len)
if (n >= max_len)
break;
+ if (opts[119].slen + n > sizeof(opts[119].s))
+ break;
+
memcpy(opts[119].s + opts[119].slen, buf, n);
opts[119].slen += n;
max_len -= n;
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] dhcp: Harden DNS search domain option handling
2026-11-17 12:06 [PATCH 0/2] dhcp: Harden DNS search domain option handling Anshu Kumari
2026-11-17 12:06 ` [PATCH 1/2] dhcp: Use unsigned int for opts[].slen Anshu Kumari
2026-11-17 12:06 ` [PATCH 2/2] dhcp: Add bounds check on DNS search domain option buffer Anshu Kumari
@ 2026-11-17 12:22 ` Stefano Brivio
2 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-11-17 12:22 UTC (permalink / raw)
To: passt-dev; +Cc: Anshu Kumari, eonzylakshitha
On Tue, 17 Nov 2026 17:36:15 +0530
Anshu Kumari <anskuma@redhat.com> wrote:
> Lakshitha Perera reported a potential out-of-bounds write in
> opt_set_dns_search() at revision f8df3f1, where an excessively long
> DNS search domain list configured via --dhcp-search could overflow the
> opts[119].s buffer.
For clarity: the original report needed a patched build to actually
cause the out-of-bounds write (which was otherwise prevented), and could
only be triggered via user configuration, with a particular
(nonsensical) values for that option, resulting in a functional issue
(clean abort on those values), nothing security relevant.
--
Stefano
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-17 12:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 12:06 [PATCH 0/2] dhcp: Harden DNS search domain option handling Anshu Kumari
2026-11-17 12:06 ` [PATCH 1/2] dhcp: Use unsigned int for opts[].slen Anshu Kumari
2026-11-17 12:06 ` [PATCH 2/2] dhcp: Add bounds check on DNS search domain option buffer Anshu Kumari
2026-11-17 12:22 ` [PATCH 0/2] dhcp: Harden DNS search domain option handling Stefano Brivio
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).