git: 0fb6aae7f0e1 - main - vm_map.c: add CONTAINS_BITS macro
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 12 Aug 2023 06:29:06 UTC
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0fb6aae7f0e19c0628c398bbe30297ef9245030e commit 0fb6aae7f0e19c0628c398bbe30297ef9245030e Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-07-29 17:52:52 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-08-12 06:28:13 +0000 vm_map.c: add CONTAINS_BITS macro Suggested by: dougm Reviewed by: alc, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41099 --- sys/vm/vm_map.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index f8a2903567a6..8c12f2a92bcb 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -148,6 +148,8 @@ static int vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, static void vm_map_wire_entry_failure(vm_map_t map, vm_map_entry_t entry, vm_offset_t failed_addr); +#define CONTAINS_BITS(set, bits) ((~(set) & (bits)) == 0) + #define ENTRY_CHARGED(e) ((e)->cred != NULL || \ ((e)->object.vm_object != NULL && (e)->object.vm_object->cred != NULL && \ !((e)->eflags & MAP_ENTRY_NEEDS_COPY))) @@ -2733,15 +2735,15 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_map_entry_t entry, first_entry, in_tran, prev_entry; vm_object_t obj; struct ucred *cred; - vm_prot_t old_prot; + vm_prot_t check_prot, old_prot; int rv; if (start == end) return (KERN_SUCCESS); - if ((flags & (VM_MAP_PROTECT_SET_PROT | VM_MAP_PROTECT_SET_MAXPROT)) == - (VM_MAP_PROTECT_SET_PROT | VM_MAP_PROTECT_SET_MAXPROT) && - (new_prot & new_maxprot) != new_prot) + if (CONTAINS_BITS(flags, VM_MAP_PROTECT_SET_PROT | + VM_MAP_PROTECT_SET_MAXPROT) && + !CONTAINS_BITS(new_maxprot, new_prot)) return (KERN_OUT_OF_BOUNDS); again: @@ -2750,8 +2752,7 @@ again: if ((map->flags & MAP_WXORX) != 0 && (flags & VM_MAP_PROTECT_SET_PROT) != 0 && - (new_prot & (VM_PROT_WRITE | VM_PROT_EXECUTE)) == (VM_PROT_WRITE | - VM_PROT_EXECUTE)) { + CONTAINS_BITS(new_prot, VM_PROT_WRITE | VM_PROT_EXECUTE)) { vm_map_unlock(map); return (KERN_PROTECTION_FAILURE); } @@ -2772,6 +2773,11 @@ again: /* * Make a first pass to check for protection violations. */ + check_prot = 0; + if ((flags & VM_MAP_PROTECT_SET_PROT) != 0) + check_prot |= new_prot; + if ((flags & VM_MAP_PROTECT_SET_MAXPROT) != 0) + check_prot |= new_maxprot; for (entry = first_entry; entry->start < end; entry = vm_map_entry_succ(entry)) { if ((entry->eflags & MAP_ENTRY_GUARD) != 0) @@ -2780,12 +2786,7 @@ again: vm_map_unlock(map); return (KERN_INVALID_ARGUMENT); } - if ((flags & VM_MAP_PROTECT_SET_PROT) == 0) - new_prot = entry->protection; - if ((flags & VM_MAP_PROTECT_SET_MAXPROT) == 0) - new_maxprot = entry->max_protection; - if ((new_prot & entry->max_protection) != new_prot || - (new_maxprot & entry->max_protection) != new_maxprot) { + if (!CONTAINS_BITS(entry->max_protection, check_prot)) { vm_map_unlock(map); return (KERN_PROTECTION_FAILURE); }