Re: [PATCH] crypto/hisilicon: Add null judgment to the callback interface

From: liulongfang
Date: Fri Nov 11 2022 - 20:52:06 EST


On 2022/11/10 16:53, Herbert Xu wrote:
> On Thu, Nov 10, 2022 at 12:11:15PM +0800, liulongfang wrote:
>>
>> When using crypto's skcipher series interfaces for encryption and decryption
>> services, User can use synchronous mode(by adjusting some skcipher interfaces,
>> here is to remove skcipher_request_set_callback()) or asynchronous mode,
>> but when using synchronous mode and the current asynchronous mode is loaded
>> it will cause a calltrace.
>>
>> The current problem is that the interface of skcipher does not restrict users
>> to call functions in this way for encryption services.
>>
>> If the current driver doesn't handle this, there is a possibility that some users
>> deliberately create this kind of problem to cause the kernel to crash.
>
> It sounds like your code is misusing the skcipher API. By default
> skcipher is always async. You must always set a callback.
>
> The only way to legally use skcipher without setting a callback
> is by allocating it with crypto_alloc_sync_skcipher. In which case

OK! I found in Documentation/crypto/architecture.rst the description
that async mode must provide a callback function.

However, what is confusing is that this document does not describe
the synchronization mode so clearly.

> unless your driver incorrectly declares itself as sync instead of
> async, then it will never be used by such a user.
>
> Cheers,
>
Thanks,
Longfang.