TDDB63: Concurrent programming and operating systems Protection [SGG7] Chapter 14 and 15 Protection and Security Provide goals and principles of protection Introduce security threats and attacks Explain the fundamentals of encryption and authentication Examine the uses of cryptography in computing • • • • • • • Goals of Protection Domain of Protection Access Matrix Implementation of Access Matrix Revocation of Access Rights Capability-Based Systems Language-Based Protection Copyright Notice: The lecture notes are mainly based on Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, 7th ed., Wiley, 2005). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Addison-Wesley. These lecture notes should only be used for internal teaching purposes at the Linköping University. Andrzej Bednarski, IDA Linköpings universitet, 2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.2 Silberschatz, Galvin and Gagne ©2005 Protection Principle of Protection • Operating system consists of a collection of objects, hardware or software • Need-to-know principle + At any time a process should only be able to access only resources that it currently requires to complete its task • Each object has a unique name and can be accessed through a well-defined set of operations. • Principle of least privilege + Programs, users and systems should be given just enough privileges to perform their tasks • Protection problem – ensure that each object is accessed correctly and only by those processes that are allowed to do so. TDDB63, A. Bednarski, IDA, Linköpings universitet 10.3 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.4 Silberschatz, Galvin and Gagne ©2005 Domain Structure Domain Implementation • Access-right = <object-name, rights-set> Rights-set is a subset of all valid operations that can be performed on the object. • System consists of two domains: + User + Supervisor • Domain = set of access-rights • UNIX + Domain = user-id + Domain switch accomplished via file system. ̶ Each file has associated with it a domain bit (setuid bit). ̶ When file is executed and setuid = on, then user-id is set to owner of the file being executed. When execution completes user-id is reset. • Domain = user, process, or procedure TDDB63, A. Bednarski, IDA, Linköpings universitet 10.5 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.6 Silberschatz, Galvin and Gagne ©2005 1 Access Matrix • • • • Use of Access Matrix View protection as a matrix (access matrix) Rows represent domains Columns represent objects Access(i, j) is the set of operations that a process executing in Domaini can invoke on Objectj TDDB63, A. Bednarski, IDA, Linköpings universitet 10.7 Silberschatz, Galvin and Gagne ©2005 • If a process in Domain Di tries to do “op” on object Oj, then “op” must be in the access matrix. • Can be expanded to dynamic protection. + Operations to add, delete access rights. + Special access rights: ̶ owner of Oi ̶ copy op from Oi to Oj ̶ control – Di can modify Dj access rights ̶ transfer – switch from domain Di to Dj TDDB63, A. Bednarski, IDA, Linköpings universitet 10.8 Use of Access Matrix (Cont.) Access Control • • Protection can be applied to non-file resources • Role-based access control implements least privilege principle + Privilege is right to execute system call or use an option within a system call + Can be assigned to processes + Users assigned roles granting access to privileges and programs • Access matrix design separates mechanism from policy. + Mechanism ̶ Operating system provides access-matrix + rules. ̶ If ensures that the matrix is only manipulated by authorized agents and that rules are strictly enforced. + Policy ̶ User dictates policy. ̶ Who can access what object and in what mode. Implementation + Sparse + Access lists: associated with each object + Capability lists: associated with each domain Silberschatz, Galvin and Gagne ©2005 Example of RBAC in Solaris TDDB63, A. Bednarski, IDA, Linköpings universitet 10.9 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.10 Silberschatz, Galvin and Gagne ©2005 Revocation of Access Rights Language-Based Protection • • • Specification of protection in a programming language allows the high-level description of policies for the allocation and use of resources. • Language implementation can provide software for protection enforcement when automatic hardware-supported checking is unavailable. • Interpret protection specifications to generate calls on whatever protection system is provided by the hardware and the operating system. • • Immediate vs delayed Selective vs general + For some users or for all users Partial vs total + Subset of rights associated with an object Temporary vs permanent TDDB63, A. Bednarski, IDA, Linköpings universitet 10.11 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.12 Silberschatz, Galvin and Gagne ©2005 2 Reference Monitor Reference Monitor (Cont.) • Module: secure, always used and “fully” testable that controls all software accesses to data object and devices [Wikipedia] • • • • Checks the nature of the request against a table of allowable access types for each process on the system [Wikipedia] • • Portion of security kernel that controls access to objects + Tamperproof + Always invoked + Small enough to be subject to analysis and testing Collection of access controls for devices, files, memory, IPC, etc. Single point though which all accesses requests must pass Correctness: likelihood of correctness decreases as complexity/size of programs increases Small, simple understandable RM subjects Audit file Reference Monitor (policy) Security kernel base TDDB63, A. Bednarski, IDA, Linköpings universitet 10.13 Silberschatz, Galvin and Gagne ©2005 Trusted Computing Base • • • Utilities TDDB63, A. Bednarski, IDA, Linköpings universitet • • • User applications TCB Subject: security clearance Object: security classification 10.14 Silberschatz, Galvin and Gagne ©2005 TCB Monitoring Functions Everything in the trusted OS system necessary to enforce the security policy Handles correct enforcement of the policy Part of the OS on which our trust in the security of the whole system depends Non-TCB TDDB63, A. Bednarski, IDA, Linköpings universitet objects • User process coordination, synchronization User I/O Procedures, user processes Directories Segmentation, paging, memory management Process activation + requires security-sensitive information Domain switching + protection against access right escalation Memory protection + code/data secrecy and integrity of domains I/O operations + control of crossing domains Primitive I/O Basic operations Clocks, timing Interrupt handling Hardware: registers, memory Capabilities 10.15 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.16 Silberschatz, Galvin and Gagne ©2005 Security The Security Problem • • • • • • • • • Security must consider external environment of the system, and protect it from: + Unauthorized access + Malicious modification or destruction + Accidental introduction of inconsistency + Legitimate use of the system (denial of service) • Easier to protect against accidental than malicious misuse • Definitions + Intruders/crackers: attempt to breach security + Attack: attempt to break security + Threat: potential for security violation (vulnerability) The Security Problem Program Threats System and Network Threats Cryptography as a Security Tool User Authentication Implementing Security Defenses Firewalling to Protect Systems and Networks Computer-Security Classifications TDDB63, A. Bednarski, IDA, Linköpings universitet 10.17 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.18 Silberschatz, Galvin and Gagne ©2005 3 Security Violations Security Measure Levels • Categories + Breach of confidentiality + Breach of integrity + Breach of availability + Theft of service + Denial of service • • Methods + Masquerading (breach authentication) + Replay attack ̶ Message modification + Man-in-the-middle attack + Session hijacking Security at four different levels: 1) Physical 2) Human 3) Operating System 4) Network Security is as week as the weakest chain TDDB63, A. Bednarski, IDA, Linköpings universitet 10.19 Silberschatz, Galvin and Gagne ©2005 • • • • Trojan Horse + Code segment that misuses its environment + Exploits mechanisms for allowing programs written by users to be executed by other users + Spyware, pop-up browser windows, covert channels Trap Door + Specific user id/password that circumvents normal security procedures + Could be included in a compiler Logic Bomb + Program that initiates a security incident under certain circumstances Stack and Buffer Overflow + Exploits programs’ bugs (overflow either the stack or memory buffers) Viruses + Code fragment embedded in legitimate program + Very specific to CPU architecture, operating system, applications + Usually borne via email or as a macro TDDB63, A. Bednarski, IDA, Linköpings universitet 10.20 Silberschatz, Galvin and Gagne ©2005 Example: C Program with Buffer-overflow Condition Program Threats • TDDB63, A. Bednarski, IDA, Linköpings universitet 10.21 Silberschatz, Galvin and Gagne ©2005 #include <stdio.h> #define BUFFER SIZE 256 int main(int argc, char*argv[]) { char buffer[BUFFER SIZE]; if (argc < 2) return -1; else { strcpy(buffer,argv[1]); return 0; } } TDDB63, A. Bednarski, IDA, Linköpings universitet Layout of stack frame 10.22 Silberschatz, Galvin and Gagne ©2005 Modified Shell Code System and Network Threats #include <stdio.h> int main(int argc, char *argv[]) { execlp(“/bin/sh”, “/bin/sh”, 0); return 0; } • Worms – use spawn mechanism; standalone program • Internet worm + Exploited UNIX networking features (remote access) and bugs in finger and sendmail programs + Grappling hook program uploaded main worm program • Port scanning + Automated attempt to connect to a range of ports on one or a range of IP addresses • Denial of Service (DOS) + Overload the targeted computer preventing it from doing any useful work + Distributed denial-of-service (DDOS) come from multiple sites at once TDDB63, A. Bednarski, IDA, Linköpings universitet 10.23 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.24 Silberschatz, Galvin and Gagne ©2005 4 Implementing Security Defenses Anti-Intrusion Approaches • 1. Prevention +Precludes/handicaps the likelihood of intrusion’s success 2. Preemption +Strikes offensively against likely threat agents (prior to an intrusion) 3. Deterrence +Dissuade potential gains of intruder 4. Deflection +Direct an intruder into a “honey pot” + monitoring 5. Detection +Abnormal activities observation → reaction (authorities) 6. Countermeasures +Actively and autonomously counter an intrusion attempt • • • • • Defense in depth is most common security theory + multiple layers of security Security policy describes what is being secured Vulnerability assessment compares real state of system/network compared to security policy Intrusion detection endeavors to detect attempted or successful intrusions + Signature-based detection spots known bad patterns + Anomaly detection spots differences from normal behavior ̶ Can detect zero-day attacks + False-positives and false-negatives a problem Virus protection Auditing, accounting, and logging of all or specific system or network activities TDDB63, A. Bednarski, IDA, Linköpings universitet 10.25 Silberschatz, Galvin and Gagne ©2005 Cryptography as a Security Tool • TDDB63, A. Bednarski, IDA, Linköpings universitet • + Means to constrain potential senders (sources) and/or receivers (destinations) of messages Based on secrets (keys) TDDB63, A. Bednarski, IDA, Linköpings universitet 10.27 Silberschatz, Galvin and Gagne ©2005 Encryption algorithm consists of + Set of K keys + Set of M messages + Set of C ciphertexts (encrypted messages) + A function E : K → (M →C). That is, for each k ∈ K, E(k) is a function for generating ciphertexts from messages. ̶ Both E and E(k) for any k should be efficiently computable functions. + A function D : K → (C → M). That is, for each k ∈ K, D(k) is a function for generating messages from ciphertexts. ̶ Both D and D(k) for any k should be efficiently computable functions. TDDB63, A. Bednarski, IDA, Linköpings universitet 10.28 Encryption (Cont.) Symmetric Encryption • • An encryption algorithm must provide this essential property: Given a ciphertext c ∈ C, a computer can compute m such that E(k)(m) = c only if it possesses D(k). + Thus, a computer holding D(k) can decrypt ciphertexts to the plaintexts used to produce them, but a computer not holding D(k) cannot decrypt ciphertexts. + Since ciphertexts are generally exposed (for example, sent on the network), it is important that it be infeasible to derive D(k) from the ciphertexts TDDB63, A. Bednarski, IDA, Linköpings universitet 10.29 Silberschatz, Galvin and Gagne ©2005 Encryption Broadest security tool available + Source and destination of messages cannot be trusted without cryptography • 10.26 Silberschatz, Galvin and Gagne ©2005 • • • • Silberschatz, Galvin and Gagne ©2005 Same key used to encrypt and decrypt + E(k) can be derived from D(k), and vice versa DES is most commonly used symmetric block-encryption algorithm (created by US Government) + Encrypts a block of data at a time Triple-DES considered more secure Advanced Encryption Standard (AES), twofish up and coming RC4 is most common symmetric stream cipher, but known to have vulnerabilities + Encrypts/decrypts a stream of bytes (i.e. wireless transmission) + Key is a input to pseudo-random-bit generator ̶ Generates an infinite key-stream TDDB63, A. Bednarski, IDA, Linköpings universitet 10.30 Silberschatz, Galvin and Gagne ©2005 5 Asymmetric Encryption Asymmetric Encryption (Cont.) • Public-key encryption based on each user having two keys: + public key – used to encrypt data + private key – used to decrypt data • • Must be an encryption scheme that can be made public without making it easy to figure out the decryption scheme + Most common is RSA (Rivest, Shamir, Adleman) block cipher + Efficient algorithm for testing whether or not a number is prime + Relies on lack of efficient algorithm for finding the prime factors of a number TDDB63, A. Bednarski, IDA, Linköpings universitet 10.31 Silberschatz, Galvin and Gagne ©2005 Asymmetric Encryption Example • • • • • • • TDDB63, A. Bednarski, IDA, Linköpings universitet • yielding 5 Calculate kd such that kekd mod 72 = 1, yielding 29 We how have our keys + Public key, ke, N = 5, 91 + Private key, kd , N = 29, 91 Encrypting the message 69 with the public key: cyphertext 62 Cyphertext can be decoded with the private key + Public key can be distributed in clear-text to anyone who wants to communicate with holder of public key 10.33 10.32 Silberschatz, Galvin and Gagne ©2005 Cryptography (Cont.) p = 7 and q = 13 N = 7∗13 = 91 and (p−1)(q−1) = 72 Select ke relatively prime to 72 and< 72, TDDB63, A. Bednarski, IDA, Linköpings universitet Formally, it is computationally infeasible to derive D(kd , N) from E(ke , N), and so E(ke , N) need not be kept secret and can be widely distributed + E(ke , N) (or just ke) is the public key + D(kd , N) (or just kd) is the private key + N is the product of two large, randomly chosen prime numbers p and q (for example, p and q are 512 bits each) + Encryption algorithm is E(ke , N)(m) = mke mod N, where ke satisfies kekd mod (p−1)(q −1) = 1 + The decryption algorithm is then D(kd , N)(c) = ckd mod N Silberschatz, Galvin and Gagne ©2005 Note symmetric cryptography based on transformations, asymmetric based on mathematical functions + Asymmetric much more compute intensive + Typically not used for bulk data encryption TDDB63, A. Bednarski, IDA, Linköpings universitet 10.34 Silberschatz, Galvin and Gagne ©2005 Authentication Authentication (Cont.) • • For a message m, a computer can generate an authenticator a ∈ A such that V(k)(m, a) = true only if it possesses S(k) • Thus, computer holding S(k) can generate authenticators on messages so that any other computer possessing V(k) can verify them Computer not holding S(k) cannot generate authenticators on messages that can be verified using V(k) Since authenticators are generally exposed (for example, they are sent on the network with the messages themselves), it must not be feasible to derive S(k) from the authenticators • Constraining set of potential senders of a message + Complementary and sometimes redundant to encryption + Also can prove message unmodified Algorithm components + A set K of keys + A set M of messages + A set A of authenticators + A function S : K → (M→ A) ̶ That is, for each k ∈ K, S(k) is a function for generating authenticators from messages ̶ Both S and S(k) for any k should be efficiently computable functions + A function V : K → (M× A→ {true, false}). That is, for each k ∈ K, V(k) is a function for verifying authenticators on messages ̶ Both V and V(k) for any k should be efficiently computable functions TDDB63, A. Bednarski, IDA, Linköpings universitet 10.35 Silberschatz, Galvin and Gagne ©2005 • • TDDB63, A. Bednarski, IDA, Linköpings universitet 10.36 Silberschatz, Galvin and Gagne ©2005 6 Authentication – Hash Functions • • • • • Authentication - MAC Basis of authentication Creates small, fixed-size block of data (message digest, hash value) from m Hash Function H must be collision resistant on m + Must be infeasible to find an m’ ≠ m such that H(m) = H(m’) If H(m) = H(m’), then m = m’ + The message has not been modified Common message-digest functions include MD5, which produces a 128-bit hash, and SHA-1, which outputs a 160-bit hash • • Symmetric encryption used in message-authentication code (MAC) authentication algorithm Simple example: + MAC defines S(k)(m) = f (k, H(m)) ̶ Where f is a function that is one-way on its first argument ̶ ̶ ̶ ̶ TDDB63, A. Bednarski, IDA, Linköpings universitet 10.37 Silberschatz, Galvin and Gagne ©2005 k cannot be derived from f (k, H(m)) Because of the collision resistance in the hash function, reasonably assured no other message could create the same MAC A suitable verification algorithm is V(k)(m, a) ≡ (f(k,m) = a) Note that k is needed to compute both S(k) and V(k), so anyone able to compute one can compute the other TDDB63, A. Bednarski, IDA, Linköpings universitet 10.38 Authentication – Digital Signature Authentication (Cont.) • • • • • Based on asymmetric keys and digital signature algorithm Authenticators produced are digital signatures In a digital-signature algorithm, computationally infeasible to derive S(ks) from V (kv) + V is a one-way function + Thus, kv is the public key and ks is the private key Consider the RSA digital-signature algorithm + Similar to the RSA encryption algorithm, but the key use is reversed + Digital signature of message S(ks )(m) = H(m)ks mod N + The key ks again is a pair d, N, where N is the product of two large, randomly chosen prime numbers p and q + Verification algorithm is V(kv)(m, a) ≡ (akv mod N = H(m)) ̶ Where kv satisfies kvks mod (p − 1)(q − 1) = 1 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.39 Silberschatz, Galvin and Gagne ©2005 Why authentication if a subset of encryption? + Fewer computations (except for RSA digital signatures) + Authenticator usually shorter than message + Sometimes want authentication but not confidentiality ̶ Signed patches et al + Can be basis for non-repudiation TDDB63, A. Bednarski, IDA, Linköpings universitet Key Distribution Digital Certificates • • • • • Delivery of symmetric key is huge challenge + Sometimes done out-of-band Asymmetric keys can proliferate – stored on key ring + Even asymmetric key distribution needs care (man-in-the-middle attack) TDDB63, A. Bednarski, IDA, Linköpings universitet 10.41 Silberschatz, Galvin and Gagne ©2005 • Silberschatz, Galvin and Gagne ©2005 10.40 Silberschatz, Galvin and Gagne ©2005 Proof of who or what owns a public key Public key digitally signed a trusted party Trusted party receives proof of identification from entity and certifies that public key belongs to entity Certificate authority are trusted party – their public keys included with web browser distributions + They vouch for other authorities via digitally signing their keys, and so on TDDB63, A. Bednarski, IDA, Linköpings universitet 10.42 Silberschatz, Galvin and Gagne ©2005 7 User Authentication Recommended Reading • • Reading + [SGG7] Chapters 14 and 15 + Chapters 18 and 19 (sixth edition) • References: + Ravi S. Sandhu, Edward J. Coyne, Hal L. Feinstein and Charles E. Youman. “Role-Based Access Control Models” + Lawrence R. Halme and R. Kenneth Bauer “AINT Misbehaving: A Taxonomy of Anti-Intrusion Techniques” + Lecture notes: Brett D. Fleish “Design of Trusted Operating Systems” • • • Crucial to identify user correctly, as protection systems depend on user ID User identity most often established through passwords, can be considered a special case of either keys or capabilities + Also can include something user has and /or a user attribute Passwords must be kept secret + Frequent change of passwords + Use of “non-guessable” passwords + Log all invalid access attempts Passwords may also either be encrypted or allowed to be used only once TDDB63, A. Bednarski, IDA, Linköpings universitet 10.43 Silberschatz, Galvin and Gagne ©2005 TDDB63, A. Bednarski, IDA, Linköpings universitet 10.44 Silberschatz, Galvin and Gagne ©2005 8