Received: from list by lists.gnu.org with archive (Exim 4.71) id 1h2E2S-0005cU-Lc for mharc-grub-devel@gnu.org; Fri, 08 Mar 2019 06:51:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2E2N-0005Z2-Kc for grub-devel@gnu.org; Fri, 08 Mar 2019 06:51:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2E2K-0006Yc-8J for grub-devel@gnu.org; Fri, 08 Mar 2019 06:51:39 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53726 helo=foss.arm.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2E2J-0006B9-6s for grub-devel@gnu.org; Fri, 08 Mar 2019 06:51:36 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6232880D; Fri, 8 Mar 2019 03:51:31 -0800 (PST) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2CF123F706; Fri, 8 Mar 2019 03:51:30 -0800 (PST) Date: Fri, 8 Mar 2019 11:51:27 +0000 From: Andre Przywara To: Daniel Kiper Cc: Daniel Kiper , Vladimir Serbinenko , Andrei Borzenkov , Mark Rutland , grub-devel@gnu.org Subject: Re: [PATCH v3 03/10] net: dhcp: Allow overloading legacy bootfile and name field Message-ID: <20190308115127.0f7ccf79@donnerap.cambridge.arm.com> In-Reply-To: <20190308113418.y3d6syl6hnzyefgd@tomti.i.net-space.pl> References: <20190307151416.49014-1-andre.przywara@arm.com> <20190307151416.49014-4-andre.przywara@arm.com> <20190308113418.y3d6syl6hnzyefgd@tomti.i.net-space.pl> Organization: ARM X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.140.101.70 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Mar 2019 11:51:42 -0000 On Fri, 8 Mar 2019 12:34:18 +0100 Daniel Kiper wrote: > On Thu, Mar 07, 2019 at 03:14:09PM +0000, Andre Przywara wrote: > > From: Andrei Borzenkov > > > > DHCP specifies a special dummy option OVERLOAD, to allow DHCP options to > > spill over into the (legacy) BOOTFILE and SNAME fields. > > > > Parse and handle this option properly. > > > > Signed-off-by: Andre Przywara > > In general Reviewed-by: Daniel Kiper but one > nitpick below... > > > --- > > grub-core/net/bootp.c | 59 ++++++++++++++++++++++++++++++++++++++++++- > > include/grub/net.h | 1 + > > 2 files changed, 59 insertions(+), 1 deletion(-) > > > > diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c > > index 8d6763689..860d9c80d 100644 > > --- a/grub-core/net/bootp.c > > +++ b/grub-core/net/bootp.c > > @@ -25,11 +25,19 @@ > > #include > > #include > > > > +enum > > +{ > > + GRUB_DHCP_OPT_OVERLOAD_FILE = 1, > > + GRUB_DHCP_OPT_OVERLOAD_SNAME = 2, > > +}; > > + > > static const void * > > find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, > > grub_uint8_t opt_code, grub_uint8_t *opt_len) > > { > > const grub_uint8_t *ptr; > > + grub_uint8_t overload = 0; > > + int end = 0; > > grub_size_t i; > > > > if (opt_len) > > @@ -54,6 +62,7 @@ find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, > > size -= sizeof (*bp); > > i = sizeof (grub_uint32_t); > > > > +again: > > while (i < size) > > { > > grub_uint8_t tagtype; > > @@ -67,7 +76,10 @@ find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, > > > > /* End tag. */ > > if (tagtype == GRUB_NET_BOOTP_END) > > - break; > > + { > > + end = 1; > > + break; > > + } > > > > if (i >= size) > > return NULL; > > @@ -84,9 +96,54 @@ find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, > > return &ptr[i]; > > } > > > > + if (tagtype == GRUB_NET_DHCP_OVERLOAD && taglength == 1) > > + overload = ptr[i]; > > + > > i += taglength; > > } > > > > + if (!end) > > + return NULL; > > + > > + /* RFC2131, 4.1, 23ff: > > + * If the options in a DHCP message extend into the 'sname' and 'file' > > + * fields, the 'option overload' option MUST appear in the 'options' > > + * field, with value 1, 2 or 3, as specified in RFC 1533. If the > > + * 'option overload' option is present in the 'options' field, the > > + * options in the 'options' field MUST be terminated by an 'end' option, > > + * and MAY contain one or more 'pad' options to fill the options field. > > + * The options in the 'sname' and 'file' fields (if in use as indicated > > + * by the 'options overload' option) MUST begin with the first octet of > > + * the field, MUST be terminated by an 'end' option, and MUST be > > + * followed by 'pad' options to fill the remainder of the field. Any > > + * individual option in the 'options', 'sname' and 'file' fields MUST be > > + * entirely contained in that field. The options in the 'options' field > > + * MUST be interpreted first, so that any 'option overload' options may > > + * be interpreted. The 'file' field MUST be interpreted next (if the > > + * 'option overload' option indicates that the 'file' field contains > > + * DHCP options), followed by the 'sname' field. > > + * > > + * FIXME: We do not explicitly check for trailing 'pad' options here. > > + */ > > + end = 0; > > It seems to me that this line is not needed... I can drop it before > committing the patch if you are OK with it. I was eyeballing this line as well, but I think it *is* needed: It resets end to 0, before possibly jumping back to the again label, inside the if conditions below. Does that make sense? Cheers, Andre. > > > + if (overload & GRUB_DHCP_OPT_OVERLOAD_FILE) > > + { > > + overload &= ~GRUB_DHCP_OPT_OVERLOAD_FILE; > > + ptr = (grub_uint8_t *) &bp->boot_file[0]; > > + size = sizeof (bp->boot_file); > > + i = 0; > > + goto again; > > + } > > + > > + if (overload & GRUB_DHCP_OPT_OVERLOAD_SNAME) > > + { > > + overload &= ~GRUB_DHCP_OPT_OVERLOAD_SNAME; > > + ptr = (grub_uint8_t *) &bp->server_name[0]; > > + size = sizeof (bp->server_name); > > + i = 0; > > + goto again; > > + } > > + > > return NULL; > > } > > Daniel