Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site nmtvax.UUCP Path: utzoo!linus!philabs!cmcl2!lanl-a!unm-cvax!nmtvax!fred From: fred@nmtvax.UUCP Newsgroups: net.unix-wizards,net.bugs.4bsd Subject: Re: kernal bug in flock Message-ID: <226@nmtvax.UUCP> Date: Wed, 11-Apr-84 16:37:43 EST Article-I.D.: nmtvax.226 Posted: Wed Apr 11 16:37:43 1984 Date-Received: Fri, 13-Apr-84 01:43:50 EST References: <307@nbires.UUCP> Organization: New Mexico Tech, Socorro, N.M. Lines: 73 > Subject: flock panics kernel when given invalid parameter > > Index: sys/sys/kern_descrip.c 4.2BSD > > Description: > The flock system call can cause the 4.2 kernel to panic when > given an invalid second parameter. This occurs only when the > file in question is already locked with LOCK_SH and a second > call to flock where the second parameter does not contain any > of (LOCK_UN|LOCK_EX|LOCK_SH) set. > > Repeat-By: > The problem can be shown with: > ... > flock(fd, LOCK_SH); > ... > flock(fd, 0); > ... > > Fix: > The following context diff of kern_descrip.c prevents the panics: > > *** kern_descrip.c Mon Apr 9 08:16:14 1984 > --- /sys/sys/kern_descrip.c Wed Mar 28 14:35:47 1984 > *************** > *** 405,414 > u.u_error = EOPNOTSUPP; > return; > } > - if ((uap->how & (LOCK_UN|LOCK_EX|LOCK_SH){ > - u.u_error = EINVAL; /* ??? */ > - return; > - } > if (uap->how & LOCK_UN) { > ino_unlock(fp, FSHLOCK|FEXLOCK); > return; > --- 405,410 ----- > u.u_error = EOPNOTSUPP; > return; > } > if (uap->how & LOCK_UN) { > ino_unlock(fp, FSHLOCK|FEXLOCK); > return; I found that the above fix was obviously not tested by the person who posted it. The fix had both a syntax error and a logic error. The fix should have been: - if (!(uap->how & (LOCK_UN|LOCK_EX|LOCK_SH))){ - u.u_error = EINVAL; /* ??? */ - return; - } Fred Romelfanger Computer Science Department New Mexico Tech ..!ucbvax!unmvax!nmtvax!fred (uucp) ..!cmcl2!lanl-a!nmtvax!fred (uucp) fred.nmt@rand-relay (arpa) fred@nmt (CSnet)