lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Sat, 23 Jul 2011 12:08:50 +0100
From:	Alex Bligh <alex@...x.org.uk>
To:	linux-kernel@...r.kernel.org
cc:	Alex Bligh <alex@...x.org.uk>
Subject: Creating CoW mmap pages from userspace

I have a threaded application which has a large file mmap'd into a
single large area L. L contains lots of page-aligned data structures
each of an integer number of pages in length.

L is volatile (altered by lots of threads). What I'd like to do
is take memory "snapshots" of bits of L by

1. taking a lock (preventing other threads writing to L)
2. generating an mmap CoW copy of a subset of L (just a few pages)
   which would generate a new mmap'd area S (much smaller).
3. releasing a lock.

I'm not going to write to S, but I will read from it, and I need
it to contain what that bit of L contained at the time, and not
be affected by subsequent changes to L.

At kernel level, I can see how this would work - it's pretty much
what happens with fork().

I can't, however, see any way to do it from userspace. The only
near seems to be MAP_PRIVATE (i.e. open the file backing L
with another fd, or perhaps use the same fd, then create
a new memory map with MAP_PRIVATE set), but as far as I can tell
a) this would require me to msync() the relevant portion of L, and
   there is no need for anything to hit the disk - memcpy() would
   be faster, and
b) MAP_PRIVATE seems to protect L against changes to S, but does
   not protect S against changes to L (which is what I need). The
   manpage says "It is unspecified whether changes made to the file
   after the mmap() call are visible in the mapped region"

Any ideas? Currently I am taking the easy way out and memcpy()'ing
the region, but I'd really rather avoid continuously memcpy()'ing
8MB chunks given that 99.9% of the time the relevant bit of L does
not change.

-- 
Alex Bligh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ