Why does mmap (2) with PROT_WRITE only need to read fd?

From the POSIX section (IEEE Std 1003.1-2008) to mmap:

Fildes file descriptors must be open with read permissions regardless of the specified security options.

Why? It seems that a handle open O_WRONLYand mapped to PROT_WRITE, rather than PROT_READ, should not be problematic with respect to permissions, right?

+1
source share
2 answers

But the next line says that:

If PROT_WRITE is specified, the application shall ensure that it has opened the file descriptor fildes with write permission unless MAP_PRIVATE is specified in the flags parameter as described below.

, , , , atleast . , .

, READ ONLY mmap.

fd= open(file_name,O_RDONLY);  
mappedData = mmap(0,fdstat.st_size,PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);

, , :

mmap:

EDIT: , .

0

, - , - : RAM mmaped-. . ( , O_WRONLY , PROT_WRITE) , , , .

, , , msync() munmap(). , , "" , momory.

, 4KB - , .

0

Source: https://habr.com/ru/post/1568637/


All Articles