Skip to content

Commit

Permalink
Sync code to OxygenOS5.0.4 OTA
Browse files Browse the repository at this point in the history
Change-Id: I7c83e245354516a2c4f79cda522cc4931628bb5f
  • Loading branch information
andersonchen committed Jul 27, 2018
1 parent 016b1f2 commit ae484a2
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 34 deletions.
5 changes: 5 additions & 0 deletions crypto/hmac.c
Expand Up @@ -194,8 +194,13 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
salg = shash_attr_alg(tb[1], 0, 0);
if (IS_ERR(salg))
return PTR_ERR(salg);
alg = &salg->base;

/* The underlying hash algorithm must be unkeyed */
err = -EINVAL;
if (crypto_shash_alg_has_setkey(salg))
goto out_put_alg;

ds = salg->digestsize;
ss = salg->statesize;
alg = &salg->base;
Expand Down
19 changes: 10 additions & 9 deletions crypto/pcrypt.c
Expand Up @@ -306,6 +306,14 @@ static void pcrypt_aead_exit_tfm(struct crypto_tfm *tfm)
crypto_free_aead(ctx->child);
}

static void pcrypt_free(struct aead_instance *inst)
{
struct pcrypt_instance_ctx *ctx = aead_instance_ctx(inst);

crypto_drop_aead(&ctx->spawn);
kfree(inst);
}

static struct crypto_instance *pcrypt_alloc_instance(struct crypto_alg *alg)
{
struct crypto_instance *inst;
Expand Down Expand Up @@ -376,6 +384,8 @@ static struct crypto_instance *pcrypt_alloc_aead(struct rtattr **tb,
inst->alg.cra_aead.decrypt = pcrypt_aead_decrypt;
inst->alg.cra_aead.givencrypt = pcrypt_aead_givencrypt;

inst->free = pcrypt_free;

out_put_alg:
crypto_mod_put(alg);
return inst;
Expand All @@ -397,14 +407,6 @@ static struct crypto_instance *pcrypt_alloc(struct rtattr **tb)
return ERR_PTR(-EINVAL);
}

static void pcrypt_free(struct crypto_instance *inst)
{
struct pcrypt_instance_ctx *ctx = crypto_instance_ctx(inst);

crypto_drop_spawn(&ctx->spawn);
kfree(inst);
}

static int pcrypt_cpumask_change_notify(struct notifier_block *self,
unsigned long val, void *data)
{
Expand Down Expand Up @@ -517,7 +519,6 @@ static void pcrypt_fini_padata(struct padata_pcrypt *pcrypt)
static struct crypto_template pcrypt_tmpl = {
.name = "pcrypt",
.alloc = pcrypt_alloc,
.free = pcrypt_free,
.module = THIS_MODULE,
};

Expand Down
3 changes: 2 additions & 1 deletion crypto/shash.c
Expand Up @@ -24,11 +24,12 @@

static const struct crypto_type crypto_shash_type;

static int shash_no_setkey(struct crypto_shash *tfm, const u8 *key,
int shash_no_setkey(struct crypto_shash *tfm, const u8 *key,
unsigned int keylen)
{
return -ENOSYS;
}
EXPORT_SYMBOL_GPL(shash_no_setkey);

static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key,
unsigned int keylen)
Expand Down
2 changes: 1 addition & 1 deletion drivers/pci/pci-sysfs.c
Expand Up @@ -544,7 +544,7 @@ static ssize_t driver_override_show(struct device *dev,
{
struct pci_dev *pdev = to_pci_dev(dev);

return snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
return sprintf(buf, "%s\n", pdev->driver_override);
}
static DEVICE_ATTR_RW(driver_override);

Expand Down
5 changes: 3 additions & 2 deletions drivers/scsi/sg.c
Expand Up @@ -2091,11 +2091,12 @@ sg_get_rq_mark(Sg_fd * sfp, int pack_id)
if ((1 == resp->done) && (!resp->sg_io_owned) &&
((-1 == pack_id) || (resp->header.pack_id == pack_id))) {
resp->done = 2; /* guard against other readers */
break;
write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
return resp;
}
}
write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
return resp;
return NULL;
}

/* always adds to end of list */
Expand Down
9 changes: 6 additions & 3 deletions drivers/usb/core/config.c
Expand Up @@ -633,18 +633,21 @@ void usb_destroy_configuration(struct usb_device *dev)
return;

if (dev->rawdescriptors) {
for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
for (i = 0; i < dev->descriptor.bNumConfigurations &&
i < USB_MAXCONFIG; i++)
kfree(dev->rawdescriptors[i]);

kfree(dev->rawdescriptors);
dev->rawdescriptors = NULL;
}

for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
for (c = 0; c < dev->descriptor.bNumConfigurations &&
c < USB_MAXCONFIG; c++) {
struct usb_host_config *cf = &dev->config[c];

kfree(cf->string);
for (i = 0; i < cf->desc.bNumInterfaces; i++) {
for (i = 0; i < cf->desc.bNumInterfaces &&
i < USB_MAXINTERFACES; i++) {
if (cf->intf_cache[i])
kref_put(&cf->intf_cache[i]->ref,
usb_release_interface_cache);
Expand Down
21 changes: 20 additions & 1 deletion drivers/usb/gadget/function/f_hid.c
Expand Up @@ -197,6 +197,13 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,
/* pick the first one */
list = list_first_entry(&hidg->completed_out_req,
struct f_hidg_req_list, list);

/*
* Remove this from list to protect it from beign free()
* while host disables our function
*/
list_del(&list->list);

req = list->req;
count = min_t(unsigned int, count, req->actual - list->pos);
spin_unlock_irqrestore(&hidg->spinlock, flags);
Expand All @@ -219,8 +226,16 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,

req->length = hidg->report_length;
ret = usb_ep_queue(hidg->out_ep, req, GFP_KERNEL);
if (ret < 0)
if (ret < 0) {
free_ep_req(hidg->out_ep, req);
return ret;
}
} else {
spin_lock_irqsave(&hidg->spinlock, flags);
list_add(&list->list, &hidg->completed_out_req);
spin_unlock_irqrestore(&hidg->spinlock, flags);

wake_up(&hidg->read_queue);
}

return count;
Expand Down Expand Up @@ -455,17 +470,21 @@ static void hidg_disable(struct usb_function *f)
{
struct f_hidg *hidg = func_to_hidg(f);
struct f_hidg_req_list *list, *next;
unsigned long flags;

usb_ep_disable(hidg->in_ep);
hidg->in_ep->driver_data = NULL;

usb_ep_disable(hidg->out_ep);
hidg->out_ep->driver_data = NULL;

spin_lock_irqsave(&hidg->spinlock, flags);
list_for_each_entry_safe(list, next, &hidg->completed_out_req, list) {
free_ep_req(hidg->out_ep, list->req);
list_del(&list->list);
kfree(list);
}
spin_unlock_irqrestore(&hidg->spinlock, flags);
}

static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
Expand Down
6 changes: 0 additions & 6 deletions drivers/usb/gadget/function/f_sourcesink.c
Expand Up @@ -435,12 +435,6 @@ static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
return alloc_ep_req(ep, len, buflen);
}

void free_ep_req(struct usb_ep *ep, struct usb_request *req)
{
kfree(req->buf);
usb_ep_free_request(ep, req);
}

static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
{
int value;
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/function/g_zero.h
Expand Up @@ -69,7 +69,6 @@ void lb_modexit(void);
int lb_modinit(void);

/* common utilities */
void free_ep_req(struct usb_ep *ep, struct usb_request *req);
void disable_endpoints(struct usb_composite_dev *cdev,
struct usb_ep *in, struct usb_ep *out,
struct usb_ep *iso_in, struct usb_ep *iso_out,
Expand Down
2 changes: 1 addition & 1 deletion fs/sdcardfs/sdcardfs.h
Expand Up @@ -655,7 +655,7 @@ static inline bool str_n_case_eq(const char *s1, const char *s2, size_t len)

static inline bool qstr_case_eq(const struct qstr *q1, const struct qstr *q2)
{
return q1->len == q2->len && str_case_eq(q1->name, q2->name);
return q1->len == q2->len && str_n_case_eq(q1->name, q2->name, q2->len);
}

/* */
Expand Down
8 changes: 8 additions & 0 deletions include/crypto/internal/hash.h
Expand Up @@ -83,6 +83,14 @@ int ahash_register_instance(struct crypto_template *tmpl,
struct ahash_instance *inst);
void ahash_free_instance(struct crypto_instance *inst);

int shash_no_setkey(struct crypto_shash *tfm, const u8 *key,
unsigned int keylen);

static inline bool crypto_shash_alg_has_setkey(struct shash_alg *alg)
{
return alg->setkey != shash_no_setkey;
}

int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,
struct hash_alg_common *alg,
struct crypto_instance *inst);
Expand Down
46 changes: 37 additions & 9 deletions security/keys/request_key.c
Expand Up @@ -250,11 +250,12 @@ static int construct_key(struct key *key, const void *callout_info,
* The keyring selected is returned with an extra reference upon it which the
* caller must release.
*/
static void construct_get_dest_keyring(struct key **_dest_keyring)
static int construct_get_dest_keyring(struct key **_dest_keyring)
{
struct request_key_auth *rka;
const struct cred *cred = current_cred();
struct key *dest_keyring = *_dest_keyring, *authkey;
int ret;

kenter("%p", dest_keyring);

Expand All @@ -263,6 +264,8 @@ static void construct_get_dest_keyring(struct key **_dest_keyring)
/* the caller supplied one */
key_get(dest_keyring);
} else {
bool do_perm_check = true;

/* use a default keyring; falling through the cases until we
* find one that we actually have */
switch (cred->jit_keyring) {
Expand All @@ -277,8 +280,10 @@ static void construct_get_dest_keyring(struct key **_dest_keyring)
dest_keyring =
key_get(rka->dest_keyring);
up_read(&authkey->sem);
if (dest_keyring)
if (dest_keyring) {
do_perm_check = false;
break;
}
}

case KEY_REQKEY_DEFL_THREAD_KEYRING:
Expand Down Expand Up @@ -313,11 +318,29 @@ static void construct_get_dest_keyring(struct key **_dest_keyring)
default:
BUG();
}

/*
* Require Write permission on the keyring. This is essential
* because the default keyring may be the session keyring, and
* joining a keyring only requires Search permission.
*
* However, this check is skipped for the "requestor keyring" so
* that /sbin/request-key can itself use request_key() to add
* keys to the original requestor's destination keyring.
*/
if (dest_keyring && do_perm_check) {
ret = key_permission(make_key_ref(dest_keyring, 1),
KEY_NEED_WRITE);
if (ret) {
key_put(dest_keyring);
return ret;
}
}
}

*_dest_keyring = dest_keyring;
kleave(" [dk %d]", key_serial(dest_keyring));
return;
return 0;
}

/*
Expand Down Expand Up @@ -438,12 +461,16 @@ static struct key *construct_key_and_link(struct keyring_search_context *ctx,
int ret;

kenter("");

ret = construct_get_dest_keyring(&dest_keyring);
if (ret)
goto error;

user = key_user_lookup(current_fsuid());
if (!user)
return ERR_PTR(-ENOMEM);

construct_get_dest_keyring(&dest_keyring);
if (!user) {
ret = -ENOMEM;
goto error_put_dest_keyring;
}

ret = construct_alloc_key(ctx, dest_keyring, flags, user, &key);
key_user_put(user);
Expand All @@ -458,7 +485,7 @@ static struct key *construct_key_and_link(struct keyring_search_context *ctx,
} else if (ret == -EINPROGRESS) {
ret = 0;
} else {
goto couldnt_alloc_key;
goto error_put_dest_keyring;
}

key_put(dest_keyring);
Expand All @@ -468,8 +495,9 @@ static struct key *construct_key_and_link(struct keyring_search_context *ctx,
construction_failed:
key_negate_and_link(key, key_negative_timeout, NULL, NULL);
key_put(key);
couldnt_alloc_key:
error_put_dest_keyring:
key_put(dest_keyring);
error:
kleave(" = %d", ret);
return ERR_PTR(ret);
}
Expand Down

0 comments on commit ae484a2

Please sign in to comment.