Re: [PATCH] scsi: elx: sli4: Replace deprecated strncpy() with strscpy()

From: Thorsten Blum
Date: Mon Apr 07 2025 - 16:55:29 EST


On 7. Apr 2025, at 22:30, Kees Cook wrote:
> On Mon, Apr 07, 2025 at 09:01:53PM +0200, Thorsten Blum wrote:
>> On 7. Apr 2025, at 20:28, Kees Cook wrote:
>>> On Wed, Feb 26, 2025 at 07:55:26PM +0100, Thorsten Blum wrote:
>>>> strncpy() is deprecated for NUL-terminated destination buffers; use
>>>> strscpy() instead.
>>>>
>>>> Compile-tested only.
>>>>
>>>> Link: https://github.com/KSPP/linux/issues/90
>>>> Cc: linux-hardening@xxxxxxxxxxxxxxx
>>>> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
>>>> ---
>>>
>>> Standard question for these kinds of conversions: Why is it safe that
>>> this is not NUL padded? I haven't found where this buffer is being
>>> zeroed out, but it probably is (given the "- 1" on the length), but
>>> without run-time testing, this needs much more careful analysis.
>>
>> I think this was submitted before I started to explain this better.
>>
>> 'wr_obj' is the zeroed out 'buf' returned from sli_config_cmd_init().
>
> I don't see how dma->virt and buf are associated?

Since dma is NULL, sli_config_cmd_init() returns config->payload.embed
early (it doesn't get to return dma->virt) and before we have

memset(buf, 0, SLI4_BMBX_SIZE);
config = buf;

and SLI4_BMBX_SIZE is 256 which matches the size of sli4_cmd_sli_config.

It's not very obvious tbh.