Uh oh!
There was an error while loading. Please reload this page.
forked from torvalds/linux
- Notifications
You must be signed in to change notification settings - Fork 150
Fix arithmetic overflows#2383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Fix arithmetic overflows #2383
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -221,7 +221,6 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol, | ||
| struct sof_ipc_ctrl_data *cdata = scontrol->control_data; | ||
| struct sof_abi_hdr *data = cdata->data; | ||
| size_t size; | ||
| int ret = 0; | ||
| if (be->max > sizeof(ucontrol->value.bytes.data)) { | ||
| dev_err_ratelimited(scomp->dev, | ||
| @@ -230,20 +229,20 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol, | ||
| return -EINVAL; | ||
| } | ||
| size = data->size + sizeof(*data); | ||
| if (size > be->max) { | ||
| /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ | ||
| if (data->size > be->max - sizeof(*data)) { | ||
| dev_err_ratelimited(scomp->dev, | ||
| "error: DSP sent %zu bytes max is %d\n", | ||
| size, be->max); | ||
| ret = -EINVAL; | ||
| goto out; | ||
| "error: %u bytes of control data is invalid, max is %lu\n", | ||
| data->size, be->max - sizeof(*data)); | ||
ranj063 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return -EINVAL; | ||
| } | ||
| size = data->size + sizeof(*data); | ||
| /* copy back to kcontrol */ | ||
| memcpy(ucontrol->value.bytes.data, data, size); | ||
| out: | ||
| return ret; | ||
| return 0; | ||
| } | ||
| int snd_sof_bytes_put(struct snd_kcontrol *kcontrol, | ||
| @@ -255,7 +254,7 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol, | ||
| struct snd_soc_component *scomp = scontrol->scomp; | ||
| struct sof_ipc_ctrl_data *cdata = scontrol->control_data; | ||
| struct sof_abi_hdr *data = cdata->data; | ||
| size_t size = data->size + sizeof(*data); | ||
| size_t size; | ||
| if (be->max > sizeof(ucontrol->value.bytes.data)) { | ||
| dev_err_ratelimited(scomp->dev, | ||
| @@ -264,13 +263,16 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol, | ||
| return -EINVAL; | ||
| } | ||
| if (size > be->max) { | ||
| /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ | ||
| if (data->size > be->max - sizeof(*data)) { | ||
| dev_err_ratelimited(scomp->dev, | ||
| "error: size too big %zu bytes max is %d\n", | ||
| size, be->max); | ||
| "error: data size too big %u bytes max is %lu\n", | ||
| data->size, be->max - sizeof(*data)); | ||
| return -EINVAL; | ||
| } | ||
| size = data->size + sizeof(*data); | ||
| /* copy from kcontrol */ | ||
| memcpy(data, ucontrol->value.bytes.data, size); | ||
| @@ -337,7 +339,8 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol, | ||
| return -EINVAL; | ||
| } | ||
| if (cdata->data->size + sizeof(const struct sof_abi_hdr) > be->max) { | ||
| /* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ | ||
| if (cdata->data->size > be->max - sizeof(const struct sof_abi_hdr)) { | ||
| dev_err_ratelimited(scomp->dev, "error: Mismatch in ABI data size (truncated?).\n"); | ||
| return -EINVAL; | ||
| } | ||
| @@ -423,8 +426,7 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol, | ||
| struct snd_ctl_tlv header; | ||
| struct snd_ctl_tlv __user *tlvd = | ||
| (struct snd_ctl_tlv __user *)binary_data; | ||
| int data_size; | ||
| int ret = 0; | ||
| size_t data_size; | ||
| /* | ||
| * Decrement the limit by ext bytes header size to | ||
| @@ -436,27 +438,22 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol, | ||
| cdata->data->magic = SOF_ABI_MAGIC; | ||
| cdata->data->abi = SOF_ABI_VERSION; | ||
| /* Prevent read of other kernel data or possibly corrupt response */ | ||
| data_size = cdata->data->size + sizeof(const struct sof_abi_hdr); | ||
| /* check data size doesn't exceed max coming from topology */ | ||
| if (data_size > be->max) { | ||
| dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %d.\n", | ||
| data_size, be->max); | ||
| ret = -EINVAL; | ||
| goto out; | ||
| if (cdata->data->size > be->max - sizeof(const struct sof_abi_hdr)) { | ||
| dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %lu.\n", | ||
| cdata->data->size, be->max - sizeof(const struct sof_abi_hdr)); | ||
| return -EINVAL; | ||
| } | ||
| data_size = cdata->data->size + sizeof(const struct sof_abi_hdr); | ||
| header.numid = scontrol->cmd; | ||
| header.length = data_size; | ||
| if (copy_to_user(tlvd, &header, sizeof(const struct snd_ctl_tlv))) { | ||
| ret = -EFAULT; | ||
| goto out; | ||
| } | ||
| if (copy_to_user(tlvd, &header, sizeof(const struct snd_ctl_tlv))) | ||
| return -EFAULT; | ||
| if (copy_to_user(tlvd->tlv, cdata->data, data_size)) | ||
| ret = -EFAULT; | ||
| return -EFAULT; | ||
| out: | ||
| return ret; | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.