|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 4/4] automation/eclair: deviate MISRA C Rule 11.8 for xfree() and vfree()
On Tue, 17 Nov 2026, Andrew Cooper wrote: > On 17/11/2026 8:01 pm, Dmytro Prokopchuk wrote: > > > > > > On 11/4/26 13:24, Andrew Cooper wrote: > >> On 03/11/2026 10:29 am, Dmytro Prokopchuk1 wrote: > >>> Livepatch passes const-qualified pointers from struct payload to > >>> xfree() > >>> and vfree(), which take a 'void *' argument. The cast that removes the > >>> const qualifier is a violation of MISRA C Rule 11.8. > >>> > >>> Such casts are safe. The deallocation functions neither read nor write > >>> the content of the object being freed, and the object is not accessed > >>> after it has been freed. > >> > >> I have a very firm objection to this. > >> > >> It is impossible for any allocation from malloc()/calloc()/etc to point > >> to read-only memory, which is why free() takes a mutable pointer, not a > >> const pointer. The same is true of any other heap implementation. > >> > >> It is impossible to make an object in read-only memory undefined. > >> Objects in read-only memory by definition have a global lifetime, and it > >> is absurd to argue that a specific heap implementation ought to permit > >> making such objects undefined. > >> > >> > >> The bug here is livepatch storing a heap allocation in a const pointer. > >> > >> This comes from deeper problem where some contributors/reviewers want > >> the const keyword to mean something it doesn't. > >> > >> ~Andrew > > > > Jan, Andrew, > > > > thanks for the review. Given the disagreement, I will drop this > > deviation for now. > > > > If the preferred fix is to stop storing heap allocations in > > const-qualified members of 'struct payload' (so the casts go away), I > > can prepare a follow-up patch. Please confirm that is the direction > > you want for livepatch. > > Please remove the const qualification in struct payload. The logic > should not have been accepted in that state to begin with. > > This is the only course of action here which does not create a class of > undefined behaviour, or permit said undefined behaviour to go unnoticed. I agree with Andrew. xfree() does write into the freed block, so a const parameter would be misleading. The real issue is livepatch keeping owned heap allocations in const pointers. text_addr, symtab and strtab all come from non-const allocations, so dropping const from those three fields of struct payload removes all six casts, with no deviation needed. If the issue were more widespread I would also consider a deviation but with wording like: Casting away the const qualifier from the argument of the memory deallocation functions xfree() and vfree() is safe. The pointer always refers to memory obtained from the corresponding allocator, which is never an object defined as const, and the object's lifetime ends with the call, so no access through a const-qualified lvalue can follow.
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |