From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WsOvzIhG; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id B551C5A0274 for ; Mon, 03 Feb 2025 20:01:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738609261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WY6azbGhvrLV4KLKtaVBUpDaIHpZJGpoy5q60Gqm7rU=; b=WsOvzIhG17BGKQZc0eZarFA5fUDcuZ6pwiwlJHRck8mhAWnwRP5JOuoKV60VKq4P35/GKP aFmDoxnrKuguHjh5ZBLabolzZRKFn1c8wY1IG8Kp7cq2J7we6OZna5B++4DnKjbsrAC2ip nGzIlnNDk0tpIdPdOBEjyYQn5mk5Oi0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-275-jPsrbdVHMPWLEBdGCTaecw-1; Mon, 03 Feb 2025 14:00:57 -0500 X-MC-Unique: jPsrbdVHMPWLEBdGCTaecw-1 X-Mimecast-MFC-AGG-ID: jPsrbdVHMPWLEBdGCTaecw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so38235435e9.3 for ; Mon, 03 Feb 2025 11:00:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738609256; x=1739214056; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XP3sxDd5cggWv375RSF1/KCLqjvvRrJJZrEg9dvx2kk=; b=LbTh9cg721N8CE+Ztaot8tZ9oHvyj54qf/lz1DTcf5VXhYkMdMelCpU4IbahmhCjeI vZeQuLS79JDEYGiH6WVzK2vtfpJ2qCslY4vA8hWRt7XdQA7WSXpka7RboAvIV8DKU8V/ BKzzi9NLukcBe4OyR/MvQzmKIdNrvwdC9YDN95sBibPHDDvcLpajsVFOtprEYb0eB14l RuiCoo8+QmFbcKpI2Yyig976wo44zw5VxmTsvy03XJYPzSXDVNu7RO9WeA8BoLezeY8x JQ+DJgFdc70wMpjWaHb59sLk9RWlOe6OlE1Bj55+BWuPyk0nITLoOobKAsHrVmyo1qCo skrg== X-Gm-Message-State: AOJu0YxpNJi+8YX20Pomua5X1Y5LbDPsfRljhSWh6cMJMlHw6+brHVtF WDx2AGasJWceuoravkyrgQOo/N2nDrim2a/axCwyu/m2bg2yoQDtQo+dEduCP51RZJf7cJ1Dt6J m941JGgiuwyR0gSEEK52txYYE6jNbJzReWNhE0sDjfuySRzTdJfCIpMjdnmbMk6iciSxy9FCj43 mtcz2zeUxo1DpIM1XaXF7IQWVJuEd9BGcU X-Gm-Gg: ASbGncvfd7+WSg1VlWmISwHzy4TdlsfHdQS0KOkrXoEYj2EwKwv1/4PwODgZdVItR43 h7Z88SCYzSBafFPyallN0Zp6gKD2Pl7XQk+NXabdcCXvMt6ZWjjVhztqks3mFma2N8uY39pzKBR SsbpaoOoPE/gssGINI3N0+gtjkznvsIAjCPrUH6RSDxBnYUX3euD4ot9ukGVEb4NI6h1S526qiq qd1wB9/kYzfogOAYVj7H8OT3Q0cb9DHYhFtOQ+HdKpYV+nuR1xbbc4/HyzcN8AMrHvOC98UQiCp AebjLeKtVrRyTMLf X-Received: by 2002:a05:600c:5119:b0:438:a432:7c44 with SMTP id 5b1f17b1804b1-438dc40b281mr180272635e9.21.1738609255815; Mon, 03 Feb 2025 11:00:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2Av6T0CmvTVw+ekblVuVTX88hGj8oMzCXFtFE0oZdIyF95xdY/3WW43gseZa0Z6qApZaREg== X-Received: by 2002:a05:600c:5119:b0:438:a432:7c44 with SMTP id 5b1f17b1804b1-438dc40b281mr180272195e9.21.1738609255372; Mon, 03 Feb 2025 11:00:55 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438dcc6e00esm204817675e9.28.2025.02.03.11.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 11:00:54 -0800 (PST) Date: Mon, 3 Feb 2025 20:00:52 +0100 From: Stefano Brivio To: Enrique Llorente Pastora Subject: Re: [PATCH] dhcp: Don't re-use request message for reply Message-ID: <20250203200052.7ed1968f@elisabeth> In-Reply-To: References: <20250131145329.1835558-1-ellorent@redhat.com> <20250201141330.59af1324@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: WcKzYKK6oPVRVgsxpIKS9V7WPGNpE1n3QcTNIRojwSc_1738609256 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: COEC2L6724IQQGLKF37IAO4H5NSEYK3E X-Message-ID-Hash: COEC2L6724IQQGLKF37IAO4H5NSEYK3E X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Sorry for the delay: On Mon, 3 Feb 2025 11:26:42 +0100 Enrique Llorente Pastora wrote: > On Sat, Feb 1, 2025 at 2:13=E2=80=AFPM Stefano Brivio wrote: > > > > On Fri, 31 Jan 2025 15:53:29 +0100 > > Enrique Llorente wrote: > > =20 > > > The logic composing the DHCP reply message is reusing the request > > > message to compose the it, this kind be problematic from a security = =20 > > > > Does "be problematic" imply "would be ... once we add longer options"? > > =20 > > > context and may break the functionality. =20 > > > > Which one? This is important to know for distribution maintainers and, > > ultimately, users. > > > > As far as I know it's all fine until now, the problem would arise in > > your next patch, so perhaps state that. > > > > The real reason why we need this is that we want to have a given, fixed > > size for the option field (308) so that we can easily check we don't > > exceed it once we start writing the FQDN in it. > > =20 > > > This change create a new reply message and fill it in with proper fie= lds > > > from request adding on top the generated opetions. =20 > > > > s/opetions/options/ > > =20 > > > > > > Signed-off-by: Enrique Llorente > > > --- > > > dhcp.c | 55 ++++++++++++++++++++++++++++++++++++++----------------- > > > 1 file changed, 38 insertions(+), 17 deletions(-) > > > > > > diff --git a/dhcp.c b/dhcp.c > > > index d8515aa..d8ff330 100644 > > > --- a/dhcp.c > > > +++ b/dhcp.c > > > @@ -142,17 +142,36 @@ static void fill_one(struct msg *m, int o, int = *offset) > > > } > > > > > > /** > > > - * fill() - Fill options in message > > > - * @m: Message to fill > > > + * fill() - Fill fields and options in response message =20 > > > > On one hand, this fits with a function that's called "fill()". On the > > other hand, I would have a slight preference to keep this in dhcp() > > because dhcp() is a comprehensive summary (albeit a bit long) of what > > we're doing. > > > > Is there a particular reason why you moved non-option field assignments > > to here? =20 >=20 > The original fill() function do set some non options fields >=20 > m->op =3D BOOTREPLY; > m->secs =3D 0; >=20 > That was my motivation to add the rest of them. Hah, funny. Sorry for that, I had no idea. It was actually not intended on my side. > What do you think about doing the opposite and moving op and secs out > of fill next to the rest of options ? Yes, definitely, it makes sense and fits the original intention behind fill(). > The place would be just after parsing request with "packet_get(p, 0, > offset, offsetof(struct msg, o), &opt_len);" >=20 > Something like: >=20 > m =3D packet_get(p, 0, offset, offsetof(struct msg, o), &opt_le= n); > if (!m || > mlen !=3D ntohs(uh->len) - sizeof(*uh) || > mlen < offsetof(struct msg, o) || > m->op !=3D BOOTREQUEST) > return -1; >=20 > reply.op =3D BOOTREPLY; > reply.htype =3D m->htype; > reply.hlen =3D m->hlen; > reply.hops =3D 0; > reply.xid =3D m->xid; > reply.secs =3D 0; > reply.flags =3D m->flags; > reply.ciaddr =3D m->ciaddr; > reply.yiaddr =3D c->ip4.addr; > reply.siaddr =3D 0; > reply.giaddr =3D m->giaddr; > memcpy(&reply.chaddr, m->chaddr, sizeof(reply.chaddr)); > memset(&reply.sname, 0, sizeof(reply.sname)); > memset(&reply.file, 0, sizeof(reply.file)); > reply.magic =3D m->magic; Looks good to me. Maybe use tabs: =09reply.op=09=3D BOOTREPLY; and this would look even more readable (to me at least, with spaces too, if it doesn't offend anybody): =09... =09reply.siaddr=09=09=3D 0; =09reply.giaddr=09=09=3D m->giaddr; =09memcpy(&reply.chaddr,=09 m->chaddr,=09sizeof(reply.chaddr)); =09memset(&reply.sname,=09 0,=09=09sizeof(reply.sname)); =09memset(&reply.file,=09 0,=09=09sizeof(reply.file)); =09reply.magic=09=09=3D m->magic; ...which is the reason why we don't have/want an automatic formatter. :) --=20 Stefano