Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Documentation/crypto/userspace-if.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ performed by the consumer:
system calls to send data to the kernel or obtain data from the
kernel, the file descriptor returned by accept must be used.

.. caution::

Support for hardware cryptographic accelerators has been removed from
AF_ALG. Only algorithms implemented in software are now accessible
through this interface. Hardware accelerator drivers are frequently
buggy, and removing their exposure via AF_ALG reduces the kernel's
attack surface. This means AF_ALG no longer fulfills its original
purpose of providing access to off-CPU cryptography.

In-place Cipher operation
-------------------------

Expand Down
2 changes: 1 addition & 1 deletion crypto/af_alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
if (IS_ERR(type))
return PTR_ERR(type);

private = type->bind(sa->salg_name, sa->salg_feat, sa->salg_mask);
private = type->bind(sa->salg_name);
if (IS_ERR(private)) {
module_put(type->owner);
return PTR_ERR(private);
Expand Down
4 changes: 2 additions & 2 deletions crypto/algif_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ static struct proto_ops algif_aead_ops_nokey = {
.poll = af_alg_poll,
};

static void *aead_bind(const char *name, u32 type, u32 mask)
static void *aead_bind(const char *name)
{
return crypto_alloc_aead(name, type, mask);
return crypto_alloc_aead(name, 0, AF_ALG_CRYPTOAPI_MASK);
}

static void aead_release(void *private)
Expand Down
4 changes: 2 additions & 2 deletions crypto/algif_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ static struct proto_ops algif_hash_ops_nokey = {
.accept = hash_accept_nokey,
};

static void *hash_bind(const char *name, u32 type, u32 mask)
static void *hash_bind(const char *name)
{
return crypto_alloc_ahash(name, type, mask);
return crypto_alloc_ahash(name, 0, AF_ALG_CRYPTOAPI_MASK);
}

static void hash_release(void *private)
Expand Down
4 changes: 2 additions & 2 deletions crypto/algif_rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static struct proto_ops __maybe_unused algif_rng_test_ops = {
.sendmsg = rng_test_sendmsg,
};

static void *rng_bind(const char *name, u32 type, u32 mask)
static void *rng_bind(const char *name)
{
struct rng_parent_ctx *pctx;
struct crypto_rng *rng;
Expand All @@ -206,7 +206,7 @@ static void *rng_bind(const char *name, u32 type, u32 mask)
if (!pctx)
return ERR_PTR(-ENOMEM);

rng = crypto_alloc_rng(name, type, mask);
rng = crypto_alloc_rng(name, 0, AF_ALG_CRYPTOAPI_MASK);
if (IS_ERR(rng)) {
kfree(pctx);
return ERR_CAST(rng);
Expand Down
4 changes: 2 additions & 2 deletions crypto/algif_skcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ static struct proto_ops algif_skcipher_ops_nokey = {
.poll = af_alg_poll,
};

static void *skcipher_bind(const char *name, u32 type, u32 mask)
static void *skcipher_bind(const char *name)
{
return crypto_alloc_skcipher(name, type, mask);
return crypto_alloc_skcipher(name, 0, AF_ALG_CRYPTOAPI_MASK);
}

static void skcipher_release(void *private)
Expand Down
14 changes: 13 additions & 1 deletion include/crypto/if_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct af_alg_control {
};

struct af_alg_type {
void *(*bind)(const char *name, u32 type, u32 mask);
void *(*bind)(const char *name);
void (*release)(void *private);
int (*setkey)(void *private, const u8 *key, unsigned int keylen);
int (*setentropy)(void *private, sockptr_t entropy, unsigned int len);
Expand Down Expand Up @@ -253,4 +253,16 @@ int af_alg_get_rsgl(struct sock *sk, struct msghdr *msg, int flags,
struct af_alg_async_req *areq, size_t maxsize,
size_t *outlen);

/*
* Mask used to disable unsupported algorithm implementations.
*
* This is the same as FSCRYPT_CRYPTOAPI_MASK in fs/crypto/fscrypt_private.h.
* In additions to the motivations there, this API is exposed to userspace
* that might not be fully trusted.
Comment on lines +259 to +261
*/
#define AF_ALG_CRYPTOAPI_MASK \
(CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | \
CRYPTO_ALG_KERN_DRIVER_ONLY)


#endif /* _CRYPTO_IF_ALG_H */
Loading