Giter Site home page Giter Site logo

Comments (4)

fogti avatar fogti commented on September 27, 2024

PROT_READ + MAP_PRIVATE is also useful if one then casts the slice into utf8 because this allows an safer usage of mmap (verified const utf8 content (&[u8]) will stay the same, without violation of Rusts strict aliasing rules).

from memmap-rs.

fogti avatar fogti commented on September 27, 2024

example usage: https://github.com/zserik/readfilez/blob/master/src/lib.rs

from memmap-rs.

adamreichold avatar adamreichold commented on September 27, 2024

@zseri I am somewhat late to comment on this, but I think

PROT_READ + MAP_PRIVATE is also useful if one then casts the slice into utf8 because this allows an safer usage of mmap (verified const utf8 content (&[u8]) will stay the same, without violation of Rusts strict aliasing rules).

is not correct as the Linux manual page for mmap says

It is unspecified whether changes made to the file after the mmap() call are visible in the mapped region.

concerning MAP_PRIVATE, i.e. it ensures that your changes do not propagate to the underlying file, but it does not seem to ensure that changes to the underlying file do not propagate into your mapping, i.e. another process could possibly turn the file contents into invalid UTF-8 after you validated it.

As a result of the discussion at https://users.rust-lang.org/t/how-unsafe-is-mmap/19635, I think we need another mapping mode that is sort of the converse of MAP_PRIVATE, maybe MAP_SNAPSHOT, which ensures that if a process has read a page at least once, it will not change even if the underlying file changes. Or alternatively, the unspecified part of the behaviour of MAP_PRIVATE would need to be strengthened into that direction.

from memmap-rs.

fogti avatar fogti commented on September 27, 2024

Yeah, I also noticed that... A far bigger problem is also that the underlying file can suddenly become truncated, and if the mapping is then read, it might fail with SIGBUS.

from memmap-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.