lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 03 May 2019 07:38:52 +0300
From:   Kalle Valo <kvalo@...eaurora.org>
To:     Nick Desaulniers <ndesaulniers@...gle.com>
Cc:     Nathan Chancellor <natechancellor@...il.com>,
        Amitkumar Karwar <amitkarwar@...il.com>,
        Siva Rebbagondla <siva8118@...il.com>,
        linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
        LKML <linux-kernel@...r.kernel.org>,
        clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH] rsi: Properly initialize data in rsi_sdio_ta_reset

Nick Desaulniers <ndesaulniers@...gle.com> writes:

> On Thu, May 2, 2019 at 8:16 AM Nathan Chancellor
> <natechancellor@...il.com> wrote:
>>
>> When building with -Wuninitialized, Clang warns:
>>
>> drivers/net/wireless/rsi/rsi_91x_sdio.c:940:43: warning: variable 'data'
>> is uninitialized when used here [-Wuninitialized]
>>         put_unaligned_le32(TA_HOLD_THREAD_VALUE, data);
>>                                                  ^~~~
>> drivers/net/wireless/rsi/rsi_91x_sdio.c:930:10: note: initialize the
>> variable 'data' to silence this warning
>>         u8 *data;
>>                 ^
>>                  = NULL
>> 1 warning generated.
>>
>> Using Clang's suggestion of initializing data to NULL wouldn't work out
>> because data will be dereferenced by put_unaligned_le32. Use kzalloc to
>> properly initialize data, which matches a couple of other places in this
>> driver.
>>
>> Fixes: e5a1ecc97e5f ("rsi: add firmware loading for 9116 device")
>> Link: https://github.com/ClangBuiltLinux/linux/issues/464
>> Signed-off-by: Nathan Chancellor <natechancellor@...il.com>
>> ---
>>  drivers/net/wireless/rsi/rsi_91x_sdio.c | 21 ++++++++++++++-------
>>  1 file changed, 14 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/net/wireless/rsi/rsi_91x_sdio.c b/drivers/net/wireless/rsi/rsi_91x_sdio.c
>> index f9c67ed473d1..b35728564c7b 100644
>> --- a/drivers/net/wireless/rsi/rsi_91x_sdio.c
>> +++ b/drivers/net/wireless/rsi/rsi_91x_sdio.c
>> @@ -929,11 +929,15 @@ static int rsi_sdio_ta_reset(struct rsi_hw *adapter)
>>         u32 addr;
>>         u8 *data;
>>
>> +       data = kzalloc(sizeof(u32), GFP_KERNEL);
>
> Something fishy is going on here.  We allocate 4 B but declare data as
> a u8* (pointer to individual bytes)?  In general, dynamically
> allocating that few bytes is a code smell; either you meant to just
> use the stack, or this memory's lifetime extends past the lifetime of
> this stackframe, at which point you probably just meant to stack
> allocate space in a higher parent frame and pass this preallocated
> memory down to the child frame to get filled in.
>
> Reading through this code, I don't think that the memory is meant to
> outlive the stack frame.  Is there a reason why we can't just declare
> data as:
>
> u8 data [4];
>
> then use ARRAY_SIZE(data) or RSI_9116_REG_SIZE in rsi_reset_chip(),
> getting rid of the kzalloc/kfree?

I haven't checked the details but AFAIK stack variables are not supposed
to be used with DMA. So in that case I think it's ok alloc four bytes,
unless the DMA rules have changed of course. But I didn't check if rsi
is using DMA here, just a general comment.

-- 
Kalle Valo

Powered by blists - more mailing lists