Skip to content

Conversation

@linh2931
Copy link
Contributor

@linh2931 linh2931 commented Apr 2, 2025

Allow privileged host functions to be called if the receiver has the privileged permission.

Resolve #1279

@linh2931 linh2931 requested review from heifner and spoonincode April 2, 2025 15:50
REGISTER_LEGACY_HOST_FUNCTION(get_resource_limits, privileged_check);
REGISTER_HOST_FUNCTION(get_parameters_packed, privileged_check);
REGISTER_HOST_FUNCTION(set_parameters_packed, privileged_check);
REGISTER_HOST_FUNCTION(set_parameters_packed, privileged_check, action_check); // Not allowed in sync calls. Change of max_sync_call_depth will interfere with active sync calls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this prevent any useful sub-divide of the system contract?

Copy link
Contributor Author

@linh2931 linh2931 Apr 2, 2025

Choose a reason for hiding this comment

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

I hated to break the uniformity of privileged host function preconditions too. The worse is this restriction is due to implementation of sync call wasm allocator queue resizing.

With the restriction, implementation would be simpler. We can resize right at when set_parameters_packed is executed.

Without the restriction, we know set_parameters_packed cannot be called from read-only threads and in read-window. On the main thread, we will need to check if max_sync_call_depth has changed after every sync call. If changed, we resize the wasm allocator queue.

@spoonincode, @arhag What do you think about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I lean toward allowing it. The complication with resizing can be avoided by simply never shrinking the allocator vector/queue during operation. (yeah this leaves some resources unused until restart but seems no big deal)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should allow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I will revert to allow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Base automatically changed from zero_sized_data_and_return to enforce_host_func_preconditions April 2, 2025 23:36
@linh2931 linh2931 merged commit c345069 into enforce_host_func_preconditions Apr 3, 2025
36 checks passed
@linh2931 linh2931 deleted the priviledge_support branch April 3, 2025 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants