From nobody Sun Dec 26 19:27:57 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C8CAF19195C8; Sun, 26 Dec 2021 19:27:58 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (glebi.us [162.251.186.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JMW6Q3w2wz3qCv; Sun, 26 Dec 2021 19:27:58 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.16.1/8.16.1) with ESMTPS id 1BQJRvX8002301 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 26 Dec 2021 11:27:57 -0800 (PST) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.glebi.us (8.16.1/8.16.1/Submit) id 1BQJRvOA002300; Sun, 26 Dec 2021 11:27:57 -0800 (PST) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@freebsd.org using -f Date: Sun, 26 Dec 2021 11:27:57 -0800 From: Gleb Smirnoff To: Jessica Clarke Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Subject: Re: git: eb8dcdeac22d - main - jail: network epoch protection for IP address lists Message-ID: References: <202112261846.1BQIkYd8075256@gitrepo.freebsd.org> <04FFE80E-388E-4028-A6D8-FE6F725C1B5B@freebsd.org> <7905A4B0-3308-41E9-BA29-73006E55ED53@freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7905A4B0-3308-41E9-BA29-73006E55ED53@freebsd.org> X-Rspamd-Queue-Id: 4JMW6Q3w2wz3qCv X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Sun, Dec 26, 2021 at 07:15:58PM +0000, Jessica Clarke wrote: J> > On Sun, Dec 26, 2021 at 07:07:06PM +0000, Jessica Clarke wrote: J> > J> > +struct prison_ip { J> > J> > + struct epoch_context ctx; J> > J> > + uint32_t ips; J> > J> > +#ifdef FUTURE_C J> > J> > + union { J> > J> > + struct in_addr pr_ip4[]; J> > J> > + struct in6_addr pr_ip6[]; J> > J> > + }; J> > J> > +#else /* No future C :( */ J> > J> > +#define PR_IP(pip, i) ((const char *)((pip) + 1) + pr_families[af].size * (i)) J> > J> > +#define PR_IPD(pip, i) ((char *)((pip) + 1) + pr_families[af].size * (i)) J> > J> > +#endif J> > J> > +}; J> > J> J> > J> You can make this work with a prison_ip base and prison_ipv[46] derived J> > J> structs. J> > J> J> > J> As it stands this is quite gross, you’re assuming things about J> > J> alignment, and don’t even have a flexible char[] at the end to J> > J> represent the extra data. J> > J> > Will adding char [] to the end be sufficient to guarantee proper alignment? J> J> No. J> J> > Using prison_ipv[46] derived structs won't work as most functions are now J> > made protocol independent. J> J> Why not? Just cast from prison_ip * to prison_ipv4 * when known/needed? What about this? diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index f1c81d8813bd..ee8bfadb4a3c 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -572,11 +572,15 @@ struct prison_ip { struct in_addr pr_ip4[]; struct in6_addr pr_ip6[]; }; +}; #else /* No future C :( */ + struct in_addr pr_ip4[]; #define PR_IP(pip, i) ((const char *)((pip) + 1) + pr_families[af].size * (i)) #define PR_IPD(pip, i) ((char *)((pip) + 1) + pr_families[af].size * (i)) -#endif }; +_Static_assert(__alignof(struct in_addr) == __alignof(struct in6_addr), + "AF_INET and AF_INET6 address alignment shall be the same"); +#endif -- Gleb Smirnoff