aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/uipc_shm.c
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-08-31 15:07:15 +0000
committerKyle Evans <kevans@FreeBSD.org>2020-08-31 15:07:15 +0000
commit5dd47b52e59bbca60bda9388051d45ebbfc3305c (patch)
treedf90612c33d1cc5d18480f48c5b985c15cca5502 /sys/kern/uipc_shm.c
parent641b7baa5b5d4eb76c79e69acba0a1c60a56f12d (diff)
downloadsrc-5dd47b52e59bbca60bda9388051d45ebbfc3305c.tar.gz
src-5dd47b52e59bbca60bda9388051d45ebbfc3305c.zip
posixshm: fix setting of shm_flags
Noted in D24652, we currently set shmfd->shm_flags on every shm_open()/shm_open2(). This wasn't properly thought out; one shouldn't be able to specify incompatible flags on subsequent opens of non-anon shm. Move setting of shm_flags explicitly to the two places shmfd are created, as we do with seals, and validate when we're opening a pre-existing mapping that we've either passed no flags or we've passed the exact same flags as the first time. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D26242
Notes
Notes: svn path=/head/; revision=364990
Diffstat (limited to 'sys/kern/uipc_shm.c')
-rw-r--r--sys/kern/uipc_shm.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index 796c2b08582a..74fc9b023b09 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -833,6 +833,7 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode,
}
shmfd = shm_alloc(td->td_ucred, cmode);
shmfd->shm_seals = initial_seals;
+ shmfd->shm_flags = shmflags;
} else {
error = shm_copyin_path(td, userpath, &path);
if (error != 0) {
@@ -855,6 +856,7 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode,
#endif
shmfd = shm_alloc(td->td_ucred, cmode);
shmfd->shm_seals = initial_seals;
+ shmfd->shm_flags = shmflags;
shm_insert(path, fnv, shmfd);
#ifdef MAC
}
@@ -898,6 +900,8 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode,
else if ((flags & (O_CREAT | O_EXCL)) ==
(O_CREAT | O_EXCL))
error = EEXIST;
+ else if (shmflags != 0 && shmflags != shmfd->shm_flags)
+ error = EINVAL;
else {
#ifdef MAC
error = mac_posixshm_check_open(td->td_ucred,
@@ -947,7 +951,6 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode,
}
}
- shmfd->shm_flags = shmflags;
finit(fp, FFLAGS(flags & O_ACCMODE), DTYPE_SHM, shmfd, &shm_ops);
td->td_retval[0] = fd;