What permissions are needed to use mmap and MAP_LOCKED

Asked by tomdean

I have an application that uses mmap and MAP_LOCKED, MAP_LOCKED is defined in bits/mman.h

The application works fine as root, but, fails when started as a normal user. I believed this may be due to permissions. ulimit shows the same values for root as the normal user.

I prefer to not use sudo for this application.

/code
   int mapflags = MAP_SHARED;
   #if defined(MAP_LOCKED)
      if( locked) mapflags |= MAP_LOCKED;
   #endif
   char *mem = mmap( NULL, bufsize, PROT_READ | PROT_WRITE, mapflags, fh, 0);

   if( mem == MAP_FAILED)
   {
  sprintf( VT_error, "cannot mmap posix %s, %s\n",
        filename, strerror( errno));
      free( filename);
      return 0;
   }
\code

errno is EAGAIN and strerror(errno) returns 'Resource temporarily unavailable'

> ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127786
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 127786
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

> sudo bash
> ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127786
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 127786
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

Tom Dean

Question information

Language:
English Edit question
Status:
Expired
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

nmap needs to be ran using sudo. You could set the SUID bit on the ACL and it will run as the file owner (root) but this has the same effect as running the command using sudo but doesn't require sudo access.

Revision history for this message
tomdean (tomdean) said :
#2

On 06/29/15 23:51, actionparsnip wrote:
> Your question #268682 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/268682
>
> Status: Open => Answered

The example given in man mmap runs on the same pipe as my application.
The difference is in read vs write. This sort of indicates a
permissions problem.

Tom Dean

Revision history for this message
tomdean (tomdean) said :
#3

On 06/30/15 11:46, tomdean wrote:
>
> The example given in man mmap runs on the same pipe as my application.
> The difference is in read vs write. This sort of indicates a
> permissions problem.

In /etc/security/limits.conf,

<user> hard memlock unlimited
<user> soft memlock unlimited
<user> hard rtprio unlimited
<user> soft rtprio unlimited
<user> hard priority unlimited
<user> soft priority unlimited

I did not try just adding hard or soft...

This fixed the problem I was having. Now, I can run the app without
using sudo.

Tom Dean

Revision history for this message
Launchpad Janitor (janitor) said :
#4

This question was expired because it remained in the 'Open' state without activity for the last 15 days.