From norm@norm2.home.cs.ubc.ca  Mon Feb 17 11:56:30 1997
Received: from norm2.home.cs.ubc.ca (norm2.home.cs.ubc.ca [198.162.38.204])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id LAA10385
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 17 Feb 1997 11:56:27 -0800 (PST)
Received: (from norm@localhost)
	by norm2.home.cs.ubc.ca (8.8.5/8.8.5) id LAA02415;
	Mon, 17 Feb 1997 11:54:24 -0800 (PST)
Message-Id: <199702171954.LAA02415@norm2.home.cs.ubc.ca>
Date: Mon, 17 Feb 1997 11:54:24 -0800 (PST)
From: Norm Hutchinson <norm@norm2.home.cs.ubc.ca>
Reply-To: norm@norm2.home.cs.ubc.ca
To: FreeBSD-gnats-submit@freebsd.org
Subject: <Synopsis of the problem (one line)>Using memory mmapped to an NFS file can cause system hang
X-Send-Pr-Version: 3.2

>Number:         2754
>Category:       kern
>Synopsis:       Using memory mmapped to an NFS file can cause system hang
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 17 12:00:03 PST 1997
>Closed-Date:    Mon May 19 07:38:00 PDT 1997
>Last-Modified:  Mon May 19 07:38:16 PDT 1997
>Originator:     Norm Hutchinson
>Release:        FreeBSD 2.2-970215-GAMMA i386
>Organization:
Computer Science, UBC
>Environment:

	Pentium CPU 32 or 64 M memory

>Description:

	After mmapping an NFS mounted file and modifying it, later accesses to
	the file can cause the system to hang.  Hanging symptoms include no
	response to keyboard/mouse, low-level network connectivity (ping and
	tcp connects) but no ability to remotely log in.

>How-To-Repeat:

	Compile the following program.
		cc -o mmt mmt.c
	Create a small file named foo (on an NFS partition)
		echo fooooo > foo
	Run mmt.
		mmt
	Try to access the file to see the effect of the mmap change.
		od -c foo

Other observed behaviour:
	2.2 BETA had the same problem.  I never tried 2.2 ALPHA.
	This is not a problem on 2.1.6.
	Waiting several seconds after making the change through mmap before 
	accessing the file results in correct behaviour.  Several seconds is 
	something less than 15 and more than 0.

------------
mmt.c
------------

#include <sys/types.h>
#include <sys/mman.h>
#include <sys/file.h>
#include <stdio.h>
#include <sys/stat.h>

/*
 * Map a file into virtual memory.
 */
void *
map_file(int fd)
{
  struct stat statb;
  void *rtn;

  if (fstat(fd, &statb) < 0) {
    return (void *)-1;
  }
  rtn = mmap(NULL, statb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED,
	     fd, (off_t)0);
  return rtn;
}

main()
{
  int fd = open("foo", O_RDWR);
  char * p = map_file(fd);
  *(char **)p = p;
  close(fd);
}

>Fix:
	
	Unknown

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: gpalmer 
Responsible-Changed-When: Mon Feb 17 15:56:01 PST 1997 
Responsible-Changed-Why:  
Misfiled PR 
State-Changed-From-To: open->closed 
State-Changed-By: dfr 
State-Changed-When: Mon May 19 07:38:00 PDT 1997 
State-Changed-Why:  
Fixed in current 20 May 1997. 
>Unformatted:
