From: Thomas Huth <thuth@redhat.com>
To: Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: qat-linux@intel.com, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, Ahsan Atta <ahsan.atta@intel.com>
Subject: Re: [PATCH] crypto: qat - Don't use -EFAULT as error code during setkey()
Date: Fri, 13 Nov 2026 12:34:39 +0100 [thread overview]
Message-ID: <6eb809cc-de84-459e-a580-ea4eceb045a7@redhat.com> (raw)
In-Reply-To: <20260824122403.630026-1-thuth@redhat.com>
Am 24.08.26 um 14:24 schrieb Thomas Huth:
> EFAULT means "Bad Address", it's the error code that is meant to
> be returned when userspace provided the kerknel with a pointer to
> memory that is not part of its address space. However, the QAT driver
> abuses this error code during its setkey() function to signal that
> there was something wrong with the selected algorithm, which is just
> confusing.
>
> The best choice for an error code would likely have been EINVAL here,
> but qat_alg_aead_init_sessions() seems to make an effort to use this
> for another error case already, so there is likely the desire to
> distinguish the different errors here. Thus use EOPNOTSUPP as a
> replacement now, so qat_alg_aead_init_sessions() continues to return
> two different error codes depending on what went wrong.
>
> Anyway, instead of hard-coding the error codes in the function
> qat_alg_aead_init_sessions() again, let's also simply rather pass
> the error code from the called functions up to the caller instead,
> this way we can also get rid of the need to call memzero_explicit()
> here three times.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> .../crypto/intel/qat/qat_common/qat_algs.c | 31 +++++++++----------
> 1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/crypto/intel/qat/qat_common/qat_algs.c b/drivers/crypto/intel/qat/qat_common/qat_algs.c
> index 91663805d9e60..91da9cad1d89a 100644
> --- a/drivers/crypto/intel/qat/qat_common/qat_algs.c
> +++ b/drivers/crypto/intel/qat/qat_common/qat_algs.c
> @@ -135,7 +135,7 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash,
> return 0;
> }
> default:
> - return -EFAULT;
> + return -EOPNOTSUPP;
> }
> }
>
> @@ -186,7 +186,7 @@ static int qat_alg_aead_init_enc_session(struct crypto_aead *aead_tfm,
> cpu_to_be32(ctx->hash_blocksize);
>
> if (qat_alg_do_precomputes(hash, ctx, keys->authkey, keys->authkeylen))
> - return -EFAULT;
> + return -EOPNOTSUPP;
>
> /* Request setup */
> qat_alg_init_common_hdr(header);
> @@ -273,7 +273,7 @@ static int qat_alg_aead_init_dec_session(struct crypto_aead *aead_tfm,
> cpu_to_be32(ctx->hash_blocksize);
>
> if (qat_alg_do_precomputes(hash, ctx, keys->authkey, keys->authkeylen))
> - return -EFAULT;
> + return -EOPNOTSUPP;
>
> /* Request setup */
> qat_alg_init_common_hdr(header);
> @@ -472,28 +472,25 @@ static int qat_alg_aead_init_sessions(struct crypto_aead *tfm, const u8 *key,
> unsigned int keylen, int mode)
> {
> struct crypto_authenc_keys keys;
> - int alg;
> -
> - if (crypto_authenc_extractkeys(&keys, key, keylen))
> - goto bad_key;
> + int alg, ret;
>
> - if (qat_alg_validate_key(keys.enckeylen, &alg, mode))
> - goto bad_key;
> + ret = crypto_authenc_extractkeys(&keys, key, keylen);
> + if (ret)
> + goto error;
>
> - if (qat_alg_aead_init_enc_session(tfm, alg, &keys, mode))
> + ret = qat_alg_validate_key(keys.enckeylen, &alg, mode);
> + if (ret)
> goto error;
>
> - if (qat_alg_aead_init_dec_session(tfm, alg, &keys, mode))
> + ret = qat_alg_aead_init_enc_session(tfm, alg, &keys, mode);
> + if (ret)
> goto error;
>
> - memzero_explicit(&keys, sizeof(keys));
> - return 0;
> -bad_key:
> - memzero_explicit(&keys, sizeof(keys));
> - return -EINVAL;
> + ret = qat_alg_aead_init_dec_session(tfm, alg, &keys, mode);
> +
> error:
> memzero_explicit(&keys, sizeof(keys));
> - return -EFAULT;
> + return ret;
> }
>
> static int qat_alg_skcipher_init_sessions(struct qat_alg_skcipher_ctx *ctx,
Friendly ping! Anybody got a comment on this patch?
Thomas
prev parent reply other threads:[~2026-11-13 11:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 12:24 Thomas Huth
2026-11-13 11:34 ` Thomas Huth [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6eb809cc-de84-459e-a580-ea4eceb045a7@redhat.com \
--to=thuth@redhat.com \
--cc=ahsan.atta@intel.com \
--cc=davem@davemloft.net \
--cc=giovanni.cabiddu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qat-linux@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®