diff mbox series

[06/15] crypto: algif_skcipher - Disallow nonincremental algorithms

Message ID a22dc748fdd6b67efb5356fd7855610170da30d9.1707815065.git.herbert@gondor.apana.org.au
State New
Headers show
Series crypto: Add twopass lskcipher for adiantum | expand

Commit Message

Herbert Xu Dec. 5, 2023, 6:13 a.m. UTC
As algif_skcipher does not support nonincremental algorithms, check
for them and return ENOSYS.  If necessary support for them could
be added in the same way as AEAD.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 crypto/algif_skcipher.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Eric Biggers Feb. 14, 2024, 10:56 p.m. UTC | #1
On Tue, Dec 05, 2023 at 02:13:26PM +0800, Herbert Xu wrote:
> As algif_skcipher does not support nonincremental algorithms, check
> for them and return ENOSYS

Shouldn't they still be supported if the data is being read/written all at once?

Also, ENOSYS isn't really an appropriate error code.  ENOSYS normally means that
the system call isn't supported at all.  Maybe use EOPNOTSUPP?

- Eric
Herbert Xu Feb. 15, 2024, 6:47 a.m. UTC | #2
On Wed, Feb 14, 2024 at 02:56:38PM -0800, Eric Biggers wrote:
>
> Shouldn't they still be supported if the data is being read/written all at once?

It is supported, or at least it worked for my libkcapi tests on
adiantum.  This error only triggers if we enter the code-path that
splits the operation into two or more (because the user didn't
write all the data in one go).

> Also, ENOSYS isn't really an appropriate error code.  ENOSYS normally means that
> the system call isn't supported at all.  Maybe use EOPNOTSUPP?

Within the crypto subsystem ENOSYS means that a particular
functionality is not supported.  I'm happy to change that but
that should go into a different patch as there are existing uses
which are similar (e.g., cloning).

Thanks,
diff mbox series

Patch

diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index e22516c3d285..ac59fd9ea4e4 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -131,6 +131,10 @@  static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
 	 * full block size buffers.
 	 */
 	if (ctx->more || len < ctx->used) {
+		err = -ENOSYS;
+		if (!crypto_skcipher_isincremental(tfm))
+			goto free;
+
 		if (ctx->more && ctx->used - ts < len)
 			len = ctx->used - ts;
 		len -= len % bs;