From nobody Sat Aug 12 06:29:06 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RN9jZ5dLKz4TvV3; Sat, 12 Aug 2023 06:29:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RN9jZ46xZz3Xtc; Sat, 12 Aug 2023 06:29:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691821746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QhbLURO/8BVmgKExIQLIe7ghQ4Vlnq1J7n0b656rrho=; b=Yi2fv5Z8JjIC3+8LIwY6vuDCU3HcCv4l95gcb5W5oT3NFGdFVTbnQGTw/q2hXwLcYYiqNl FhidiDE6pHJR+NsjdGyN5TJftGKTgcuuyiTLaJ+z9KhHPuPpWBighmdWX8/K9KyPHH9clA d+UN9OQJB7UbfTueOgeXLpZ1IBGjci8hAsbQrMXrYeeTzfl742JzwSc/dOHPaFnq4QLkXr DhUc1PFwbKHLW2884VFZ+GZspmWhMGmaHP0AuBRbmLco7yxRkquH5KOdKeiGsnuHiz8xS8 TdqqACq84PkuUtodvPZ6ZBq5s8/w1r4Ow5UlrYVo/teHk8/GvWm7nV28HIo1bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691821746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QhbLURO/8BVmgKExIQLIe7ghQ4Vlnq1J7n0b656rrho=; b=qDQL3gC9qhYSLCN1WGFCj1GiZF6cL/VkCvjRXMnqZEY4Oo43ztGBfWegUZHjPJAYvKmWA4 JK9axSG3CuJhMj/Tw8lZKRSovZANl5q24mLJB7AX7FFj6kON/slil49CS1TL640LI9jMRx y9iEpqYLIdq6Mf+QXuUbSfukoYRyinEld53DqW1SuUJ4CzVa7OFELm6d6O48bj2loJ3rVx WI8h7x33RV2f/MBdAkZcB9fW6LPaYrjHvAo3tYGZMYUAyxBeghj+dgrICk707MFQe3OuRj 5T4juOqQgQjyXYJbKltup/0TpZa94wBVLDINrVmsyGzv0yi6BAg/2Jb7nuloDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691821746; a=rsa-sha256; cv=none; b=mCdzQqK3HuzJm1BcqAlEFvb3lxcAhnc3DRZlHHvgihnvQPY0537uya0JRDWBoHJGV1w/aG b/JE79XVcDv2ESqpt66MVZPT5NacIi9hF5o3OpuXd+ItJ50uHZBSTdi1qM7qtadwDI43uy VGdS1sMkM/qaP7QPkEuEGhsd0hn+1pKO+bjRbOp3W5kwyKcQRzn4QnFRW+T+TN2KQVr4FM fe5BOmkfBvP3Jh9G6AxSw1WzuI/fp0LKg9ET/QZnxPt8UjnFD8G6kK3c3Gvpv+c6B/JvpO 9m8rZMKq2urVi5EkRSQQHBNTTcXM7vCPosiXXc2ZFLDeqg80b7YeqPxDcBBILA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RN9jZ2LqNz19CJ; Sat, 12 Aug 2023 06:29:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37C6T6Nc024732; Sat, 12 Aug 2023 06:29:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37C6T6AU024729; Sat, 12 Aug 2023 06:29:06 GMT (envelope-from git) Date: Sat, 12 Aug 2023 06:29:06 GMT Message-Id: <202308120629.37C6T6AU024729@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 0fb6aae7f0e1 - main - vm_map.c: add CONTAINS_BITS macro List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0fb6aae7f0e19c0628c398bbe30297ef9245030e Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0fb6aae7f0e19c0628c398bbe30297ef9245030e commit 0fb6aae7f0e19c0628c398bbe30297ef9245030e Author: Konstantin Belousov AuthorDate: 2023-07-29 17:52:52 +0000 Commit: Konstantin Belousov 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); }