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