Title: mmap(2) of append-only files may result in corrupted data
Date Issued: May 9, 1998
Last Modified: May 9, 1998
Code: NetBSD-SA1998-003
Source: NetBSD
-----BEGIN PGP SIGNED MESSAGE----- 

                 NetBSD Security Advisory 1998-003 
                 -------------------------------------- 

Topic:           mmap(2) of append-only files may result in corrupted data. 
Version:        NetBSD 1.3.1 and prior. 
Severity:       Possible data corruption. 
  

Abstract 
--------- 

Files that have the append-only flag set are erroneously allowed to 
be memory mapped shared, causing other processes to see changes made 
to the file.  While the on-disk copy is not updated, any other process 
using memory mapping will see this change, causing data corruption. 
  

Technical Details 
----------------- 

4.4BSD added several new concepts to the system security, including a 
system `securelevel', and the ability to mark FFS files as append-only 
or immutable.  These flags are settable at any time, but can only be 
removed when the securelevel is zero, or less.  The securelevel of a 
running system can only be lowered by the /sbin/init process, which 
typically only does this when entering single user mode.  This ensures 
that the even the super-user can not tamper with the file flags. 

Due to a bug in the mmap(2) system call, files that are marked 
append-only, may be opened with append, read and write flags, as normal 
for append-only files, and then mmap(2)'ed shared with write protection. 
When the data mapped is changed, other processes that use mmap(2) on 
this file will also see the changes, defeating the purpose of the 
append-only flag.  The actual on-disk copy of the file is not updated. 
  

Solutions and Workarounds 
---------------------------- 

NetBSD has changed the mmap(2) system call to fail when creating a shared, 
writable file mapping if the file is marked immutable or append-only. 

A patch has been made available for NetBSD 1.3 and 1.3.1, and can be 
found on the NetBSD FTP server: 
    ftp://ftp.NetBSD.ORG/pub/NetBSD/misc/security/patches/19980509-mmap 
  

Thanks To 
----------- 

Thanks to Darren Reed <darrenr@pobox.com.au>, Luke Mewburn 
<lukem@netbsd.org>, Charles Hannum <mycroft@mit.edu>, Chris Demetriou 
<cgd@netbsd.org> and Matthew Green <mrg@eterna.com.au> for finding 
this problem and/or providing input towards fixing the problem. 
  

More Information 
------------------ 

Information about NetBSD and NetBSD security can be found at 
  

http://www.NetBSD.ORG/ and http://www.NetBSD.ORG/Security/. 
  

Copyright 1998, The NetBSD Foundation.  All Rights Reserved. 

-----BEGIN PGP SIGNATURE----- 
Version: 2.6.1 

iQCVAwUBNVWbGD5Ru2/4N2IFAQEVfwP+K2y+wGyf4VEuAfwkqApSA473pT4OnVVD 
phsQXz68xlH9plYnlhockMuOYGb2BA70CPSlewQwZ4dUR1VVXaXld+f0j5HT2cTP 
UNuix68ebsCgrJzlgWM6wM0YABpcwJJWevvC4d5XByFugE6gQbOop03WlJbOe0iC 
ufqesO+uFCU= 
=QSVA 
-----END PGP SIGNATURE-----