Skip to content
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

ipc3: Add size checks on ipc subtypes #9297

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

cujomalainey
Copy link
Member

We have a few gaps in input validation from the kernel. Right now we check the IPC doesn't claim its larger the window, this patch adds the following checks:

  1. That the IPC size is at least large enough for any downcast type on comp new
  2. That any reported size for a process total size is less than the IPC window.

@cujomalainey
Copy link
Member Author

Pushed as draft as validation is still ongoing but I wanted early input

@cujomalainey
Copy link
Member Author

whoops, was building IPC4 when testing, not IPC3, will fix tomorrow

@@ -29,6 +29,9 @@ struct ipc_msg;
#define IPC_IS_SIZE_INVALID(object) \
(object).hdr.size == sizeof(object) ? 0 : 1

#define IPC_TAIL_IS_SIZE_INVALID(object) \
(object).hdr.size + (object).ext_data_length == sizeof(object) ? 0 : 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the very least maybe IPC_TAIL_SIZE_IS_INVALID() and ideally I'd make this

#define IPC_TAIL_SIZE_IS_VALID(object) \
	((object).hdr.size + (object).ext_data_length == sizeof(object))

because in general affirmative names might be easier to work with, and the == comparison already returns a perfect boolean result, but the definition above already does the other way, so...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather IPC_TAIL_IS_SIZE_INVALID to keep the naming semantics the same as above or update the one above to match your suggestion. But i rather not deviate on this alone.

Seconded on the brackets, i thought that was weird, not sure why they were ommitted

I am not sure either, it is the same as using != I am really not sure what is going on with that macro, i can update both to keep them the same

Looks like @lgirdwood was the original author of the macro. Maybe he can share some of his logic

@cujomalainey cujomalainey force-pushed the review branch 2 times, most recently from b58b4ed to 5dca67b Compare July 12, 2024 21:02
@cujomalainey
Copy link
Member Author

cujomalainey commented Jul 12, 2024

@singalsu The testbench is failing due to bad test cases. on the ext_data_length I am seeing the following issue in the testbench CI. scratch that, i think comp->size is a subset of hdr.size

EXPECTED = 384 (SOF_IPC_MSG_MAX_SIZE)
GOT = 716 (proc->comp.hdr.size + proc->comp.ext_data_length + proc->size)

@lyakh I flipped the comparison to < because it seems that testbench has other bad cases as well and as long as we have the memory it should be safe.

We have a few gaps in input validation from the kernel. Right now we
check the IPC doesn't claim its larger the window, this patch adds the
following checks:

1. That the IPC size is at least large enough for any downcast type on
   comp new
2. That any reported size for a process total size is less than the IPC
   window.

Also adjust the other helper to be  a bit safer and more direct

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
@cujomalainey
Copy link
Member Author

On second thought this is possibly more of a mess than i originally thought.

This check here given its a == check seems to imply that the size of the IPC is locked to sizeof(struct sof_ipc_comp) which is not true! There is clearly additional data appended based on comp_specific_builder.

So what do we want to fix? Do we want to have the firmware not able to trust the top level size? Or do we want to fix the kernel and firmware to properly emit sizes in the top level header (likely bringing in breakages between versions).

@cujomalainey cujomalainey added bug Something isn't working as expected P2 Critical bugs or normal features ABI ABI change involved IPC error IPC error is observed labels Jul 15, 2024
@cujomalainey
Copy link
Member Author

@lgirdwood @plbossart thoughts on the proper fix here? I would argue the ABI spec is either wrong or violated here

@cujomalainey
Copy link
Member Author

Moving to bug for discussion

@cujomalainey
Copy link
Member Author

Change of plans, i don't think an abi change will help, going to continue hammering this.

@cujomalainey cujomalainey reopened this Jul 26, 2024
@cujomalainey cujomalainey marked this pull request as ready for review July 29, 2024 22:48
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks correct for IPC3

@lgirdwood
Copy link
Member

SOFCI TEST

@lgirdwood
Copy link
Member

Reruns CI as been pending for a while.

@kv2019i kv2019i merged commit 3f873a6 into thesofproject:main Aug 8, 2024
84 of 88 checks passed
@cujomalainey cujomalainey deleted the review branch August 8, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI ABI change involved bug Something isn't working as expected IPC error IPC error is observed P2 Critical bugs or normal features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants