-
Notifications
You must be signed in to change notification settings - Fork 361
Tplg parser security fixes #10896
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
Open
jsarha
wants to merge
4
commits into
thesofproject:main
Choose a base branch
from
jsarha:tplg_parser_security_fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−21
Open
Tplg parser security fixes #10896
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b13f7fd
tools: tplg_parser: add bounds checking to topology object reader macros
da99850
tools: tplg_parser: Add () around all macro argument instances
8e55266
tools: tplg_parser: fix stack buffer overflow in tplg_create_graph()
d1ffb2b
tools: probes: reject oversized data_size_bytes to prevent integer ov…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
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 |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |
| #include <stdbool.h> | ||
| #include <stdarg.h> | ||
| #include <stddef.h> | ||
| #include <assert.h> | ||
| #include <stdio.h> | ||
| #include <ipc/dai.h> | ||
| #include <ipc/topology.h> | ||
| #include <ipc/stream.h> | ||
|
|
@@ -194,43 +196,65 @@ struct tplg_context { | |
|
|
||
| #define tplg_get(ctx) ((void *)(ctx->tplg_base + ctx->tplg_offset)) | ||
|
|
||
| #define tplg_check_bounds(ctx, advance) \ | ||
| do { \ | ||
| if ((long)(advance) < 0 || \ | ||
| (ctx)->tplg_offset + (long)(advance) > (long)(ctx)->tplg_size) { \ | ||
| printf("%s %d topology offset %ld + %ld > size %zu\n", \ | ||
| __func__, __LINE__, (ctx)->tplg_offset, \ | ||
| (long)(advance), (ctx)->tplg_size); \ | ||
| exit(1); \ | ||
| } \ | ||
| } while (0) | ||
|
Comment on lines
+199
to
+208
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will put an exit(1) there instead. |
||
|
|
||
| #define tplg_get_hdr(ctx) \ | ||
| ({struct snd_soc_tplg_hdr *ptr; \ | ||
| ptr = (struct snd_soc_tplg_hdr *)(ctx->tplg_base + ctx->tplg_offset); \ | ||
| tplg_check_bounds(ctx, sizeof(*ptr)); \ | ||
| ptr = (struct snd_soc_tplg_hdr *)((ctx)->tplg_base + (ctx)->tplg_offset); \ | ||
| if (ptr->size != sizeof(*ptr)) { \ | ||
| printf("%s %d hdr size mismatch 0x%x:0x%zx at offset %ld\n", \ | ||
| __func__, __LINE__, ptr->size, sizeof(*ptr), \ | ||
| ctx->tplg_offset); assert(0); \ | ||
| (ctx)->tplg_offset); assert(0); \ | ||
| } \ | ||
| ctx->tplg_offset += sizeof(*ptr); (void *)ptr; }) | ||
|
|
||
| #define tplg_skip_hdr_payload(ctx) \ | ||
| ({struct snd_soc_tplg_hdr *ptr; \ | ||
| ptr = (struct snd_soc_tplg_hdr *)(ctx->tplg_base + ctx->tplg_offset); \ | ||
| ctx->tplg_offset += hdr->payload_size; (void *)ptr; }) | ||
| tplg_check_bounds(ctx, hdr->payload_size); \ | ||
| ptr = (struct snd_soc_tplg_hdr *)((ctx)->tplg_base + (ctx)->tplg_offset); \ | ||
| (ctx)->tplg_offset += hdr->payload_size; (void *)ptr; }) | ||
|
|
||
| #define tplg_get_object(ctx, obj) \ | ||
| ({void *ptr; ptr = ctx->tplg_base + ctx->tplg_offset; \ | ||
| ctx->tplg_offset += sizeof(*(obj)); ptr; }) | ||
| ({void *ptr; \ | ||
| tplg_check_bounds(ctx, sizeof(*(obj))); \ | ||
| ptr = (ctx)->tplg_base + (ctx)->tplg_offset; \ | ||
| (ctx)->tplg_offset += sizeof(*(obj)); ptr; }) | ||
|
|
||
| #define tplg_get_object_priv(ctx, obj, priv_size) \ | ||
| ({void *ptr; ptr = ctx->tplg_base + ctx->tplg_offset; \ | ||
| ctx->tplg_offset += sizeof(*(obj)) + priv_size; ptr; }) | ||
| ({void *ptr; \ | ||
| tplg_check_bounds(ctx, sizeof(*(obj)) + (priv_size)); \ | ||
| ptr = (ctx)->tplg_base + (ctx)->tplg_offset; \ | ||
| (ctx)->tplg_offset += sizeof(*(obj)) + (priv_size); ptr; }) | ||
|
|
||
| #define tplg_get_widget(ctx) \ | ||
| ({struct snd_soc_tplg_dapm_widget *w; \ | ||
| w = (struct snd_soc_tplg_dapm_widget *)(ctx->tplg_base + ctx->tplg_offset); \ | ||
| ctx->tplg_offset += sizeof(*w) + w->priv.size; w; }) | ||
| tplg_check_bounds(ctx, sizeof(*w)); \ | ||
| w = (struct snd_soc_tplg_dapm_widget *)((ctx)->tplg_base + (ctx)->tplg_offset); \ | ||
| tplg_check_bounds(ctx, sizeof(*w) + w->priv.size); \ | ||
| (ctx)->tplg_offset += sizeof(*w) + w->priv.size; w; }) | ||
|
|
||
| #define tplg_get_graph(ctx) \ | ||
| ({struct snd_soc_tplg_dapm_graph_elem *w; \ | ||
| w = (struct snd_soc_tplg_dapm_graph_elem *)(ctx->tplg_base + ctx->tplg_offset); \ | ||
| ctx->tplg_offset += sizeof(*w); w; }) | ||
| tplg_check_bounds(ctx, sizeof(*w)); \ | ||
| w = (struct snd_soc_tplg_dapm_graph_elem *)((ctx)->tplg_base + (ctx)->tplg_offset); \ | ||
| (ctx)->tplg_offset += sizeof(*w); w; }) | ||
|
|
||
| #define tplg_get_pcm(ctx) \ | ||
| ({struct snd_soc_tplg_pcm *pcm; \ | ||
| pcm = (struct snd_soc_tplg_pcm *)(ctx->tplg_base + ctx->tplg_offset); \ | ||
| ctx->tplg_offset += sizeof(*pcm) + pcm->priv.size; pcm; }) | ||
| tplg_check_bounds(ctx, sizeof(*pcm)); \ | ||
| pcm = (struct snd_soc_tplg_pcm *)((ctx)->tplg_base + (ctx)->tplg_offset); \ | ||
| tplg_check_bounds(ctx, sizeof(*pcm) + pcm->priv.size); \ | ||
| (ctx)->tplg_offset += sizeof(*pcm) + pcm->priv.size; pcm; }) | ||
|
|
||
| static inline int tplg_valid_widget(struct snd_soc_tplg_dapm_widget *widget) | ||
| { | ||
|
|
@@ -314,6 +338,7 @@ int tplg_new_process(struct tplg_context *ctx, void *process, size_t process_siz | |
|
|
||
| int tplg_create_graph(struct tplg_context *ctx, int count, int pipeline_id, | ||
| struct tplg_comp_info *temp_comp_list, char *pipeline_string, | ||
| size_t pipeline_string_size, | ||
| struct sof_ipc_pipe_comp_connect *connection, | ||
| int route_num); | ||
|
|
||
|
|
||
Oops, something went wrong.
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.