PROBLEM: mmap MAP_SHARED does not update mtime or ctime

From: Jeff Anton (antonlk@hesiod.org)
Date: Sun Aug 19 2001 - 22:48:09 EST


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");
    }
}

void
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;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Aug 23 2001 - 21:00:33 EST