posixshm: Disallow fspacectl() on largepage objects

As with truncation, the operation isn't supported, but nothing prevented
it.

Add a regression test.

Approved by:	so
Security:	FreeBSD-SA-26:44.posixshm
Security:	CVE-2026-49428
Reported by:	Chris Jarrett-Davies <chrisjd@openai.com>
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57830
This commit is contained in:
Mark Johnston 2026-06-24 19:56:07 +00:00 • committed by Franco Fichtner
parent 1a0ae4cd6c
commit 8038f63730
2 changed files with 26 additions and 1 deletions

View file

@ -2096,11 +2096,14 @@ shm_fspacectl(struct file *fp, int cmd, off_t *offset, off_t *length, int flags,
("shm_fspacectl: non-zero flags"));
KASSERT(*offset >= 0 && *length > 0 && *length <= OFF_MAX - *offset,
("shm_fspacectl: offset/length overflow or underflow"));
error = EINVAL;
shmfd = fp->f_data;
off = *offset;
len = *length;
if (shm_largepage(shmfd))
return (ENOTSUP);
rl_cookie = shm_rangelock_wlock(shmfd, off, off + len);
switch (cmd) {
case SPACECTL_DEALLOC:

View file

@ -1380,6 +1380,27 @@ ATF_TC_BODY(largepage_config, tc)
ATF_REQUIRE(close(fd) == 0);
}
ATF_TC_WITHOUT_HEAD(largepage_fspacectl);
ATF_TC_BODY(largepage_fspacectl, tc)
{
struct spacectl_range range;
size_t ps[MAXPAGESIZES];
int fd, pscnt;
pscnt = pagesizes(ps);
for (int i = 1; i < pscnt; i++) {
fd = shm_open_large(i, SHM_LARGEPAGE_ALLOC_DEFAULT, ps[i]);
range.r_offset = 0;
range.r_len = ps[i];
ATF_REQUIRE_ERRNO(ENOTSUP,
fspacectl(fd, SPACECTL_DEALLOC, &range, 0, &range) == -1);
ATF_REQUIRE(close(fd) == 0);
}
}
ATF_TC_WITHOUT_HEAD(largepage_mmap);
ATF_TC_BODY(largepage_mmap, tc)
{
@ -2168,6 +2189,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, mmap_prot);
ATF_TP_ADD_TC(tp, largepage_basic);
ATF_TP_ADD_TC(tp, largepage_config);
ATF_TP_ADD_TC(tp, largepage_fspacectl);
ATF_TP_ADD_TC(tp, largepage_mmap);
ATF_TP_ADD_TC(tp, largepage_munmap);
ATF_TP_ADD_TC(tp, largepage_madvise);