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