2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-02-28 19:50:00 +00:00
|
|
|
/*
|
|
|
|
* algif_aead: User-space interface for AEAD algorithms
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014, Stephan Mueller <smueller@chronox.de>
|
|
|
|
*
|
|
|
|
* This file provides the user-space API for AEAD ciphers.
|
|
|
|
*
|
2017-06-25 15:12:59 +00:00
|
|
|
* The following concept of the memory management is used:
|
|
|
|
*
|
|
|
|
* The kernel maintains two SGLs, the TX SGL and the RX SGL. The TX SGL is
|
2023-06-23 22:55:12 +00:00
|
|
|
* filled by user space with the data submitted via sendmsg (maybe with
|
|
|
|
* MSG_SPLICE_PAGES). Filling up the TX SGL does not cause a crypto operation
|
|
|
|
* -- the data will only be tracked by the kernel. Upon receipt of one recvmsg
|
|
|
|
* call, the caller must provide a buffer which is tracked with the RX SGL.
|
2017-06-25 15:12:59 +00:00
|
|
|
*
|
|
|
|
* During the processing of the recvmsg operation, the cipher request is
|
|
|
|
* allocated and prepared. As part of the recvmsg operation, the processed
|
|
|
|
* TX buffers are extracted from the TX SGL into a separate SGL.
|
|
|
|
*
|
|
|
|
* After the completion of the crypto operation, the RX SGL and the cipher
|
|
|
|
* request is released. The extracted TX SGL parts are released together with
|
|
|
|
* the RX SGL release.
|
2015-02-28 19:50:00 +00:00
|
|
|
*/
|
|
|
|
|
2016-03-11 19:50:33 +00:00
|
|
|
#include <crypto/internal/aead.h>
|
2015-02-28 19:50:00 +00:00
|
|
|
#include <crypto/scatterwalk.h>
|
|
|
|
#include <crypto/if_alg.h>
|
2017-07-30 12:32:58 +00:00
|
|
|
#include <crypto/skcipher.h>
|
|
|
|
#include <crypto/null.h>
|
2015-02-28 19:50:00 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
|
2017-04-24 09:15:23 +00:00
|
|
|
struct aead_tfm {
|
|
|
|
struct crypto_aead *aead;
|
2018-09-19 02:10:51 +00:00
|
|
|
struct crypto_sync_skcipher *null_tfm;
|
2017-04-24 09:15:23 +00:00
|
|
|
};
|
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
static inline bool aead_sufficient_data(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
|
|
struct sock *psk = ask->parent;
|
|
|
|
struct alg_sock *pask = alg_sk(psk);
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
struct af_alg_ctx *ctx = ask->private;
|
2017-06-25 15:12:59 +00:00
|
|
|
struct aead_tfm *aeadc = pask->private;
|
|
|
|
struct crypto_aead *tfm = aeadc->aead;
|
|
|
|
unsigned int as = crypto_aead_authsize(tfm);
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2016-12-05 14:26:19 +00:00
|
|
|
/*
|
|
|
|
* The minimum amount of memory needed for an AEAD cipher is
|
|
|
|
* the AAD and in case of decryption the tag.
|
|
|
|
*/
|
|
|
|
return ctx->used >= ctx->aead_assoclen + (ctx->enc ? 0 : as);
|
2015-02-28 19:50:00 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 21:09:46 +00:00
|
|
|
static int aead_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
|
2015-02-28 19:50:00 +00:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct alg_sock *ask = alg_sk(sk);
|
2017-06-25 15:12:59 +00:00
|
|
|
struct sock *psk = ask->parent;
|
|
|
|
struct alg_sock *pask = alg_sk(psk);
|
|
|
|
struct aead_tfm *aeadc = pask->private;
|
|
|
|
struct crypto_aead *tfm = aeadc->aead;
|
|
|
|
unsigned int ivsize = crypto_aead_ivsize(tfm);
|
2015-02-28 19:50:00 +00:00
|
|
|
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
return af_alg_sendmsg(sock, msg, size, ivsize);
|
2016-03-11 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:10:51 +00:00
|
|
|
static int crypto_aead_copy_sgl(struct crypto_sync_skcipher *null_tfm,
|
2017-07-30 12:32:58 +00:00
|
|
|
struct scatterlist *src,
|
|
|
|
struct scatterlist *dst, unsigned int len)
|
|
|
|
{
|
2018-09-19 02:10:51 +00:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, null_tfm);
|
2017-07-30 12:32:58 +00:00
|
|
|
|
2018-09-19 02:10:51 +00:00
|
|
|
skcipher_request_set_sync_tfm(skreq, null_tfm);
|
2020-07-31 07:03:50 +00:00
|
|
|
skcipher_request_set_callback(skreq, CRYPTO_TFM_REQ_MAY_SLEEP,
|
2017-07-30 12:32:58 +00:00
|
|
|
NULL, NULL);
|
|
|
|
skcipher_request_set_crypt(skreq, src, dst, len, NULL);
|
|
|
|
|
|
|
|
return crypto_skcipher_encrypt(skreq);
|
|
|
|
}
|
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
|
|
size_t ignored, int flags)
|
2015-02-28 19:50:00 +00:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct alg_sock *ask = alg_sk(sk);
|
2017-06-25 15:12:59 +00:00
|
|
|
struct sock *psk = ask->parent;
|
|
|
|
struct alg_sock *pask = alg_sk(psk);
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
struct af_alg_ctx *ctx = ask->private;
|
2017-06-25 15:12:59 +00:00
|
|
|
struct aead_tfm *aeadc = pask->private;
|
|
|
|
struct crypto_aead *tfm = aeadc->aead;
|
2018-09-19 02:10:51 +00:00
|
|
|
struct crypto_sync_skcipher *null_tfm = aeadc->null_tfm;
|
2017-11-10 10:04:52 +00:00
|
|
|
unsigned int i, as = crypto_aead_authsize(tfm);
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
struct af_alg_async_req *areq;
|
2017-11-10 10:04:52 +00:00
|
|
|
struct af_alg_tsgl *tsgl, *tmp;
|
|
|
|
struct scatterlist *rsgl_src, *tsgl_src = NULL;
|
2017-06-25 15:12:59 +00:00
|
|
|
int err = 0;
|
|
|
|
size_t used = 0; /* [in] TX bufs to be en/decrypted */
|
|
|
|
size_t outlen = 0; /* [out] RX bufs produced by kernel */
|
|
|
|
size_t usedpages = 0; /* [in] RX bufs to be used from user */
|
|
|
|
size_t processed = 0; /* [in] TX bufs to be consumed */
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2020-05-29 14:23:49 +00:00
|
|
|
if (!ctx->init || ctx->more) {
|
|
|
|
err = af_alg_wait_for_data(sk, flags, 0);
|
2017-11-29 11:02:23 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-02-28 19:50:00 +00:00
|
|
|
/*
|
2023-06-06 13:08:54 +00:00
|
|
|
* Data length provided by caller via sendmsg that has not yet been
|
|
|
|
* processed.
|
2015-02-28 19:50:00 +00:00
|
|
|
*/
|
|
|
|
used = ctx->used;
|
|
|
|
|
|
|
|
/*
|
2023-06-06 13:08:54 +00:00
|
|
|
* Make sure sufficient data is present -- note, the same check is also
|
|
|
|
* present in sendmsg. The checks in sendmsg shall provide an
|
|
|
|
* information to the data sender that something is wrong, but they are
|
|
|
|
* irrelevant to maintain the kernel integrity. We need this check
|
|
|
|
* here too in case user space decides to not honor the error message
|
|
|
|
* in sendmsg and still call recvmsg. This check here protects the
|
|
|
|
* kernel integrity.
|
2015-02-28 19:50:00 +00:00
|
|
|
*/
|
2017-06-25 15:12:59 +00:00
|
|
|
if (!aead_sufficient_data(sk))
|
|
|
|
return -EINVAL;
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2016-12-05 14:26:19 +00:00
|
|
|
/*
|
|
|
|
* Calculate the minimum output buffer size holding the result of the
|
|
|
|
* cipher operation. When encrypting data, the receiving buffer is
|
|
|
|
* larger by the tag length compared to the input buffer as the
|
|
|
|
* encryption operation generates the tag. For decryption, the input
|
|
|
|
* buffer provides the tag which is consumed resulting in only the
|
|
|
|
* plaintext without a buffer for the tag returned to the caller.
|
|
|
|
*/
|
|
|
|
if (ctx->enc)
|
|
|
|
outlen = used + as;
|
|
|
|
else
|
|
|
|
outlen = used - as;
|
2015-05-27 09:24:41 +00:00
|
|
|
|
2015-02-28 19:50:00 +00:00
|
|
|
/*
|
|
|
|
* The cipher operation input data is reduced by the associated data
|
|
|
|
* length as this data is processed separately later on.
|
|
|
|
*/
|
2016-12-05 14:26:19 +00:00
|
|
|
used -= ctx->aead_assoclen;
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
/* Allocate cipher request for current operation. */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
areq = af_alg_alloc_areq(sk, sizeof(struct af_alg_async_req) +
|
|
|
|
crypto_aead_reqsize(tfm));
|
|
|
|
if (IS_ERR(areq))
|
|
|
|
return PTR_ERR(areq);
|
2017-06-25 15:12:59 +00:00
|
|
|
|
|
|
|
/* convert iovecs of output buffers into RX SGL */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
err = af_alg_get_rsgl(sk, msg, flags, areq, outlen, &usedpages);
|
|
|
|
if (err)
|
|
|
|
goto free;
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
/*
|
|
|
|
* Ensure output buffer is sufficiently large. If the caller provides
|
|
|
|
* less buffer space, only use the relative required input size. This
|
|
|
|
* allows AIO operation where the caller sent all data to be processed
|
|
|
|
* and the AIO operation performs the operation on the different chunks
|
|
|
|
* of the input data.
|
|
|
|
*/
|
2016-12-05 14:26:19 +00:00
|
|
|
if (usedpages < outlen) {
|
2017-06-25 15:12:59 +00:00
|
|
|
size_t less = outlen - usedpages;
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
if (used < less) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
used -= less;
|
|
|
|
outlen -= less;
|
|
|
|
}
|
2015-02-28 19:50:00 +00:00
|
|
|
|
2017-07-30 12:32:58 +00:00
|
|
|
processed = used + ctx->aead_assoclen;
|
2017-11-10 10:04:52 +00:00
|
|
|
list_for_each_entry_safe(tsgl, tmp, &ctx->tsgl_list, list) {
|
|
|
|
for (i = 0; i < tsgl->cur; i++) {
|
|
|
|
struct scatterlist *process_sg = tsgl->sg + i;
|
|
|
|
|
|
|
|
if (!(process_sg->length) || !sg_page(process_sg))
|
|
|
|
continue;
|
|
|
|
tsgl_src = process_sg;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tsgl_src)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (processed && !tsgl_src) {
|
|
|
|
err = -EFAULT;
|
|
|
|
goto free;
|
|
|
|
}
|
2017-07-30 12:32:58 +00:00
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
/*
|
2017-07-30 12:32:58 +00:00
|
|
|
* Copy of AAD from source to destination
|
|
|
|
*
|
|
|
|
* The AAD is copied to the destination buffer without change. Even
|
|
|
|
* when user space uses an in-place cipher operation, the kernel
|
|
|
|
* will copy the data as it does not see whether such in-place operation
|
|
|
|
* is initiated.
|
|
|
|
*
|
|
|
|
* To ensure efficiency, the following implementation ensure that the
|
|
|
|
* ciphers are invoked to perform a crypto operation in-place. This
|
|
|
|
* is achieved by memory management specified as follows.
|
2017-06-25 15:12:59 +00:00
|
|
|
*/
|
2017-07-30 12:32:58 +00:00
|
|
|
|
|
|
|
/* Use the RX SGL as source (and destination) for crypto op. */
|
2023-06-06 13:08:52 +00:00
|
|
|
rsgl_src = areq->first_rsgl.sgl.sgt.sgl;
|
2017-07-30 12:32:58 +00:00
|
|
|
|
|
|
|
if (ctx->enc) {
|
|
|
|
/*
|
|
|
|
* Encryption operation - The in-place cipher operation is
|
|
|
|
* achieved by the following operation:
|
|
|
|
*
|
2017-08-09 14:20:00 +00:00
|
|
|
* TX SGL: AAD || PT
|
2017-07-30 12:32:58 +00:00
|
|
|
* | |
|
|
|
|
* | copy |
|
|
|
|
* v v
|
2017-08-09 14:20:00 +00:00
|
|
|
* RX SGL: AAD || PT || Tag
|
2017-07-30 12:32:58 +00:00
|
|
|
*/
|
2017-11-10 10:04:52 +00:00
|
|
|
err = crypto_aead_copy_sgl(null_tfm, tsgl_src,
|
2023-06-06 13:08:52 +00:00
|
|
|
areq->first_rsgl.sgl.sgt.sgl,
|
|
|
|
processed);
|
2017-07-30 12:32:58 +00:00
|
|
|
if (err)
|
|
|
|
goto free;
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
af_alg_pull_tsgl(sk, processed, NULL, 0);
|
2017-07-30 12:32:58 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Decryption operation - To achieve an in-place cipher
|
|
|
|
* operation, the following SGL structure is used:
|
|
|
|
*
|
|
|
|
* TX SGL: AAD || CT || Tag
|
|
|
|
* | | ^
|
|
|
|
* | copy | | Create SGL link.
|
|
|
|
* v v |
|
|
|
|
* RX SGL: AAD || CT ----+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Copy AAD || CT to RX SGL buffer for in-place operation. */
|
2017-11-10 10:04:52 +00:00
|
|
|
err = crypto_aead_copy_sgl(null_tfm, tsgl_src,
|
2023-06-06 13:08:52 +00:00
|
|
|
areq->first_rsgl.sgl.sgt.sgl,
|
|
|
|
outlen);
|
2017-07-30 12:32:58 +00:00
|
|
|
if (err)
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
/* Create TX SGL for tag and chain it to RX SGL. */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
areq->tsgl_entries = af_alg_count_tsgl(sk, processed,
|
|
|
|
processed - as);
|
2017-07-30 12:32:58 +00:00
|
|
|
if (!areq->tsgl_entries)
|
|
|
|
areq->tsgl_entries = 1;
|
treewide: Use array_size() in sock_kmalloc()
The sock_kmalloc() function has no 2-factor argument form, so
multiplication factors need to be wrapped in array_size(). This patch
replaces cases of:
sock_kmalloc(handle, a * b, gfp)
with:
sock_kmalloc(handle, array_size(a, b), gfp)
as well as handling cases of:
sock_kmalloc(handle, a * b * c, gfp)
with:
sock_kmalloc(handle, array3_size(a, b, c), gfp)
This does, however, attempt to ignore constant size factors like:
sock_kmalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
sock_kmalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
sock_kmalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
sock_kmalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
sock_kmalloc(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * COUNT_ID
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
sock_kmalloc(HANDLE,
- SIZE * COUNT
+ array_size(COUNT, SIZE)
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
sock_kmalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
sock_kmalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
sock_kmalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
sock_kmalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
sock_kmalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
sock_kmalloc(HANDLE, C1 * C2 * C3, ...)
|
sock_kmalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants.
@@
expression HANDLE;
expression E1, E2;
constant C1, C2;
@@
(
sock_kmalloc(HANDLE, C1 * C2, ...)
|
sock_kmalloc(HANDLE,
- E1 * E2
+ array_size(E1, E2)
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:28:11 +00:00
|
|
|
areq->tsgl = sock_kmalloc(sk, array_size(sizeof(*areq->tsgl),
|
|
|
|
areq->tsgl_entries),
|
2017-07-30 12:32:58 +00:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!areq->tsgl) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
sg_init_table(areq->tsgl, areq->tsgl_entries);
|
|
|
|
|
|
|
|
/* Release TX SGL, except for tag data and reassign tag data. */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
af_alg_pull_tsgl(sk, processed, areq->tsgl, processed - as);
|
2017-07-30 12:32:58 +00:00
|
|
|
|
|
|
|
/* chain the areq TX SGL holding the tag with RX SGL */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
if (usedpages) {
|
2017-07-30 12:32:58 +00:00
|
|
|
/* RX SGL present */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
struct af_alg_sgl *sgl_prev = &areq->last_rsgl->sgl;
|
2023-06-06 13:08:52 +00:00
|
|
|
struct scatterlist *sg = sgl_prev->sgt.sgl;
|
2017-07-30 12:32:58 +00:00
|
|
|
|
2023-06-06 13:08:52 +00:00
|
|
|
sg_unmark_end(sg + sgl_prev->sgt.nents - 1);
|
|
|
|
sg_chain(sg, sgl_prev->sgt.nents + 1, areq->tsgl);
|
2017-07-30 12:32:58 +00:00
|
|
|
} else
|
|
|
|
/* no RX SGL present (e.g. authentication only) */
|
2017-11-10 10:04:52 +00:00
|
|
|
rsgl_src = areq->tsgl;
|
2017-06-25 15:12:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the crypto operation */
|
2017-11-10 10:04:52 +00:00
|
|
|
aead_request_set_crypt(&areq->cra_u.aead_req, rsgl_src,
|
2023-06-06 13:08:52 +00:00
|
|
|
areq->first_rsgl.sgl.sgt.sgl, used, ctx->iv);
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
aead_request_set_ad(&areq->cra_u.aead_req, ctx->aead_assoclen);
|
|
|
|
aead_request_set_tfm(&areq->cra_u.aead_req, tfm);
|
2017-06-25 15:12:59 +00:00
|
|
|
|
|
|
|
if (msg->msg_iocb && !is_sync_kiocb(msg->msg_iocb)) {
|
|
|
|
/* AIO operation */
|
2017-11-10 12:20:55 +00:00
|
|
|
sock_hold(sk);
|
2017-06-25 15:12:59 +00:00
|
|
|
areq->iocb = msg->msg_iocb;
|
2017-12-08 10:50:37 +00:00
|
|
|
|
|
|
|
/* Remember output size that will be generated. */
|
|
|
|
areq->outlen = outlen;
|
|
|
|
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
aead_request_set_callback(&areq->cra_u.aead_req,
|
2020-07-31 07:03:50 +00:00
|
|
|
CRYPTO_TFM_REQ_MAY_SLEEP,
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
af_alg_async_cb, areq);
|
|
|
|
err = ctx->enc ? crypto_aead_encrypt(&areq->cra_u.aead_req) :
|
|
|
|
crypto_aead_decrypt(&areq->cra_u.aead_req);
|
2017-11-10 12:20:55 +00:00
|
|
|
|
|
|
|
/* AIO operation in progress */
|
2020-07-31 07:03:50 +00:00
|
|
|
if (err == -EINPROGRESS)
|
2017-11-10 12:20:55 +00:00
|
|
|
return -EIOCBQUEUED;
|
|
|
|
|
|
|
|
sock_put(sk);
|
2017-06-25 15:12:59 +00:00
|
|
|
} else {
|
|
|
|
/* Synchronous operation */
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
aead_request_set_callback(&areq->cra_u.aead_req,
|
2020-07-31 07:03:50 +00:00
|
|
|
CRYPTO_TFM_REQ_MAY_SLEEP |
|
2017-06-25 15:12:59 +00:00
|
|
|
CRYPTO_TFM_REQ_MAY_BACKLOG,
|
2017-10-18 07:00:39 +00:00
|
|
|
crypto_req_done, &ctx->wait);
|
|
|
|
err = crypto_wait_req(ctx->enc ?
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
crypto_aead_encrypt(&areq->cra_u.aead_req) :
|
|
|
|
crypto_aead_decrypt(&areq->cra_u.aead_req),
|
2017-10-18 07:00:39 +00:00
|
|
|
&ctx->wait);
|
2015-02-28 19:50:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
|
|
|
|
free:
|
2017-11-10 12:20:55 +00:00
|
|
|
af_alg_free_resources(areq);
|
2015-02-28 19:50:00 +00:00
|
|
|
|
|
|
|
return err ? err : outlen;
|
|
|
|
}
|
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
static int aead_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
|
|
size_t ignored, int flags)
|
2016-03-11 19:50:33 +00:00
|
|
|
{
|
2017-06-25 15:12:59 +00:00
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
while (msg_data_left(msg)) {
|
|
|
|
int err = _aead_recvmsg(sock, msg, ignored, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This error covers -EIOCBQUEUED which implies that we can
|
|
|
|
* only handle one AIO request. If the caller wants to have
|
|
|
|
* multiple AIO requests in parallel, he must make multiple
|
|
|
|
* separate AIO calls.
|
2017-07-30 12:31:18 +00:00
|
|
|
*
|
|
|
|
* Also return the error if no data has been processed so far.
|
2017-06-25 15:12:59 +00:00
|
|
|
*/
|
|
|
|
if (err <= 0) {
|
2017-07-30 12:31:18 +00:00
|
|
|
if (err == -EIOCBQUEUED || err == -EBADMSG || !ret)
|
2017-06-25 15:12:59 +00:00
|
|
|
ret = err;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += err;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
af_alg_wmem_wakeup(sk);
|
2017-06-25 15:12:59 +00:00
|
|
|
release_sock(sk);
|
|
|
|
return ret;
|
2016-03-11 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 19:50:00 +00:00
|
|
|
static struct proto_ops algif_aead_ops = {
|
|
|
|
.family = PF_ALG,
|
|
|
|
|
|
|
|
.connect = sock_no_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.getname = sock_no_getname,
|
|
|
|
.ioctl = sock_no_ioctl,
|
|
|
|
.listen = sock_no_listen,
|
|
|
|
.shutdown = sock_no_shutdown,
|
|
|
|
.mmap = sock_no_mmap,
|
|
|
|
.bind = sock_no_bind,
|
|
|
|
.accept = sock_no_accept,
|
|
|
|
|
|
|
|
.release = af_alg_release,
|
|
|
|
.sendmsg = aead_sendmsg,
|
|
|
|
.recvmsg = aead_recvmsg,
|
2018-06-28 16:43:44 +00:00
|
|
|
.poll = af_alg_poll,
|
2015-02-28 19:50:00 +00:00
|
|
|
};
|
|
|
|
|
2017-04-24 09:15:23 +00:00
|
|
|
static int aead_check_key(struct socket *sock)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct sock *psk;
|
|
|
|
struct alg_sock *pask;
|
|
|
|
struct aead_tfm *tfm;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
|
|
|
|
|
|
lock_sock(sk);
|
2020-06-08 06:48:43 +00:00
|
|
|
if (!atomic_read(&ask->nokey_refcnt))
|
2017-04-24 09:15:23 +00:00
|
|
|
goto unlock_child;
|
|
|
|
|
|
|
|
psk = ask->parent;
|
|
|
|
pask = alg_sk(ask->parent);
|
|
|
|
tfm = pask->private;
|
|
|
|
|
|
|
|
err = -ENOKEY;
|
|
|
|
lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
|
2018-01-03 19:16:30 +00:00
|
|
|
if (crypto_aead_get_flags(tfm->aead) & CRYPTO_TFM_NEED_KEY)
|
2017-04-24 09:15:23 +00:00
|
|
|
goto unlock;
|
|
|
|
|
2020-06-08 06:48:43 +00:00
|
|
|
atomic_dec(&pask->nokey_refcnt);
|
|
|
|
atomic_set(&ask->nokey_refcnt, 0);
|
2017-04-24 09:15:23 +00:00
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
release_sock(psk);
|
|
|
|
unlock_child:
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aead_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = aead_check_key(sock);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return aead_sendmsg(sock, msg, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aead_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
|
|
|
|
size_t ignored, int flags)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = aead_check_key(sock);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return aead_recvmsg(sock, msg, ignored, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct proto_ops algif_aead_ops_nokey = {
|
|
|
|
.family = PF_ALG,
|
|
|
|
|
|
|
|
.connect = sock_no_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.getname = sock_no_getname,
|
|
|
|
.ioctl = sock_no_ioctl,
|
|
|
|
.listen = sock_no_listen,
|
|
|
|
.shutdown = sock_no_shutdown,
|
|
|
|
.mmap = sock_no_mmap,
|
|
|
|
.bind = sock_no_bind,
|
|
|
|
.accept = sock_no_accept,
|
|
|
|
|
|
|
|
.release = af_alg_release,
|
|
|
|
.sendmsg = aead_sendmsg_nokey,
|
|
|
|
.recvmsg = aead_recvmsg_nokey,
|
2018-06-28 16:43:44 +00:00
|
|
|
.poll = af_alg_poll,
|
2017-04-24 09:15:23 +00:00
|
|
|
};
|
|
|
|
|
2015-02-28 19:50:00 +00:00
|
|
|
static void *aead_bind(const char *name, u32 type, u32 mask)
|
|
|
|
{
|
2017-04-24 09:15:23 +00:00
|
|
|
struct aead_tfm *tfm;
|
|
|
|
struct crypto_aead *aead;
|
2018-09-19 02:10:51 +00:00
|
|
|
struct crypto_sync_skcipher *null_tfm;
|
2017-04-24 09:15:23 +00:00
|
|
|
|
|
|
|
tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
|
|
|
|
if (!tfm)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
aead = crypto_alloc_aead(name, type, mask);
|
|
|
|
if (IS_ERR(aead)) {
|
|
|
|
kfree(tfm);
|
|
|
|
return ERR_CAST(aead);
|
|
|
|
}
|
|
|
|
|
2017-12-07 18:56:34 +00:00
|
|
|
null_tfm = crypto_get_default_null_skcipher();
|
2017-07-30 12:32:58 +00:00
|
|
|
if (IS_ERR(null_tfm)) {
|
|
|
|
crypto_free_aead(aead);
|
|
|
|
kfree(tfm);
|
|
|
|
return ERR_CAST(null_tfm);
|
|
|
|
}
|
|
|
|
|
2017-04-24 09:15:23 +00:00
|
|
|
tfm->aead = aead;
|
2017-07-30 12:32:58 +00:00
|
|
|
tfm->null_tfm = null_tfm;
|
2017-04-24 09:15:23 +00:00
|
|
|
|
|
|
|
return tfm;
|
2015-02-28 19:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void aead_release(void *private)
|
|
|
|
{
|
2017-04-24 09:15:23 +00:00
|
|
|
struct aead_tfm *tfm = private;
|
|
|
|
|
|
|
|
crypto_free_aead(tfm->aead);
|
2017-12-07 18:56:34 +00:00
|
|
|
crypto_put_default_null_skcipher();
|
2017-04-24 09:15:23 +00:00
|
|
|
kfree(tfm);
|
2015-02-28 19:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int aead_setauthsize(void *private, unsigned int authsize)
|
|
|
|
{
|
2017-04-24 09:15:23 +00:00
|
|
|
struct aead_tfm *tfm = private;
|
|
|
|
|
|
|
|
return crypto_aead_setauthsize(tfm->aead, authsize);
|
2015-02-28 19:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int aead_setkey(void *private, const u8 *key, unsigned int keylen)
|
|
|
|
{
|
2017-04-24 09:15:23 +00:00
|
|
|
struct aead_tfm *tfm = private;
|
|
|
|
|
2018-01-03 19:16:30 +00:00
|
|
|
return crypto_aead_setkey(tfm->aead, key, keylen);
|
2015-02-28 19:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void aead_sock_destruct(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct alg_sock *ask = alg_sk(sk);
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
struct af_alg_ctx *ctx = ask->private;
|
2017-06-25 15:12:59 +00:00
|
|
|
struct sock *psk = ask->parent;
|
|
|
|
struct alg_sock *pask = alg_sk(psk);
|
|
|
|
struct aead_tfm *aeadc = pask->private;
|
|
|
|
struct crypto_aead *tfm = aeadc->aead;
|
|
|
|
unsigned int ivlen = crypto_aead_ivsize(tfm);
|
2015-02-28 19:50:00 +00:00
|
|
|
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
af_alg_pull_tsgl(sk, ctx->used, NULL, 0);
|
2015-02-28 19:50:00 +00:00
|
|
|
sock_kzfree_s(sk, ctx->iv, ivlen);
|
|
|
|
sock_kfree_s(sk, ctx, ctx->len);
|
|
|
|
af_alg_release_parent(sk);
|
|
|
|
}
|
|
|
|
|
2017-04-24 09:15:23 +00:00
|
|
|
static int aead_accept_parent_nokey(void *private, struct sock *sk)
|
2015-02-28 19:50:00 +00:00
|
|
|
{
|
crypto: af_alg - consolidation of duplicate code
Consolidate following data structures:
skcipher_async_req, aead_async_req -> af_alg_async_req
skcipher_rsgl, aead_rsql -> af_alg_rsgl
skcipher_tsgl, aead_tsql -> af_alg_tsgl
skcipher_ctx, aead_ctx -> af_alg_ctx
Consolidate following functions:
skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
skcipher_writable, aead_writable -> af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
skcipher_readable, aead_readable -> af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
aead_sendpage, skcipher_sendpage -> af_alg_sendpage
aead_async_cb, skcipher_async_cb -> af_alg_async_cb
aead_poll, skcipher_poll -> af_alg_poll
Split out the following common code from recvmsg:
af_alg_alloc_areq: allocation of the request data structure for the
cipher operation
af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure
The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:
The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).
af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.
af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.
af_alg_async_cb requires to store the number of output bytes in
areq->outlen before the AIO callback is triggered.
The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.
The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-08-02 05:56:19 +00:00
|
|
|
struct af_alg_ctx *ctx;
|
2015-02-28 19:50:00 +00:00
|
|
|
struct alg_sock *ask = alg_sk(sk);
|
2017-04-24 09:15:23 +00:00
|
|
|
struct aead_tfm *tfm = private;
|
|
|
|
struct crypto_aead *aead = tfm->aead;
|
2017-06-25 15:12:59 +00:00
|
|
|
unsigned int len = sizeof(*ctx);
|
2017-04-24 09:15:23 +00:00
|
|
|
unsigned int ivlen = crypto_aead_ivsize(aead);
|
2015-02-28 19:50:00 +00:00
|
|
|
|
|
|
|
ctx = sock_kmalloc(sk, len, GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
memset(ctx, 0, len);
|
|
|
|
|
|
|
|
ctx->iv = sock_kmalloc(sk, ivlen, GFP_KERNEL);
|
|
|
|
if (!ctx->iv) {
|
|
|
|
sock_kfree_s(sk, ctx, len);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memset(ctx->iv, 0, ivlen);
|
|
|
|
|
2017-06-25 15:12:59 +00:00
|
|
|
INIT_LIST_HEAD(&ctx->tsgl_list);
|
2015-02-28 19:50:00 +00:00
|
|
|
ctx->len = len;
|
2017-10-18 07:00:39 +00:00
|
|
|
crypto_init_wait(&ctx->wait);
|
2015-02-28 19:50:00 +00:00
|
|
|
|
|
|
|
ask->private = ctx;
|
|
|
|
|
|
|
|
sk->sk_destruct = aead_sock_destruct;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-24 09:15:23 +00:00
|
|
|
static int aead_accept_parent(void *private, struct sock *sk)
|
|
|
|
{
|
|
|
|
struct aead_tfm *tfm = private;
|
|
|
|
|
2018-01-03 19:16:30 +00:00
|
|
|
if (crypto_aead_get_flags(tfm->aead) & CRYPTO_TFM_NEED_KEY)
|
2017-04-24 09:15:23 +00:00
|
|
|
return -ENOKEY;
|
|
|
|
|
|
|
|
return aead_accept_parent_nokey(private, sk);
|
|
|
|
}
|
|
|
|
|
2015-02-28 19:50:00 +00:00
|
|
|
static const struct af_alg_type algif_type_aead = {
|
|
|
|
.bind = aead_bind,
|
|
|
|
.release = aead_release,
|
|
|
|
.setkey = aead_setkey,
|
|
|
|
.setauthsize = aead_setauthsize,
|
|
|
|
.accept = aead_accept_parent,
|
2017-04-24 09:15:23 +00:00
|
|
|
.accept_nokey = aead_accept_parent_nokey,
|
2015-02-28 19:50:00 +00:00
|
|
|
.ops = &algif_aead_ops,
|
2017-04-24 09:15:23 +00:00
|
|
|
.ops_nokey = &algif_aead_ops_nokey,
|
2015-02-28 19:50:00 +00:00
|
|
|
.name = "aead",
|
|
|
|
.owner = THIS_MODULE
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init algif_aead_init(void)
|
|
|
|
{
|
|
|
|
return af_alg_register_type(&algif_type_aead);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit algif_aead_exit(void)
|
|
|
|
{
|
|
|
|
int err = af_alg_unregister_type(&algif_type_aead);
|
|
|
|
BUG_ON(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(algif_aead_init);
|
|
|
|
module_exit(algif_aead_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Stephan Mueller <smueller@chronox.de>");
|
|
|
|
MODULE_DESCRIPTION("AEAD kernel crypto API user space interface");
|