BSD 4_1_snap development
[unix-history] / usr / doc / security
CommitLineData
f55d5308
C
1.ND June 10, 1977
2.TL
3On the Security of UNIX
4.AU
5Dennis M. Ritchie
6.AI
7.MH
8.PP
9Recently there has been much interest in the security
10aspects of operating systems and software.
11At issue is the ability
12to prevent undesired
13disclosure of information, destruction of information,
14and harm to the functioning of the system.
15This paper discusses the degree of security which can be provided
16under the
17.UX
18system and offers a number of hints
19on how to improve security.
20.PP
21The first fact to face is that
22.UX
23was not developed with
24security, in any realistic sense, in mind;
25this fact alone guarantees a vast number of holes.
26(Actually the same statement can be made with respect
27to most systems.)
28The area of security in which
29.UX
30is theoretically weakest is
31in protecting against crashing or at least crippling
32the operation of the system.
33The problem here is not mainly in uncritical
34acceptance of bad parameters to system calls\(em
35there may be bugs in this area, but none are known\(em
36but rather in lack of checks for excessive
37consumption of resources.
38Most notably, there is no limit on the amount of disk
39storage used, either in total space allocated or in
40the number of files or directories.
41Here is a particularly ghastly shell sequence guaranteed
42to stop the system:
43.DS
44while : ; do
45 mkdir x
46 cd x
47done
48.DE
49Either a panic will occur because all the i-nodes
50on the device are used up, or all the disk blocks will
51be consumed, thus preventing anyone from writing files
52on the device.
53.PP
54In this version of the system,
55users are prevented from creating more than
56a set number of processes simultaneously,
57so unless users are in collusion it is unlikely that any one
58can stop the system altogether.
59However, creation of 20 or so CPU or disk-bound jobs
60leaves few resources available for others.
61Also, if many large jobs are run simultaneously,
62swap space may run out, causing a panic.
63.PP
64It should be evident that excessive consumption of disk
65space, files, swap space, and processes can easily occur
66accidentally in malfunctioning programs
67as well as at command level.
68In fact
69.UX
70is essentially defenseless against this kind of
71abuse,
72nor is there any easy fix.
73The best that can be said is that it is generally
74fairly
75easy to detect what has happened when disaster
76strikes,
77to identify the user responsible,
78and take appropriate action.
79In practice,
80we have found that difficulties
81in this area are rather rare,
82but we have not been faced with malicious users,
83and enjoy a fairly generous supply of
84resources which have served to cushion us against
85accidental overconsumption.
86.PP
87The picture is considerably brighter
88in the area of protection of information
89from unauthorized perusal and destruction.
90Here the degree of security seems (almost)
91adequate theoretically, and the problems lie
92more in the necessity for care in the actual use of
93the system.
94.PP
95Each
96.UX
97file has associated with it
98eleven bits of protection information
99together with a user identification number and a user-group
100identification number
101(UID and GID).
102Nine of the protection bits
103are used to specify independently
104permission to read, to write, and to execute the file
105to the user himself, to members of the user's
106group, and to all other users.
107Each process generated
108by or for a user has associated with
109it an effective UID and a real UID, and an effective and real GID.
110When an attempt is made
111to access the file for reading, writing, or execution,
112the user process's effective UID is compared
113against the file's UID; if a match is obtained,
114access is granted provided the read, write, or execute
115bit respectively for the user himself is
116present.
117If the UID for the file and for the process fail to match,
118but the GID's do match, the group bits are used; if the GID's
119do not match, the bits for other users are tested.
120The last two bits of each file's protection information,
121called the set-UID and set-GID bits,
122are used only when the
123file is executed as a program.
124If, in this case, the set-UID bit is on for the file,
125the effective UID for the process is changed to the UID
126associated with the file; the change persists
127until the process terminates or until the UID
128changed again by another execution of a set-UID file.
129Similarly the effective group ID of a process is changed
130to the GID associated with a file
131when that file is executed and has the set-GID bit set.
132The real UID and GID of a process do not change
133when any file is executed,
134but only as the result of a privileged system
135call.
136.PP
137The basic notion of the set-UID and set-GID
138bits is that one may write a program which is executable
139by others and which maintains files accessible to others only
140by that program.
141The classical example is the game-playing program which
142maintains records of the scores of its players.
143The program itself has to read and write the score file,
144but
145no one but the game's sponsor can be allowed
146unrestricted access to the file lest they manipulate
147the game to their own advantage.
148The solution is to
149turn on the set-UID bit of the
150game
151program.
152When, and only when, it is invoked
153by players of the game, it may update the score file
154but ordinary programs executed by others cannot
155access the score.
156.PP
157There are a number of special cases involved
158in determining access permissions.
159Since executing a directory as a program is a meaningless
160operation, the execute-permission
161bit, for directories, is taken instead to mean
162permission to search the directory for a given file
163during the scanning of a path name;
164thus if a directory has execute permission but no read
165permission for a given user, he may access files
166with known names in the directory,
167but may not read (list) the entire contents of the
168directory.
169Write permission on a directory is interpreted to
170mean that the user may create and delete
171files in that directory;
172it is impossible
173for any user to write directly into any directory.
174.PP
175Another, and from the point of view of security, much
176more serious special case is that there is a ``super user''
177who is able to read any file and write any non-directory.
178The super-user is also able to change the protection
179mode and the owner UID and GID of any file
180and to invoke privileged system calls.
181It must be recognized that the mere notion of
182a super-user is a theoretical, and usually
183practical, blemish on any protection scheme.
184.PP
185The first necessity for a secure system
186is of course arranging that all files and directories
187have the proper protection modes.
188Traditionally,
189.UX
190software has been exceedingly
191permissive in this regard;
192essentially all commands create files
193readable and writable by everyone.
194In the current version,
195this policy may be easily adjusted to suit the needs of
196the installation or the individual user.
197Associated with each process and its descendants
198is a mask, which is in effect
199.I and\fR\|-ed
200with the mode of every file and directory created by
201that process.
202In this way, users can arrange that, by default,
203all their files are no more accessible than they wish.
204The standard mask, set by
205.I login,
206allows all permissions to the user himself and to his group,
207but disallows writing by others.
208.PP
209To maintain both data privacy and
210data integrity,
211it is necessary, and largely sufficient,
212to make one's files inaccessible to others.
213The lack of sufficiency could follow
214from the existence of set-UID programs
215created by the user
216and the possibility of total
217breach of system security
218in one of the ways discussed below
219(or one of the ways not discussed below).
220For greater protection,
221an encryption scheme is available.
222Since the editor is able to create encrypted
223documents, and the
224.I crypt
225command can be used to pipe such documents into
226the other text-processing programs,
227the length of time during which cleartext versions
228need be available is strictly limited.
229The encryption scheme used is not one of the strongest
230known, but it is judged adequate, in the sense that
231cryptanalysis
232is likely to require considerably more effort than more direct
233methods of reading the encrypted files.
234For example, a user who stores data that he regards as truly secret
235should be aware that he is implicitly trusting the system
236administrator not to install a version of the crypt command
237that stores every typed password in a file.
238.PP
239Needless to say, the system administrators
240must be at least as careful as their most
241demanding user to place the correct
242protection mode on the files under their
243control.
244In particular,
245it is necessary that special files be protected
246from writing, and probably reading, by ordinary
247users when
248they store sensitive files belonging to other
249users.
250It is easy to write programs that examine and change
251files by accessing the device
252on which the files live.
253.PP
254On the issue of password security,
255.UX
256is probably better than most systems.
257Passwords are stored in an encrypted form
258which, in the absence of serious attention
259from specialists in the field,
260appears reasonably secure,
261provided its limitations are understood.
262In the current version, it is based on a slightly
263defective version of the Federal DES;
264it is purposely defective so that
265easily-available hardware is useless for attempts at exhaustive
266key-search.
267Since both the encryption algorithm and the encrypted passwords
268are available,
269exhaustive enumeration of potential passwords
270is still feasible up to a point.
271We have observed that users choose passwords that are easy to guess:
272they are short, or from a limited alphabet, or
273in a dictionary.
274Passwords should be
275at least six characters long and randomly chosen from an alphabet
276which includes digits and special characters.
277.PP
278Of course there also exist
279feasible non-cryptanalytic
280ways of finding out passwords.
281For example: write a program which types out ``login:\|''
282on the typewriter and copies whatever is typed
283to a file of your own.
284Then invoke the command and go away until the victim arrives.
285.PP
286The set-UID (set-GID)
287notion must be used carefully if any security is to be maintained.
288The first thing to keep in mind is that
289a writable set-UID file can have another program copied onto it.
290For example, if the super-user
291.I (su)
292command is writable,
293anyone can copy the shell
294onto it and get a password-free version
295of
296.I su.
297A more subtle problem
298can come from
299set-UID programs which are not sufficiently
300careful of what is fed into them.
301To take an obsolete example,
302the previous version of the
303.I mail
304command was set-UID and owned by the super-user.
305This version sent mail to the recipient's own directory.
306The notion was that one should be able to send
307mail to anyone even if they want to protect
308their directories from writing.
309The trouble was that
310.I mail
311was rather dumb:
312anyone could mail someone else's private file to himself.
313Much more serious
314is the following scenario:
315make a file with a line like one in the password file
316which allows one to log in as the super-user.
317Then make a link named ``.mail'' to the password file
318in some writable
319directory on the same device as the password file (say /tmp).
320Finally mail the bogus login line to /tmp/.mail;
321You can then login as the super-user,
322clean up the incriminating evidence,
323and have your will.
324.PP
325The fact that users can mount their own disks and tapes
326as file systems
327can be another way of gaining super-user status.
328Once a disk pack is mounted, the system believes
329what is on it.
330Thus one can take a blank disk pack,
331put on it anything desired,
332and mount it.
333There are obvious and unfortunate consequences.
334For example:
335a mounted disk with garbage on it will crash the
336system;
337one of the files on the mounted disk can easily be
338a password-free version of
339.I su;
340other files can be unprotected entries for special files.
341The only easy fix for this problem is to
342forbid the use of
343.I mount
344to unprivileged users.
345A partial solution, not so restrictive,
346would be to have the
347.I mount
348command examine the special file for bad data,
349set-UID programs owned by others, and accessible
350special files,
351and balk at unprivileged invokers.