* [PATCH] dhcp: Add option code byte in calculation for OPT_MAX boundary check
@ 2025-02-18 8:52 Stefano Brivio
2025-02-18 23:20 ` David Gibson
0 siblings, 1 reply; 3+ messages in thread
From: Stefano Brivio @ 2025-02-18 8:52 UTC (permalink / raw)
To: passt-dev; +Cc: Enrique Llorente
Otherwise we'll limit messages to 577 bytes, instead of 576 bytes as
intended:
$ fqdn="thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.then_make_it_251_with_this"
$ hostname="__eighteen_bytes__"
$ ./pasta --fqdn ${fqdn} -H ${hostname} -p dhcp.pcap -- /sbin/dhclient -4
Saving packet capture to dhcp.pcap
$ tshark -r dhcp.pcap -V -Y 'dhcp.option.value == 5' | grep "Total Length"
Total Length: 577
This was hidden by the issue fixed by commit bcc4908c2b4a ("dhcp
Remove option 255 length byte") until now.
Fixes: 31e8109a86ee ("dhcp, dhcpv6: Add hostname and client fqdn ops")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
dhcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dhcp.c b/dhcp.c
index 4a209f1..b7d5ea3 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -143,7 +143,7 @@ static bool fill_one(struct msg *m, int o, int *offset)
size_t slen = opts[o].slen;
/* If we don't have space to write the option, then just skip */
- if (*offset + 1 /* length of option */ + slen > OPT_MAX)
+ if (*offset + 2 /* code and length of option */ + slen > OPT_MAX)
return true;
m->o[*offset] = o;
--
@@ -143,7 +143,7 @@ static bool fill_one(struct msg *m, int o, int *offset)
size_t slen = opts[o].slen;
/* If we don't have space to write the option, then just skip */
- if (*offset + 1 /* length of option */ + slen > OPT_MAX)
+ if (*offset + 2 /* code and length of option */ + slen > OPT_MAX)
return true;
m->o[*offset] = o;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] dhcp: Add option code byte in calculation for OPT_MAX boundary check
2025-02-18 8:52 [PATCH] dhcp: Add option code byte in calculation for OPT_MAX boundary check Stefano Brivio
@ 2025-02-18 23:20 ` David Gibson
2025-02-19 7:37 ` Enrique Llorente Pastora
0 siblings, 1 reply; 3+ messages in thread
From: David Gibson @ 2025-02-18 23:20 UTC (permalink / raw)
To: Stefano Brivio; +Cc: passt-dev, Enrique Llorente
[-- Attachment #1: Type: text/plain, Size: 1735 bytes --]
On Tue, Feb 18, 2025 at 09:52:31AM +0100, Stefano Brivio wrote:
> Otherwise we'll limit messages to 577 bytes, instead of 576 bytes as
> intended:
>
> $ fqdn="thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.then_make_it_251_with_this"
> $ hostname="__eighteen_bytes__"
> $ ./pasta --fqdn ${fqdn} -H ${hostname} -p dhcp.pcap -- /sbin/dhclient -4
> Saving packet capture to dhcp.pcap
> $ tshark -r dhcp.pcap -V -Y 'dhcp.option.value == 5' | grep "Total Length"
> Total Length: 577
>
> This was hidden by the issue fixed by commit bcc4908c2b4a ("dhcp
> Remove option 255 length byte") until now.
>
> Fixes: 31e8109a86ee ("dhcp, dhcpv6: Add hostname and client fqdn ops")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> dhcp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/dhcp.c b/dhcp.c
> index 4a209f1..b7d5ea3 100644
> --- a/dhcp.c
> +++ b/dhcp.c
> @@ -143,7 +143,7 @@ static bool fill_one(struct msg *m, int o, int *offset)
> size_t slen = opts[o].slen;
>
> /* If we don't have space to write the option, then just skip */
> - if (*offset + 1 /* length of option */ + slen > OPT_MAX)
> + if (*offset + 2 /* code and length of option */ + slen > OPT_MAX)
> return true;
>
> m->o[*offset] = o;
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dhcp: Add option code byte in calculation for OPT_MAX boundary check
2025-02-18 23:20 ` David Gibson
@ 2025-02-19 7:37 ` Enrique Llorente Pastora
0 siblings, 0 replies; 3+ messages in thread
From: Enrique Llorente Pastora @ 2025-02-19 7:37 UTC (permalink / raw)
To: David Gibson; +Cc: Stefano Brivio, passt-dev
On Wed, Feb 19, 2025 at 12:21 AM David Gibson
<david@gibson.dropbear.id.au> wrote:
>
> On Tue, Feb 18, 2025 at 09:52:31AM +0100, Stefano Brivio wrote:
> > Otherwise we'll limit messages to 577 bytes, instead of 576 bytes as
> > intended:
> >
> > $ fqdn="thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.then_make_it_251_with_this"
> > $ hostname="__eighteen_bytes__"
> > $ ./pasta --fqdn ${fqdn} -H ${hostname} -p dhcp.pcap -- /sbin/dhclient -4
> > Saving packet capture to dhcp.pcap
> > $ tshark -r dhcp.pcap -V -Y 'dhcp.option.value == 5' | grep "Total Length"
> > Total Length: 577
> >
> > This was hidden by the issue fixed by commit bcc4908c2b4a ("dhcp
> > Remove option 255 length byte") until now.
> >
> > Fixes: 31e8109a86ee ("dhcp, dhcpv6: Add hostname and client fqdn ops")
> > Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
>
> > ---
> > dhcp.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/dhcp.c b/dhcp.c
> > index 4a209f1..b7d5ea3 100644
> > --- a/dhcp.c
> > +++ b/dhcp.c
> > @@ -143,7 +143,7 @@ static bool fill_one(struct msg *m, int o, int *offset)
> > size_t slen = opts[o].slen;
> >
> > /* If we don't have space to write the option, then just skip */
> > - if (*offset + 1 /* length of option */ + slen > OPT_MAX)
> > + if (*offset + 2 /* code and length of option */ + slen > OPT_MAX)
> > return true;
> >
> > m->o[*offset] = o;
>
> --
> David Gibson (he or they) | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
> | around.
> http://www.ozlabs.org/~dgibson
I see "+ 2" better since it is explicit than the alternative of ">=
OPT_MAX", so LGTM.
Reviewed-by: Enrique Llorente <ellorent@redhat.com>
--
Quique Llorente
CNV networking Senior Software Engineer
Red Hat EMEA
ellorent@redhat.com
@RedHat Red Hat Red Hat
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-19 7:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-18 8:52 [PATCH] dhcp: Add option code byte in calculation for OPT_MAX boundary check Stefano Brivio
2025-02-18 23:20 ` David Gibson
2025-02-19 7:37 ` Enrique Llorente Pastora
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).