mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	qat-linux <qat-linux@intel.com>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Atta, Ahsan" <ahsan.atta@intel.com>
Subject: Re: [PATCH] crypto: qat - Don't use -EFAULT as error code during setkey()
Date: Wed, 18 Nov 2026 17:55:11 +0000	[thread overview]
Message-ID: <av3mf1z+/SlzbCxH@gcabiddu-mobl.ger.corp.intel.com> (raw)
In-Reply-To: <a0153735095f47aabfb471f12cff9cb7@BL1PR11MB5431.namprd11.prod.outlook.com>

On Fri, Nov 13, 2026 at 11:34:39AM +0000, Thomas Huth wrote:
> 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
/s/kerknel/kernel

> > 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;
We could also change this into:

	ret = qat_alg_do_precomputes(hash, ctx, keys->authkey, keys->authkeylen));
	if (ret)
		return ret;

> >   	/* 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?
Apologies, I thought this was already merged!

You might have to re-send it as I see that it is marked as `Deferred` in
patchwork.

Also, you can add my tag:
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>

Regards,

-- 
Giovanni

      parent reply	other threads:[~2026-11-18 17:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 12:24 Thomas Huth
2026-11-13 11:34 ` Thomas Huth
     [not found] ` <a0153735095f47aabfb471f12cff9cb7@BL1PR11MB5431.namprd11.prod.outlook.com>
2026-11-18 17:55   ` Giovanni Cabiddu [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=av3mf1z+/SlzbCxH@gcabiddu-mobl.ger.corp.intel.com \
    --to=giovanni.cabiddu@intel.com \
    --cc=ahsan.atta@intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qat-linux@intel.com \
    --cc=thuth@redhat.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®