mmap: fail and set -ENODEV when map to unmappable special file

mappable special files are /dev/mem and /dev/zero

Change-Id: Id1d4317104f901644e565007913e320d287e376f
This commit is contained in:
Ken Sato
2019-09-15 15:25:28 +09:00
committed by Masamichi Takagi
parent 4b252a990f
commit 569dc33a9c

View File

@ -943,8 +943,16 @@ static int pager_req_create(ihk_os_t os, int fd, uintptr_t result_pa)
printk("pager_req_create(%d,%lx):vfs_stat failed. %d\n", fd, (long)result_pa, error);
goto out;
}
if (S_ISCHR(st.mode) && (MAJOR(st.rdev) == 1)) {
/* treat memory devices as regular files */
if (S_ISCHR(st.mode) && (MAJOR(st.rdev) == 1) &&
(MINOR(st.rdev) == 1 || // /dev/mem
MINOR(st.rdev) == 5)) { // /dev/zero
/* treat memory devices and zero devices as regular files */
}
else if (S_ISCHR(st.mode) && (MAJOR(st.rdev) == 1)) {
error = -ENODEV;
dprintk("%s(%d,%lx):unmappable device %x\n",
__func__, fd, (long)result_pa, st.mode);
goto out;
}
else if (!S_ISREG(st.mode)) {
error = -ESRCH;