git: libnvmm: Fix mmap() failure with 'permission denied'

Aaron LI aly at crater.dragonflybsd.org
Tue Jul 20 16:30:21 PDT 2021


commit 7f94978c70551b3b48544b1ff6f6b22502b5bca1
Author: Aaron LI <aly at aaronly.me>
Date:   Mon May 31 07:25:14 2021 +0800

    libnvmm: Fix mmap() failure with 'permission denied'
    
    The mmap() in nvmm_vcpu_create() was always failing with the EACCES
    (permission denied) error code.  It was because mmap() was requesting
    prot = PROT_READ|PROT_WRITE and flags = MAP_SHARED, but the fd was
    opened with O_RDONLY (or O_WRONLY in nvmm_root_init()) and thus
    disallowed such a mmap request.
    
    Fix this issue by opening the nvmm fd with O_RDWR flag.  This also
    requires to change the mode of '/dev/nvmm' from 0640 to 0660.
    However, this makes root owner distinguishing in nvmm kernel module
    useless.  So change to identify root owner by checking whether the
    caller has root privilege.
    
    In addition, refactor nvmm_root_init() to also check for root privilege
    first and then call nvmm_init().

Summary of changes:
 lib/libnvmm/libnvmm.c       | 20 ++++----------------
 sys/dev/virtual/nvmm/nvmm.c |  5 +++--
 2 files changed, 7 insertions(+), 18 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/7f94978c70551b3b48544b1ff6f6b22502b5bca1


-- 
DragonFly BSD source repository


More information about the Commits mailing list