Capability-based security in Operating Systems - Time & Space Complexity
We want to understand how the time it takes to check permissions grows as the number of capabilities increases in a system using capability-based security.
Specifically, how does the system's work change when it verifies access rights for a user or process?
Analyze the time complexity of the following code snippet.
// Check if a process has a capability
function hasCapability(process, capability) {
for (let cap of process.capabilities) {
if (cap === capability) {
return true;
}
}
return false;
}
This code checks if a process holds a specific capability by scanning through its list of capabilities.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through the list of capabilities held by the process.
- How many times: Up to once for each capability until the desired one is found or the list ends.
As the number of capabilities a process has grows, the time to check for one capability grows roughly in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Up to 10 checks |
| 100 | Up to 100 checks |
| 1000 | Up to 1000 checks |
Pattern observation: The time grows linearly as the number of capabilities increases.
Time Complexity: O(n)
This means the time to check a capability grows directly with the number of capabilities the process has.
[X] Wrong: "Checking a capability always takes the same amount of time no matter how many capabilities there are."
[OK] Correct: Because the code must look through the list until it finds the capability or reaches the end, so more capabilities mean more work.
Understanding how capability checks scale helps you design secure systems that remain efficient as they grow.
"What if the capabilities were stored in a data structure that allows instant lookup? How would the time complexity change?"
Practice
capability-based security?Solution
Step 1: Understand capability-based security concept
It means giving users or programs special tokens that say what they can do.Step 2: Compare with other methods
Unlike passwords or firewalls, capability tokens directly grant permission.Final Answer:
Users or programs get tokens that directly grant permissions -> Option DQuick Check:
Capability tokens = direct permission [OK]
- Confusing capability tokens with passwords
- Thinking security is only about firewalls
- Believing permissions are random
Solution
Step 1: Define what a capability is
A capability is a token that grants specific access rights to a resource.Step 2: Eliminate incorrect options
Passwords, firewall rules, and usernames are not capabilities.Final Answer:
A token that grants specific access rights -> Option AQuick Check:
Capability = access token [OK]
- Mixing capabilities with passwords
- Thinking firewall rules are capabilities
- Confusing usernames with capabilities
Solution
Step 1: Understand capability permissions
Capabilities specify exact rights, here only read permission is given.Step 2: Predict system behavior on unauthorized action
Trying to write without write permission causes failure.Final Answer:
The write operation fails because the capability only allows reading -> Option AQuick Check:
Capability limits action to allowed rights [OK]
- Assuming any access means all actions allowed
- Thinking system prompts user for permission
- Believing unauthorized actions delete files
Solution
Step 1: Identify common reasons for capability errors
Revoked or expired tokens cause access errors.Step 2: Eliminate unrelated causes
Too many tokens, internet issues, or user passwords do not affect capability token validity.Final Answer:
The capability token was revoked or expired -> Option BQuick Check:
Revoked/expired token = error cause [OK]
- Blaming network issues for capability errors
- Thinking password affects capability tokens
- Assuming token count causes errors
Solution
Step 1: Understand safe sharing in capability systems
Sharing limited permission tokens lets others access only what you allow.Step 2: Avoid unsafe methods
Sharing passwords, admin rights, or disabling security risks full control and breaches.Final Answer:
Give the other program a capability token with limited permissions -> Option CQuick Check:
Limited capability token = safe sharing [OK]
- Sharing passwords instead of tokens
- Granting full admin rights unnecessarily
- Turning off security checks
Ready to prove it?
Pass the test and this pattern moves unknown
