Re: Using INN with shared writable memory in Linux 1.3.3

Brian Blackmore (
Mon, 26 Jun 1995 07:53:55 +0100 (BST)

> You can't change the size of a file by means of writing outside the
> region of a shared writable mapping - at least that's what the slowaris
> man pages say. The problem here's a little different, though. Consider
> the following program:

[ deletion ]

After taking a look at the code to INN I release now that it isn't
trying to extend the mapping, but it does do the following...

#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>

int main(int argc,char **argv)
char text1[] = "Hello";
char text2[] = "World";
char *p;
int fd;

fd = open("testfile",O_RDWR|O_CREAT|O_TRUNC,0644);
p = (char *)mmap(0,sizeof(text1),PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,
p[0] = 'B';
return 0;

Ie its memory mapping the file, writting the new newsgroup in the file
itself, but past the end of the memory map, and then unmapping the
memory. At this point the kernel is writting the entire last page back
and not just the section specified in the munmap command, thus
smashing the new text you wrote with NUL's. If you don't modify the
mapping while in memory the problem doesn't occur.