all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Robert Obkircher <r.obkircher@proxmox.com>
To: "Max R. Carrara" <m.carrara@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-backup 1/2] pbs-tape: fix undefined behavior in block header deallocation
Date: Mon, 10 Aug 2026 14:39:01 +0200	[thread overview]
Message-ID: <36e1aa51-9a25-4b49-a6d1-5675286117d9@proxmox.com> (raw)
In-Reply-To: <DKL666JH49B7.GSJ3FU7IPGL2@proxmox.com>


On 10.08.26 11:51, Max R. Carrara wrote:
> [..]
>
> Could you perhaps show what would make it easier to reason about for you
> instead? Maybe I'm just missing something here.
The indirection just makes it easier to overlook things.

For example, if someone increased the size of PayloadType it is now
very easy to overlook that it could result in an allocation that is
bigger that size_of_val(t).

Not an actual problem, though.

>>>>> +
>>>>> [..]
>>>>>
>>>>> +// Putting underlying implementation in here to prevent access to private fields
>>>>>
>>>> This seems like a confusing, unrelated change with no benefit.
>>> The main benefit here is that private fields cannot be accessed anymore.
>> I'm not fully convinced that the definition of an extern format needs
>> to be hidden from someone willing to work at that level.
> What do you mean with hidden? All fields are still accessible through
> their respective methods, it's just that *directly* modifying those
> fields is not as easy as before anymore. There wasn't any point in
> exposing the fields as `pub` in the first place IMO, and I also think
> that doing that encourages bad patterns ...
TLDR, since we already discussed this offline:

I think fields are slightly better for this specific case because it's
plain old data and you can mutably borrow more than one at a time. Not
that important, though.
>
> For example, in both the [reader] and [writer] implementations we are
> casting the entire struct to a byte slice directly, even though that
> could've been a method each instead, keeping the implementation of such
> an operation local to the struct. That's why I introduced `as_bytes()`
> and `as_bytes_mut()`, which do exactly that.

Those two are great! By accessors I meant getters and setters.

We should seriously consider making zerocopy an explicit dependency.
It is already used by rand and hashbrown and it could handle this
exact case [1] and the byte-order aware U24 length field [2] without
any unsafe code on our part. I was already considering it for the
index readers and Fabian said he wouldn't mind if we could eventually
get rid of endian_trait(_derive) that way.

[1] https://docs.rs/zerocopy/latest/zerocopy/byteorder/index.html#example

[2] https://docs.rs/u24/latest/u24/unaligned/index.html

> [..]
>
>> There is a [2]nd one that I had posted on Zulip, and the third could
>> be a unit test that checks an Rc count.
>>
>> I just prefer mechanical changes like moving code to be in separate
>> commits.
>>
>> [2]
>> https://git.proxmox.com/?p=proxmox-backup.git;a=blob;f=pbs-tape/src/sgutils2.rs;h=340616c73675b994c8761a6981fd41e2e249f953;hb=HEAD#l447
> Hmm, fair point! I'll see if I can fix the second instance in v2 too,
> then.
>
> Which third one are you referring to exactly?
I just meant a unit test that can be run without
Zmiri-disable-isolation to verify that drop is invoked.
> [..]




  reply	other threads:[~2026-08-10 12:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-06 10:57   ` Robert Obkircher
2026-08-07 12:47     ` Max R. Carrara
2026-08-10  8:34       ` Robert Obkircher
2026-08-10  9:51         ` Max R. Carrara
2026-08-10 12:39           ` Robert Obkircher [this message]
2026-08-05 14:16 ` [PATCH proxmox-backup 2/2] pbs-tape: rename `buffer` to `header` Max R. Carrara
2026-08-06 10:57   ` Robert Obkircher
2026-08-07 12:52     ` 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 1/2] pbs-tape: fix undefined behavior in block header deallocation Max R. Carrara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=36e1aa51-9a25-4b49-a6d1-5675286117d9@proxmox.com \
    --to=r.obkircher@proxmox.com \
    --cc=m.carrara@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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