From nobody@FreeBSD.org  Wed Jan 11 03:09:29 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D5D0916A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 11 Jan 2006 03:09:28 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A2ED443D46
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 11 Jan 2006 03:09:28 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k0B39SvZ006490
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 11 Jan 2006 03:09:28 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k0B39SQ8006489;
	Wed, 11 Jan 2006 03:09:28 GMT
	(envelope-from nobody)
Message-Id: <200601110309.k0B39SQ8006489@www.freebsd.org>
Date: Wed, 11 Jan 2006 03:09:28 GMT
From: joe <freebsd-security@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /bin/cp does not update atime of the source file
X-Send-Pr-Version: www-2.3

>Number:         91622
>Category:       bin
>Synopsis:       cp(1) does not update atime of the source file
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    dds
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 11 03:10:07 GMT 2006
>Closed-Date:    Fri Dec 14 08:38:48 UTC 2007
>Last-Modified:  Fri Dec 14 08:38:48 UTC 2007
>Originator:     joe
>Release:        RELENG_4 20051028
>Organization:
>Environment:
RELENG_4 20051028
>Description:

[] date
Tue Jan 10 21:58:06 EST 2006

[] ls -lTu  /var/run/dmesg.boot /tmp/dmesg.boot ~/.zshrc /tmp/.zshrc
ls: /tmp/.zshrc: No such file or directory
ls: /tmp/dmesg.boot: No such file or directory
-rw-------  1 user  user     625 Jan 10 21:36:27 2006 /home/user/.zshrc
-rw-r--r--  1 root  wheel  15732 Jan 10 21:50:31 2006 /var/run/dmesg.boot

[] /bin/cp  /var/run/dmesg.boot ~/.zshrc /tmp

[] ls -lTu  /var/run/dmesg.boot /tmp/dmesg.boot ~/.zshrc /tmp/.zshrc
-rw-------  1 user  user     625 Jan 10 21:36:27 2006 /home/user/.zshrc
-rw-------  1 user  wheel    625 Jan 10 21:59:35 2006 /tmp/.zshrc
-rw-r--r--  1 user  wheel  15732 Jan 10 21:59:35 2006 /tmp/dmesg.boot
-rw-r--r--  1 root  wheel  15732 Jan 10 21:50:31 2006 /var/run/dmesg.boot

[] /bin/cat /var/run/dmesg.boot /tmp/dmesg.boot ~/.zshrc /tmp/.zshrc > /dev/null

[] ls -lTu  /var/run/dmesg.boot /tmp/dmesg.boot ~/.zshrc /tmp/.zshrc
-rw-------  1 user  user     625 Jan 10 22:00:57 2006 /home/user/.zshrc
-rw-------  1 user  wheel    625 Jan 10 22:00:57 2006 /tmp/.zshrc
-rw-r--r--  1 user  wheel  15732 Jan 10 22:00:57 2006 /tmp/dmesg.boot
-rw-r--r--  1 root  wheel  15732 Jan 10 22:00:57 2006 /var/run/dmesg.boot


this occurs regardless of whether or not the user has
rwx permissions on the source file. does not apply of
course if the source filesystem is mounted read-only.
they are read-write here.

since the source file is indeed being read, the atime should be updated.


>How-To-Repeat:

repeat the above commands, examine the output.
>Fix:

unknown, either /bin/cp or more likely syscalls.
thanks.
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: joe <freebsd-security@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org,
        dds@FreeBSD.org
Subject: Re: bin/91622: /bin/cp does not update atime of the source file
Date: Wed, 11 Jan 2006 17:34:58 +1100 (EST)

 On Wed, 11 Jan 2006, joe wrote:
 
 >> Environment:
 > RELENG_4 20051028
 >> Description:
 > [cp fails to update atime]
 >
 > this occurs regardless of whether or not the user has
 > rwx permissions on the source file. does not apply of
 > course if the source filesystem is mounted read-only.
 > they are read-write here.
 >
 > since the source file is indeed being read, the atime should be updated.
 
 This is because cp(1) doesn't actually read(2) the file.  It mmap(2)'s the
 file and reads memory.
 
 POSIX doesn't seem to require that cp sets atimes or otherwise acts as
 if it reads the file.
 
 Similar for cmp(1) and other utilities that use mmap() to read files
 (install(1) is another).
 
 The problem is mostly fixed in -current by "setting" (not actually
 setting, but marking for update) atimes in mmap().  I think to be
 strictly correct, setting of atimes should be nearer to munmap(2) than
 mmap().  No read has occurred from userland's viewpoint at mmap() time.
 However, since the OS can't tell if applications read mmapped memory
 unless their is a pagefault, the atime would have to be set on every
 pagefault to be as correct as possible, and I think mmap() prefaults
 some pages so it would have to set the atime whether or not the
 application reads the pages.  So I think setting atimes in mmap() is
 required in practice.  This leaves the problem that later pagefaults
 never set the atime, so the atime set by mmap() becomes out of date.
 I think the atime should be set by mmap() of there is at least one
 later pagefault.  Setting it for every pagefault may be too inefficient.
 
 Bruce
Responsible-Changed-From-To: freebsd-bugs->dds 
Responsible-Changed-By: dds 
Responsible-Changed-When: Wed Jan 11 09:53:25 EET 2006 
Responsible-Changed-Why:  
I'll try to MFC the -current fix to RELENG_4. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=91622 
State-Changed-From-To: open->closed 
State-Changed-By: dds 
State-Changed-When: Fri Dec 14 08:33:46 UTC 2007 
State-Changed-Why:  
This problem has been fixed in RELENG_6. 
Pending MFC is no longer pertinent. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=91622 
>Unformatted:
