all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH proxmox-backup 0/2] Fix Undefined Behavior in Tape Block Header Deallocation
@ 2026-08-05 14:16 Max R. Carrara
  2026-08-05 14:16 ` [PATCH proxmox-backup 1/2] pbs-tape: fix undefined behavior in block header deallocation Max R. Carrara
  2026-08-05 14:16 ` [PATCH proxmox-backup 2/2] pbs-tape: rename `buffer` to `header` Max R. Carrara
  0 siblings, 2 replies; 4+ messages in thread
From: Max R. Carrara @ 2026-08-05 14:16 UTC (permalink / raw)
  To: pbs-devel

Fix Undefined Behavior in Tape Block Header Deallocation - v1
=============================================================

We allocate `BlockHeader` in `pbs-tape` with an alignment equal
to the page size, but because it uses packed / 1-byte alignment
(`#[repr(C, packed)]` to be precise), the compiler will treat it as if
it was allocated with 1-byte alignment.

Miri [0] will flag this as undefined behavior:

    error: Undefined Behavior: incorrect layout on deallocation:
    alloc46398 has size 262144 and alignment 4096, but gave size 262144
    and alignment 1

This is because Rust cares about a memory region's alignment on
deallocation, even if the underlying allocator does not -- hence why
this hasn't actually been a problem for us. Still, there is no guarantee
that this will not change at some point in the future.

This is fixed in patch #1. Patch #2 just renames variables to fit the
new implementation better, which I didn't want to include in patch #1,
as it didn't really fit (and it would make the diff ugly). If you feel
like patch #2 is superfluous, feel free to drop it.

Special thanks to @Robert, who brought this to my attention and totally
managed to nerd-snipe me with this. I have added a respective git
trailer in patch #1.

Testing
-------

Would be great if somebody with a working tape storage could give this a
spin -- miri does not report any UB anymore and the tests we have pass,
but some smoke-testing would nevertheless be appreciated. My virtual
tape library has unfortunately borked itself, and I haven't come around
to un-borking it yet.

[0]: https://github.com/rust-lang/miri

Summary of Changes
------------------


proxmox-backup:

Max R. Carrara (2):
  pbs-tape: fix undefined behavior in block header deallocation
  pbs-tape: rename `buffer` to `header`

 pbs-tape/src/blocked_reader.rs |  58 +++---
 pbs-tape/src/blocked_writer.rs |  47 ++---
 pbs-tape/src/lib.rs            | 352 +++++++++++++++++++++++++++------
 3 files changed, 346 insertions(+), 111 deletions(-)


Summary over all repositories:
  3 files changed, 346 insertions(+), 111 deletions(-)

--
Generated by murpp 0.12.0




^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH proxmox-backup 0/2] Fix Undefined Behavior in Tape Block Header Deallocation
@ 2026-08-05 14:13 Max R. Carrara
  2026-08-05 14:13 ` [PATCH proxmox-backup 2/2] pbs-tape: rename `buffer` to `header` Max R. Carrara
  0 siblings, 1 reply; 4+ messages in thread
From: Max R. Carrara @ 2026-08-05 14:13 UTC (permalink / raw)
  To: pve-devel

Fix Undefined Behavior in Tape Block Header Deallocation - v1
=============================================================

We allocate `BlockHeader` in `pbs-tape` with an alignment equal
to the page size, but because it uses packed / 1-byte alignment
(`#[repr(C, packed)]` to be precise), the compiler will treat it as if
it was allocated with 1-byte alignment.

Miri [0] will flag this as undefined behavior:

    error: Undefined Behavior: incorrect layout on deallocation:
    alloc46398 has size 262144 and alignment 4096, but gave size 262144
    and alignment 1

This is because Rust cares about a memory region's alignment on
deallocation, even if the underlying allocator does not -- hence why
this hasn't actually been a problem for us. Still, there is no guarantee
that this will not change at some point in the future.

This is fixed in patch #1. Patch #2 just renames variables to fit the
new implementation better, which I didn't want to include in patch #1,
as it didn't really fit (and it would make the diff ugly). If you feel
like patch #2 is superfluous, feel free to drop it.

Special thanks to @Robert, who brought this to my attention and totally
managed to nerd-snipe me with this. I have added a respective git
trailer in patch #1.

Testing
-------

Would be great if somebody with a working tape storage could give this a
spin -- miri does not report any UB anymore and the tests we have pass,
but some smoke-testing would nevertheless be appreciated. My virtual
tape library has unfortunately borked itself, and I haven't come around
to un-borking it yet.

[0]: https://github.com/rust-lang/miri

Summary of Changes
------------------


proxmox-backup:

Max R. Carrara (2):
  pbs-tape: fix undefined behavior in block header deallocation
  pbs-tape: rename `buffer` to `header`

 pbs-tape/src/blocked_reader.rs |  58 +++---
 pbs-tape/src/blocked_writer.rs |  47 ++---
 pbs-tape/src/lib.rs            | 352 +++++++++++++++++++++++++++------
 3 files changed, 346 insertions(+), 111 deletions(-)


Summary over all repositories:
  3 files changed, 346 insertions(+), 111 deletions(-)

--
Generated by murpp 0.12.0




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-05 14:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 14:16 [PATCH proxmox-backup 0/2] Fix Undefined Behavior in Tape Block Header Deallocation Max R. Carrara
2026-08-05 14:16 ` [PATCH proxmox-backup 1/2] pbs-tape: fix undefined behavior in block header deallocation Max R. Carrara
2026-08-05 14:16 ` [PATCH proxmox-backup 2/2] pbs-tape: rename `buffer` to `header` Max R. Carrara
  -- strict thread matches above, loose matches on Subject: below --
2026-08-05 14:13 [PATCH proxmox-backup 0/2] Fix Undefined Behavior in Tape Block Header Deallocation Max R. Carrara
2026-08-05 14:13 ` [PATCH proxmox-backup 2/2] pbs-tape: rename `buffer` to `header` Max R. Carrara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal