* Re: [GIT PULL] Enable -Wstringop-overflow globally
[not found] ` <f00e15fcba05497a87e91182a33c888f@AcuMS.aculab.com>
@ 2024-01-27 19:53 ` Gustavo A. R. Silva
2024-01-30 14:52 ` Thomas Hellström
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2024-01-27 19:53 UTC (permalink / raw)
To: David Laight, 'Linus Torvalds', Kees Cook,
Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: linux-kernel@vger.kernel.org, intel-xe, Gustavo A. R. Silva,
dri-devel@lists.freedesktop.org, linux-hardening@vger.kernel.org
On 1/27/24 09:11, David Laight wrote:
> From: Linus Torvalds
>> Sent: 26 January 2024 22:36
>>
>> On Fri, 26 Jan 2024 at 14:24, Kees Cook <keescook@chromium.org> wrote:
>>>
>>> I think xe has some other weird problems too. This may be related (under
>>> allocating):
>>>
>>> ../drivers/gpu/drm/xe/xe_vm.c: In function 'xe_vma_create':
>>> ../drivers/gpu/drm/xe/xe_vm.c:806:21: warning: allocation of insufficient size '224' for type
>> 'struct xe_vma' with size '368' [-Walloc-size]
>>> 806 | vma = kzalloc(sizeof(*vma) - sizeof(struct xe_userptr),
>>> | ^
>>
>> That code is indeed odd, but there's a comment in the xe_vma definition
>>
>> /**
>> * @userptr: user pointer state, only allocated for VMAs that are
>> * user pointers
>> */
>> struct xe_userptr userptr;
>>
>> although I agree that it should probably simply be made a final
>> variably-sized array instead (and then you make that array size be
>> 0/1).
>
> That entire code is odd.
> It isn't obvious that the flag values that cause the short allocate
> are the same ones that control whether the extra data is accessed.
>
> Never mind the oddities with the 'flags |= ' assignments int the
> 'remap next' path.
>
> Anyone know how many of these actually get allocated (and their
> lifetimes)?
> How much difference would it make to allocate 368 (maybe 384?)
> bytes instead of 224 (likely 256).
[CC+ xen list and maintainers]
Probably the xen maintainer can help us out here.
--
Gustavo
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [GIT PULL] Enable -Wstringop-overflow globally
2024-01-27 19:53 ` [GIT PULL] Enable -Wstringop-overflow globally Gustavo A. R. Silva
@ 2024-01-30 14:52 ` Thomas Hellström
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Hellström @ 2024-01-30 14:52 UTC (permalink / raw)
To: Gustavo A. R. Silva, David Laight, 'Linus Torvalds',
Kees Cook, Lucas De Marchi, Oded Gabbay, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann
Cc: linux-kernel@vger.kernel.org, intel-xe, Gustavo A. R. Silva,
dri-devel@lists.freedesktop.org, linux-hardening@vger.kernel.org
Hi,
On 1/27/24 20:53, Gustavo A. R. Silva wrote:
>
>
> On 1/27/24 09:11, David Laight wrote:
>> From: Linus Torvalds
>>> Sent: 26 January 2024 22:36
>>>
>>> On Fri, 26 Jan 2024 at 14:24, Kees Cook <keescook@chromium.org> wrote:
>>>>
>>>> I think xe has some other weird problems too. This may be related
>>>> (under
>>>> allocating):
>>>>
>>>> ../drivers/gpu/drm/xe/xe_vm.c: In function 'xe_vma_create':
>>>> ../drivers/gpu/drm/xe/xe_vm.c:806:21: warning: allocation of
>>>> insufficient size '224' for type
>>> 'struct xe_vma' with size '368' [-Walloc-size]
>>>> 806 | vma = kzalloc(sizeof(*vma) - sizeof(struct
>>>> xe_userptr),
>>>> | ^
>>>
>>> That code is indeed odd, but there's a comment in the xe_vma definition
>>>
>>> /**
>>> * @userptr: user pointer state, only allocated for VMAs
>>> that are
>>> * user pointers
>>> */
>>> struct xe_userptr userptr;
>>>
>>> although I agree that it should probably simply be made a final
>>> variably-sized array instead (and then you make that array size be
>>> 0/1).
>>
>> That entire code is odd.
>> It isn't obvious that the flag values that cause the short allocate
>> are the same ones that control whether the extra data is accessed.
>>
>> Never mind the oddities with the 'flags |= ' assignments int the
>> 'remap next' path.
>>
>> Anyone know how many of these actually get allocated (and their
>> lifetimes)?
>> How much difference would it make to allocate 368 (maybe 384?)
>> bytes instead of 224 (likely 256).
>
> [CC+ xen list and maintainers]
>
> Probably the xen maintainer can help us out here.
Unfortunately the number of these can be quite large, and with a long
lifetime which I guess was the reason that size optimization was done in
the first place.
Ideally IMO this should've been subclassed to an xe_userptr_vma, but
until we have a chance to clean that up, We can look at the
variable-sized array or simply allocate the full size until we get to that.
Thanks,
Thomas
>
> --
> Gustavo
>
>>
>> David
>>
>> -
>> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes,
>> MK1 1PT, UK
>> Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-30 14:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <Za6JwRpknVIlfhPF@work>
[not found] ` <CAHk-=wjG4jdE19-vWWhAX3ByfbNr4DJS-pwiN9oY38WkhMZ57g@mail.gmail.com>
[not found] ` <4907a7a3-8533-480a-bc3c-488573e18e66@embeddedor.com>
[not found] ` <202401261423.7AF702239@keescook>
[not found] ` <CAHk-=wiaaCatzmF6GXxP97pa8oEX7e4rBpd4JgsbKex3Ek1_9A@mail.gmail.com>
[not found] ` <f00e15fcba05497a87e91182a33c888f@AcuMS.aculab.com>
2024-01-27 19:53 ` [GIT PULL] Enable -Wstringop-overflow globally Gustavo A. R. Silva
2024-01-30 14:52 ` Thomas Hellström
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox