Merge 4.9.53 into android-4.9
Changes in 4.9.53 cifs: release cifs root_cred after exit_cifs cifs: release auth_key.response for reconnect. fs/proc: Report eip/esp in /prod/PID/stat for coredumping mac80211: fix VLAN handling with TXQs mac80211_hwsim: Use proper TX power mac80211: flush hw_roc_start work before cancelling the ROC genirq: Make sparse_irq_lock protect what it should protect KVM: PPC: Book3S: Fix race and leak in kvm_vm_ioctl_create_spapr_tce() KVM: PPC: Book3S HV: Protect updates to spapr_tce_tables list tracing: Fix trace_pipe behavior for instance traces tracing: Erase irqsoff trace with empty write md/raid5: fix a race condition in stripe batch md/raid5: preserve STRIPE_ON_UNPLUG_LIST in break_stripe_batch_list scsi: scsi_transport_iscsi: fix the issue that iscsi_if_rx doesn't parse nlmsg properly drm/radeon: disable hard reset in hibernate for APUs crypto: drbg - fix freeing of resources crypto: talitos - Don't provide setkey for non hmac hashing algs. crypto: talitos - fix sha224 crypto: talitos - fix hashing security/keys: properly zero out sensitive key material in big_key security/keys: rewrite all of big_key crypto KEYS: fix writing past end of user-supplied buffer in keyring_read() KEYS: prevent creating a different user's keyrings KEYS: prevent KEYCTL_READ on negative key powerpc/pseries: Fix parent_dn reference leak in add_dt_node() powerpc/tm: Flush TM only if CPU has TM feature powerpc/ftrace: Pass the correct stack pointer for DYNAMIC_FTRACE_WITH_REGS s390/mm: fix write access check in gup_huge_pmd() PM: core: Fix device_pm_check_callbacks() Fix SMB3.1.1 guest authentication to Samba SMB3: Warn user if trying to sign connection that authenticated as guest SMB: Validate negotiate (to protect against downgrade) even if signing off SMB3: Don't ignore O_SYNC/O_DSYNC and O_DIRECT flags vfs: Return -ENXIO for negative SEEK_HOLE / SEEK_DATA offsets nl80211: check for the required netlink attributes presence bsg-lib: don't free job in bsg_prepare_job iw_cxgb4: remove the stid on listen create failure iw_cxgb4: put ep reference in pass_accept_req() selftests/seccomp: Support glibc 2.26 siginfo_t.h seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter() arm64: Make sure SPsel is always set arm64: fault: Route pte translation faults via do_translation_fault KVM: VMX: extract __pi_post_block KVM: VMX: avoid double list add with VT-d posted interrupts KVM: VMX: simplify and fix vmx_vcpu_pi_load kvm/x86: Handle async PF in RCU read-side critical sections KVM: VMX: Do not BUG() on out-of-bounds guest IRQ kvm: nVMX: Don't allow L2 to access the hardware CR8 xfs: validate bdev support for DAX inode flag etnaviv: fix gem object list corruption PCI: Fix race condition with driver_override btrfs: fix NULL pointer dereference from free_reloc_roots() btrfs: propagate error to btrfs_cmp_data_prepare caller btrfs: prevent to set invalid default subvolid x86/mm: Fix fault error path using unsafe vma pointer x86/fpu: Don't let userspace set bogus xcomp_bv gfs2: Fix debugfs glocks dump timer/sysclt: Restrict timer migration sysctl values to 0 and 1 KVM: VMX: do not change SN bit in vmx_update_pi_irte() KVM: VMX: remove WARN_ON_ONCE in kvm_vcpu_trigger_posted_interrupt cxl: Fix driver use count KVM: VMX: use cmpxchg64 video: fbdev: aty: do not leak uninitialized padding in clk to userspace swiotlb-xen: implement xen_swiotlb_dma_mmap callback Linux 4.9.53 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -41,10 +41,8 @@ config BIG_KEYS
|
||||
bool "Large payload keys"
|
||||
depends on KEYS
|
||||
depends on TMPFS
|
||||
depends on (CRYPTO_ANSI_CPRNG = y || CRYPTO_DRBG = y)
|
||||
select CRYPTO_AES
|
||||
select CRYPTO_ECB
|
||||
select CRYPTO_RNG
|
||||
select CRYPTO_GCM
|
||||
help
|
||||
This option provides support for holding large keys within the kernel
|
||||
(for example Kerberos ticket caches). The data may be stored out to
|
||||
|
||||
+63
-73
@@ -1,5 +1,6 @@
|
||||
/* Large capacity key type
|
||||
*
|
||||
* Copyright (C) 2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
||||
* Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
|
||||
* Written by David Howells (dhowells@redhat.com)
|
||||
*
|
||||
@@ -16,10 +17,10 @@
|
||||
#include <linux/shmem_fs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/random.h>
|
||||
#include <keys/user-type.h>
|
||||
#include <keys/big_key-type.h>
|
||||
#include <crypto/rng.h>
|
||||
#include <crypto/skcipher.h>
|
||||
#include <crypto/aead.h>
|
||||
|
||||
/*
|
||||
* Layout of key payload words.
|
||||
@@ -49,7 +50,12 @@ enum big_key_op {
|
||||
/*
|
||||
* Key size for big_key data encryption
|
||||
*/
|
||||
#define ENC_KEY_SIZE 16
|
||||
#define ENC_KEY_SIZE 32
|
||||
|
||||
/*
|
||||
* Authentication tag length
|
||||
*/
|
||||
#define ENC_AUTHTAG_SIZE 16
|
||||
|
||||
/*
|
||||
* big_key defined keys take an arbitrary string as the description and an
|
||||
@@ -64,57 +70,62 @@ struct key_type key_type_big_key = {
|
||||
.destroy = big_key_destroy,
|
||||
.describe = big_key_describe,
|
||||
.read = big_key_read,
|
||||
/* no ->update(); don't add it without changing big_key_crypt() nonce */
|
||||
};
|
||||
|
||||
/*
|
||||
* Crypto names for big_key data encryption
|
||||
* Crypto names for big_key data authenticated encryption
|
||||
*/
|
||||
static const char big_key_rng_name[] = "stdrng";
|
||||
static const char big_key_alg_name[] = "ecb(aes)";
|
||||
static const char big_key_alg_name[] = "gcm(aes)";
|
||||
|
||||
/*
|
||||
* Crypto algorithms for big_key data encryption
|
||||
* Crypto algorithms for big_key data authenticated encryption
|
||||
*/
|
||||
static struct crypto_rng *big_key_rng;
|
||||
static struct crypto_skcipher *big_key_skcipher;
|
||||
static struct crypto_aead *big_key_aead;
|
||||
|
||||
/*
|
||||
* Generate random key to encrypt big_key data
|
||||
* Since changing the key affects the entire object, we need a mutex.
|
||||
*/
|
||||
static inline int big_key_gen_enckey(u8 *key)
|
||||
{
|
||||
return crypto_rng_get_bytes(big_key_rng, key, ENC_KEY_SIZE);
|
||||
}
|
||||
static DEFINE_MUTEX(big_key_aead_lock);
|
||||
|
||||
/*
|
||||
* Encrypt/decrypt big_key data
|
||||
*/
|
||||
static int big_key_crypt(enum big_key_op op, u8 *data, size_t datalen, u8 *key)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
int ret;
|
||||
struct scatterlist sgio;
|
||||
SKCIPHER_REQUEST_ON_STACK(req, big_key_skcipher);
|
||||
struct aead_request *aead_req;
|
||||
/* We always use a zero nonce. The reason we can get away with this is
|
||||
* because we're using a different randomly generated key for every
|
||||
* different encryption. Notably, too, key_type_big_key doesn't define
|
||||
* an .update function, so there's no chance we'll wind up reusing the
|
||||
* key to encrypt updated data. Simply put: one key, one encryption.
|
||||
*/
|
||||
u8 zero_nonce[crypto_aead_ivsize(big_key_aead)];
|
||||
|
||||
if (crypto_skcipher_setkey(big_key_skcipher, key, ENC_KEY_SIZE)) {
|
||||
aead_req = aead_request_alloc(big_key_aead, GFP_KERNEL);
|
||||
if (!aead_req)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(zero_nonce, 0, sizeof(zero_nonce));
|
||||
sg_init_one(&sgio, data, datalen + (op == BIG_KEY_ENC ? ENC_AUTHTAG_SIZE : 0));
|
||||
aead_request_set_crypt(aead_req, &sgio, &sgio, datalen, zero_nonce);
|
||||
aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
|
||||
aead_request_set_ad(aead_req, 0);
|
||||
|
||||
mutex_lock(&big_key_aead_lock);
|
||||
if (crypto_aead_setkey(big_key_aead, key, ENC_KEY_SIZE)) {
|
||||
ret = -EAGAIN;
|
||||
goto error;
|
||||
}
|
||||
|
||||
skcipher_request_set_tfm(req, big_key_skcipher);
|
||||
skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP,
|
||||
NULL, NULL);
|
||||
|
||||
sg_init_one(&sgio, data, datalen);
|
||||
skcipher_request_set_crypt(req, &sgio, &sgio, datalen, NULL);
|
||||
|
||||
if (op == BIG_KEY_ENC)
|
||||
ret = crypto_skcipher_encrypt(req);
|
||||
ret = crypto_aead_encrypt(aead_req);
|
||||
else
|
||||
ret = crypto_skcipher_decrypt(req);
|
||||
|
||||
skcipher_request_zero(req);
|
||||
|
||||
ret = crypto_aead_decrypt(aead_req);
|
||||
error:
|
||||
mutex_unlock(&big_key_aead_lock);
|
||||
aead_request_free(aead_req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -146,15 +157,13 @@ int big_key_preparse(struct key_preparsed_payload *prep)
|
||||
*
|
||||
* File content is stored encrypted with randomly generated key.
|
||||
*/
|
||||
size_t enclen = ALIGN(datalen, crypto_skcipher_blocksize(big_key_skcipher));
|
||||
size_t enclen = datalen + ENC_AUTHTAG_SIZE;
|
||||
|
||||
/* prepare aligned data to encrypt */
|
||||
data = kmalloc(enclen, GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(data, prep->data, datalen);
|
||||
memset(data + datalen, 0x00, enclen - datalen);
|
||||
|
||||
/* generate random key */
|
||||
enckey = kmalloc(ENC_KEY_SIZE, GFP_KERNEL);
|
||||
@@ -162,13 +171,10 @@ int big_key_preparse(struct key_preparsed_payload *prep)
|
||||
ret = -ENOMEM;
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = big_key_gen_enckey(enckey);
|
||||
if (ret)
|
||||
goto err_enckey;
|
||||
get_random_bytes(enckey, ENC_KEY_SIZE);
|
||||
|
||||
/* encrypt aligned data */
|
||||
ret = big_key_crypt(BIG_KEY_ENC, data, enclen, enckey);
|
||||
ret = big_key_crypt(BIG_KEY_ENC, data, datalen, enckey);
|
||||
if (ret)
|
||||
goto err_enckey;
|
||||
|
||||
@@ -194,7 +200,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
|
||||
*path = file->f_path;
|
||||
path_get(path);
|
||||
fput(file);
|
||||
kfree(data);
|
||||
kzfree(data);
|
||||
} else {
|
||||
/* Just store the data in a buffer */
|
||||
void *data = kmalloc(datalen, GFP_KERNEL);
|
||||
@@ -210,9 +216,9 @@ int big_key_preparse(struct key_preparsed_payload *prep)
|
||||
err_fput:
|
||||
fput(file);
|
||||
err_enckey:
|
||||
kfree(enckey);
|
||||
kzfree(enckey);
|
||||
error:
|
||||
kfree(data);
|
||||
kzfree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -226,7 +232,7 @@ void big_key_free_preparse(struct key_preparsed_payload *prep)
|
||||
|
||||
path_put(path);
|
||||
}
|
||||
kfree(prep->payload.data[big_key_data]);
|
||||
kzfree(prep->payload.data[big_key_data]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -258,7 +264,7 @@ void big_key_destroy(struct key *key)
|
||||
path->mnt = NULL;
|
||||
path->dentry = NULL;
|
||||
}
|
||||
kfree(key->payload.data[big_key_data]);
|
||||
kzfree(key->payload.data[big_key_data]);
|
||||
key->payload.data[big_key_data] = NULL;
|
||||
}
|
||||
|
||||
@@ -294,7 +300,7 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
|
||||
struct file *file;
|
||||
u8 *data;
|
||||
u8 *enckey = (u8 *)key->payload.data[big_key_data];
|
||||
size_t enclen = ALIGN(datalen, crypto_skcipher_blocksize(big_key_skcipher));
|
||||
size_t enclen = datalen + ENC_AUTHTAG_SIZE;
|
||||
|
||||
data = kmalloc(enclen, GFP_KERNEL);
|
||||
if (!data)
|
||||
@@ -326,7 +332,7 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
|
||||
err_fput:
|
||||
fput(file);
|
||||
error:
|
||||
kfree(data);
|
||||
kzfree(data);
|
||||
} else {
|
||||
ret = datalen;
|
||||
if (copy_to_user(buffer, key->payload.data[big_key_data],
|
||||
@@ -342,47 +348,31 @@ error:
|
||||
*/
|
||||
static int __init big_key_init(void)
|
||||
{
|
||||
struct crypto_skcipher *cipher;
|
||||
struct crypto_rng *rng;
|
||||
int ret;
|
||||
|
||||
rng = crypto_alloc_rng(big_key_rng_name, 0, 0);
|
||||
if (IS_ERR(rng)) {
|
||||
pr_err("Can't alloc rng: %ld\n", PTR_ERR(rng));
|
||||
return PTR_ERR(rng);
|
||||
}
|
||||
|
||||
big_key_rng = rng;
|
||||
|
||||
/* seed RNG */
|
||||
ret = crypto_rng_reset(rng, NULL, crypto_rng_seedsize(rng));
|
||||
if (ret) {
|
||||
pr_err("Can't reset rng: %d\n", ret);
|
||||
goto error_rng;
|
||||
}
|
||||
|
||||
/* init block cipher */
|
||||
cipher = crypto_alloc_skcipher(big_key_alg_name, 0, CRYPTO_ALG_ASYNC);
|
||||
if (IS_ERR(cipher)) {
|
||||
ret = PTR_ERR(cipher);
|
||||
big_key_aead = crypto_alloc_aead(big_key_alg_name, 0, CRYPTO_ALG_ASYNC);
|
||||
if (IS_ERR(big_key_aead)) {
|
||||
ret = PTR_ERR(big_key_aead);
|
||||
pr_err("Can't alloc crypto: %d\n", ret);
|
||||
goto error_rng;
|
||||
return ret;
|
||||
}
|
||||
ret = crypto_aead_setauthsize(big_key_aead, ENC_AUTHTAG_SIZE);
|
||||
if (ret < 0) {
|
||||
pr_err("Can't set crypto auth tag len: %d\n", ret);
|
||||
goto free_aead;
|
||||
}
|
||||
|
||||
big_key_skcipher = cipher;
|
||||
|
||||
ret = register_key_type(&key_type_big_key);
|
||||
if (ret < 0) {
|
||||
pr_err("Can't register type: %d\n", ret);
|
||||
goto error_cipher;
|
||||
goto free_aead;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_cipher:
|
||||
crypto_free_skcipher(big_key_skcipher);
|
||||
error_rng:
|
||||
crypto_free_rng(big_key_rng);
|
||||
free_aead:
|
||||
crypto_free_aead(big_key_aead);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ extern key_ref_t keyring_search_aux(key_ref_t keyring_ref,
|
||||
extern key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx);
|
||||
extern key_ref_t search_process_keyrings(struct keyring_search_context *ctx);
|
||||
|
||||
extern struct key *find_keyring_by_name(const char *name, bool skip_perm_check);
|
||||
extern struct key *find_keyring_by_name(const char *name, bool uid_keyring);
|
||||
|
||||
extern int install_user_keyrings(void);
|
||||
extern int install_thread_keyring_to_cred(struct cred *);
|
||||
|
||||
@@ -301,6 +301,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
|
||||
key->flags |= 1 << KEY_FLAG_IN_QUOTA;
|
||||
if (flags & KEY_ALLOC_BUILT_IN)
|
||||
key->flags |= 1 << KEY_FLAG_BUILTIN;
|
||||
if (flags & KEY_ALLOC_UID_KEYRING)
|
||||
key->flags |= 1 << KEY_FLAG_UID_KEYRING;
|
||||
|
||||
#ifdef KEY_DEBUGGING
|
||||
key->magic = KEY_DEBUG_MAGIC;
|
||||
|
||||
@@ -766,6 +766,11 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
|
||||
|
||||
key = key_ref_to_ptr(key_ref);
|
||||
|
||||
if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) {
|
||||
ret = -ENOKEY;
|
||||
goto error2;
|
||||
}
|
||||
|
||||
/* see if we can read it directly */
|
||||
ret = key_permission(key_ref, KEY_NEED_READ);
|
||||
if (ret == 0)
|
||||
|
||||
+19
-18
@@ -416,7 +416,7 @@ static void keyring_describe(const struct key *keyring, struct seq_file *m)
|
||||
}
|
||||
|
||||
struct keyring_read_iterator_context {
|
||||
size_t qty;
|
||||
size_t buflen;
|
||||
size_t count;
|
||||
key_serial_t __user *buffer;
|
||||
};
|
||||
@@ -428,9 +428,9 @@ static int keyring_read_iterator(const void *object, void *data)
|
||||
int ret;
|
||||
|
||||
kenter("{%s,%d},,{%zu/%zu}",
|
||||
key->type->name, key->serial, ctx->count, ctx->qty);
|
||||
key->type->name, key->serial, ctx->count, ctx->buflen);
|
||||
|
||||
if (ctx->count >= ctx->qty)
|
||||
if (ctx->count >= ctx->buflen)
|
||||
return 1;
|
||||
|
||||
ret = put_user(key->serial, ctx->buffer);
|
||||
@@ -465,16 +465,12 @@ static long keyring_read(const struct key *keyring,
|
||||
return 0;
|
||||
|
||||
/* Calculate how much data we could return */
|
||||
ctx.qty = nr_keys * sizeof(key_serial_t);
|
||||
|
||||
if (!buffer || !buflen)
|
||||
return ctx.qty;
|
||||
|
||||
if (buflen > ctx.qty)
|
||||
ctx.qty = buflen;
|
||||
return nr_keys * sizeof(key_serial_t);
|
||||
|
||||
/* Copy the IDs of the subscribed keys into the buffer */
|
||||
ctx.buffer = (key_serial_t __user *)buffer;
|
||||
ctx.buflen = buflen;
|
||||
ctx.count = 0;
|
||||
ret = assoc_array_iterate(&keyring->keys, keyring_read_iterator, &ctx);
|
||||
if (ret < 0) {
|
||||
@@ -989,15 +985,15 @@ found:
|
||||
/*
|
||||
* Find a keyring with the specified name.
|
||||
*
|
||||
* All named keyrings in the current user namespace are searched, provided they
|
||||
* grant Search permission directly to the caller (unless this check is
|
||||
* skipped). Keyrings whose usage points have reached zero or who have been
|
||||
* revoked are skipped.
|
||||
* Only keyrings that have nonzero refcount, are not revoked, and are owned by a
|
||||
* user in the current user namespace are considered. If @uid_keyring is %true,
|
||||
* the keyring additionally must have been allocated as a user or user session
|
||||
* keyring; otherwise, it must grant Search permission directly to the caller.
|
||||
*
|
||||
* Returns a pointer to the keyring with the keyring's refcount having being
|
||||
* incremented on success. -ENOKEY is returned if a key could not be found.
|
||||
*/
|
||||
struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
|
||||
struct key *find_keyring_by_name(const char *name, bool uid_keyring)
|
||||
{
|
||||
struct key *keyring;
|
||||
int bucket;
|
||||
@@ -1025,10 +1021,15 @@ struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
|
||||
if (strcmp(keyring->description, name) != 0)
|
||||
continue;
|
||||
|
||||
if (!skip_perm_check &&
|
||||
key_permission(make_key_ref(keyring, 0),
|
||||
KEY_NEED_SEARCH) < 0)
|
||||
continue;
|
||||
if (uid_keyring) {
|
||||
if (!test_bit(KEY_FLAG_UID_KEYRING,
|
||||
&keyring->flags))
|
||||
continue;
|
||||
} else {
|
||||
if (key_permission(make_key_ref(keyring, 0),
|
||||
KEY_NEED_SEARCH) < 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* we've got a match but we might end up racing with
|
||||
* key_cleanup() if the keyring is currently 'dead'
|
||||
|
||||
@@ -76,7 +76,8 @@ int install_user_keyrings(void)
|
||||
if (IS_ERR(uid_keyring)) {
|
||||
uid_keyring = keyring_alloc(buf, user->uid, INVALID_GID,
|
||||
cred, user_keyring_perm,
|
||||
KEY_ALLOC_IN_QUOTA,
|
||||
KEY_ALLOC_UID_KEYRING |
|
||||
KEY_ALLOC_IN_QUOTA,
|
||||
NULL, NULL);
|
||||
if (IS_ERR(uid_keyring)) {
|
||||
ret = PTR_ERR(uid_keyring);
|
||||
@@ -93,7 +94,8 @@ int install_user_keyrings(void)
|
||||
session_keyring =
|
||||
keyring_alloc(buf, user->uid, INVALID_GID,
|
||||
cred, user_keyring_perm,
|
||||
KEY_ALLOC_IN_QUOTA,
|
||||
KEY_ALLOC_UID_KEYRING |
|
||||
KEY_ALLOC_IN_QUOTA,
|
||||
NULL, NULL);
|
||||
if (IS_ERR(session_keyring)) {
|
||||
ret = PTR_ERR(session_keyring);
|
||||
|
||||
Reference in New Issue
Block a user