From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 05B061FF0A7 for ; Wed, 02 Sep 2026 18:14:55 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 78E8F21567; Wed, 02 Sep 2026 18:14:54 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH proxmox v2 02/10] proxmox-alloc: document undefined behavior regarding custom allocs From: Robert Obkircher To: "Max R. Carrara" In-Reply-To: <20260821140238.615302-3-m.carrara@proxmox.com> References: <20260821140238.615302-1-m.carrara@proxmox.com> <20260821140238.615302-3-m.carrara@proxmox.com> Date: Wed, 02 Sep 2026 18:14:36 +0200 Message-Id: <178836567690.287871.10965145059423868295.b4-review@b4> X-Mailer: b4 0.16-dev X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788365681794 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.644 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: P5PVSJSF7DNZOLTQJ6ZPJLGLDNS4AC4S X-Message-ID-Hash: P5PVSJSF7DNZOLTQJ6ZPJLGLDNS4AC4S X-MailFrom: r.obkircher@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pbs-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: > Add a new example at examples/ub.rs with tests that demonstrate > incorrect usage & undefined behavior of custom allocations. I don't think that it is a good idea to include a runnable example, because it can theoretically format your hard drive, and it will likely result in false positives from vulnerability scanners. These examples also conflate allocation of DSTs and over-alignment to a runtime value, which are completely separate concepts that can be understood separately. > > Add a hint in the `aware_boxed` module's docs that such an example > exists in the crate. > > Signed-off-by: Max R. Carrara > > diff --git a/proxmox-alloc/Cargo.toml b/proxmox-alloc/Cargo.toml > index 4eeeb787..b16496f6 100644 > --- a/proxmox-alloc/Cargo.toml > +++ b/proxmox-alloc/Cargo.toml > @@ -11,6 +11,10 @@ repository.workspace = true > license.workspace = true > exclude.workspace = true > > +[[example]] > +crate-type = ["staticlib"] > +name = "ub" > + > [dependencies] > > [dev-dependencies] > diff --git a/proxmox-alloc/examples/ub.rs b/proxmox-alloc/examples/ub.rs > new file mode 100644 > index 00000000..aa97b02b > --- /dev/null > +++ b/proxmox-alloc/examples/ub.rs > @@ -0,0 +1,99 @@ > +//! This example contains various tests that demonstrate [undefined behavior]. > +//! Needless to say, you should not use what's shown here in your own code. > +//! > +//! You can run this example's tests using the following command: > +//! > +//! ```text > +//! cargo test --package proxmox-alloc --example ub > +//! ``` > +//! > +//! Alternatively, if you want to see what kinds of [undefined behavior] get > +//! caught by [Miri], use the following instead: > +//! > +//! ```text > +//! cargo +nightly miri nextest run --package proxmox-alloc --example ub > +//! ``` > +//! > +//! Note that this requires [`cargo nextest`][nextest] to be installed on your > +//! nightly toolchain. This will guarantee that all tests are run, even if they > +//! fail (which they do when you use Miri). > +//! > +//! [Miri]: https://github.com/rust-lang/miri > +//! [nextest]: https://nexte.st/ > +//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html > + > +#[cfg(test)] This could be `#[cfg(all(test, miri))]`, but even then I don't think miri supports something like #[should_panic] but for expected UB. -- Robert Obkircher