-
Notifications
You must be signed in to change notification settings - Fork 349
Audio: SRC: Add safeguard against completely missing init_data #7830
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
Conversation
btian1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another question is how to make sure cfg is not possible to be NULL?
see module_adapter_new() |
|
Looks ready to go, but we need a clean run for the mandatory CI checks. |
|
what logs do we have and how did we identify this? |
lyakh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, so far I don't see how this can happen
init data is only initialized if the topology has a non 0 payload. Therefore it can be null. See https://github.com/thesofproject/sof/blob/main/src/audio/module_adapter/module_adapter.c#L124 |
Also for context its a fuzzer find |
@cujomalainey but so, I still don't understand, sorry |
|
FWIW, I think this might be a special case of the issue fixed in #7854 That would also produce crashes on the module_adapter initialization path, just like this. The root cause was (what I think is) a protocol goof. There was a case (unexercised by the host) where a pointer field in the initialization data block for a new component creation would be filled in from external data, which is clearly not OK. In the failure I was looking at it wasn't NULL but garbage, but that's going to depend on the specifics of the fuzzer input. |
|
|
@lyakh , if I have understood properly the purpose of the fuzzer tests, they trying to break the FW on purpose by feeding it with broken input. I am not sure we can easily find all possible call paths from these broken messages, but still we should make all we can not to crash on them. I am still saying that a single NULL check is not a big price to pay for security. I can make one more attempt to understand how NULL ended up to SRC init_data. But if I fail, would you like the change better if the check would be an assert? |
@jsarha that's also my understanding of how fuzzers work, but - where do they feed that random input into? This probably depends on the project, but I think you only feed that random input to software exposed interfaces. E.g. on network servers you send "random" packets to them, on filesystems you feed random corrupted storage data, in our case it would be random IPC contents. Fuzzing does not slit into your software and feed into some random internal interface. So, I still think we can very well understand where data comes from and what data can appear at this point. And further, I still haven't seen any evidence of why we think that this "fix" helps - why do we think that we really get to this point with a
the above makes me strongly believe that this isn't needed. |
|
I double checked module_adapter_new, cfg->init_data was specially designed and it must not empty and always valid before enter module_init, and after module_init, this was set to NULL again, so @jsarha , Guennadi is correct, no need this extra check, it is superfluous,no need. |
|
So the root cause is not yet found. I'll mark this PR as draft for the time being. |
|
I think I found the root cause. tldr: Its a left over issue from the enum system to identify components that the fuzzer is exploiting by setting the UUID to SRC but the component type to something else. Long explanation: Blind copy from IPC into config of the toxic enum. As a result we are probably hitting the default case in the Recommended possible solutions:
|
|
Turns out I was slightly off in my analysis but on the right track. We do indeed do a enum type check in get_drv BUT with the module adapter that comp type is not set to COMP_SRC anymore so this switch case is actually completely broken. |
|
@ranj063 might need some help here, looks like we are in a sticky wicket with regards to a security issue in IPC3 for the module adapter transition |
|
Aha and it was hidden in a sub window in OSS fuzz but volume is hitting this bug as well as expected |
@cujomalainey great, you're right, now we know how this happens! I think with the Linux driver we're saved by this: https://github.com/thesofproject/linux/blob/34b7f81747f8dbb82a39d46b1234b157d4a7e38c/sound/soc/sof/ipc3-topology.c#L607 which of course isn't done with fuzzing. Then |
|
There is now a generic fix: #7891 |
@cujomalainey @jsarha sorry I;m a bit late to the party but I think the real problem is we're masking the erroneous init_data because of this check in module_adapter_new() sof/src/audio/module_adapter/module_adapter.c Line 125 in 8937929
If you look into module_load_config() , we call out the error when size if 0. So if we remove this check in module_adapter_new(), we'd fail gracefully |
@ranj063 does that mean, that 0 configuration size is invalid in general by definition for all modules? Shouldn't this be up to individual modules to decide? Cannot it be valid for some modules? |
|
Let's go back to module specific fix since there is no simple way to make a generic fix. |
@lyakh for IPC3 the init_data points to the entire IPC payload and I dont think we can create a module with a 0 sized payload at all right? |
If this is true then indeed the simple fix is to abort 0 sized ops. That being said it still leaves a hole for the kernel to give the wrong size and cause an out of bounds access unless the module checks the size. |
@ranj063 I think the sof/src/audio/module_adapter/module_adapter.c Line 118 in 8937929
sof/src/include/ipc/topology.h Line 232 in 8937929
data[] array, so, it can be 0?
|
@lyakh Now we know how this happens, so can I dismiss this comment? How about merging? |
@jsarha following analysis from @cujomalainey I think the above proposal is almost good - we cannot match the type for module-adapter drivers - the driver type is |
|
Note, #7854 is now handling the same issue... |
Topology does not help us here. FW itself doesn't now anything about the topology, it only receives messages about it, but here we are trying to make the FW robust enough to not to crash on any malformed message. So the comp type must be set in the FW source. Should be doable thou. |
In some error situations the configuration init_data may be NULL, and in such a situations we should fail gracefully and not crash. Also adds check that the IPC message is of correct size and of correct type. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
In some error situations the configuration init_data may be NULL, and in such a situations we should fail gracefully and not crash.