linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PROBLEM: mmap MAP_SHARED does not update mtime or ctime
@ 2001-08-20  3:48 Jeff Anton
  0 siblings, 0 replies; only message in thread
From: Jeff Anton @ 2001-08-20  3:48 UTC (permalink / raw)
  To: linux-kernel

PROBLEM: mmap MAP_SHARED does not update mtime or ctime

mmap'ing a file with MAP_SHARED and writeable, modifing the memory
then closeing does not update the file mod time or change time
risking that incremental dumps will not dump the file and is
a possible security problem as one can change a file without
changing the mod-time.  C program showing the problem follows.
Program has been run only against ext2 filesystems.
This is a regression from the 2.2 series which correctly updates
mtime and ctime.  Problem also appeared on 2.4.8

				Jeff Anton


Linux chaos 2.4.9 #1 Sun Aug 19 09:29:48 PDT 2001 i586 unknown
 
Gnu C                  2.95.3
Gnu make               3.77
binutils               2.10.1
usage: fdformat [ -n ] device
mount                  2.7f
modutils               2.4.1
e2fsprogs              1.19
PPP                    2.3.11
Linux C Library        2.2.2
Dynamic linker (ldd)   2.2.2
Linux C++ Library      27.2.8
Linux C++ Library      27.2.8
Procps                 1.2.7
Net-tools              1.51
Kbd                    command
Sh-utils               1.16
Modules Loaded         eepro100 binfmt_misc nls_iso8859-1 nls_cp437
msdos fat


_____________
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>

const char fname[] = "testfile";

void
statfile(const char *f)
{
    struct stat sb;

    if (stat(f, &sb) < 0)
	perror(f);
    else {
	printf("atime\t%lu\n", sb.st_atime);
	printf("mtime\t%lu\n", sb.st_mtime);
	printf("ctime\t%lu\n", sb.st_ctime);
    }
}

void
createfile(const char *f)
{
    int fd = open(f, O_CREAT|O_RDWR, 0666);
    if (fd < 0)
	perror("open-create");
    else {
	if (ftruncate(fd, 0x2000) < 0)
	    perror("ftruncate");
	if (close(fd) < 0)
	    perror("close");
    }
}

\x15\x15void
mmapchange(const char *f)
{
    int fd = open(f, O_RDWR);

    void *a = mmap(NULL, 0x2000, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
0);
    if (a) {
	long *l = (long *)a;

	/* touch the memory */
	++*l;
    } else
	perror("mmap");

    if (munmap(a, 0x2000) < 0)
	perror("munmap");

    if (close(fd) < 0)
	perror("close");
}

int
main()
{
    createfile(fname);
    statfile(fname);
    sleep(10);
    mmapchange(fname);
    statfile(fname);
    if (unlink(fname) < 0)
	perror("unlink");
    return 0;
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-08-20  3:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-20  3:48 PROBLEM: mmap MAP_SHARED does not update mtime or ctime Jeff Anton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).