From patchwork Wed Jul 19 07:51:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13318463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DFA0C001B0 for ; Wed, 19 Jul 2023 07:40:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC0FA8D0012; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6932280036; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A130A280035; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8027B8D0012 for ; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4BC3440113 for ; Wed, 19 Jul 2023 07:40:11 +0000 (UTC) X-FDA: 81027563022.29.E7F1843 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf04.hostedemail.com (Postfix) with ESMTP id 5E85540010 for ; Wed, 19 Jul 2023 07:40:07 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689752409; a=rsa-sha256; cv=none; b=exY0ap4yXOJGRCC9uzlKIkeIkUselYQmpxQHBPfWEGz4PTZbFph55n9K1YNr0xHwcj0K3E U19TfgORDefUzGJDCBoQVIFfooSuJvWmmXw8LfqgwiH+07OBqDSeDaoVfx+CbP21XsYibN r3egAlCMfO3/2Q9RDfxnLhIHjyVBTto= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689752409; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmIT3/DIKZD9qXY85ldcQFgx/ynf1Pff2Bp+H7U63aA=; b=0B7noszxzGg/N0UE59Zz3fWTWzms1m6ajAGlaOKehUniedcbpVGJCOXxT9oFlcF11P2bu7 gK9o8lBoiJwW3J1wFf09xwXy6IkSAjzu2GFG508c52N0ch+pkwWNWjqYAe1+uB+Hv7jI12 v28ni0YJdOBx+sqBqCRJ/PZla36hbzg= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R5SPj0lfRz18LYp; Wed, 19 Jul 2023 15:39:21 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 19 Jul 2023 15:40:04 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , Kefeng Wang , Paul Moore , Stephen Smalley , Eric Paris Subject: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap() Date: Wed, 19 Jul 2023 15:51:13 +0800 Message-ID: <20230719075127.47736-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719075127.47736-1-wangkefeng.wang@huawei.com> References: <20230719075127.47736-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5E85540010 X-Stat-Signature: 8gbo775npujp7wz9sszdcgys3bq43dby X-Rspam-User: X-HE-Tag: 1689752407-780926 X-HE-Meta: U2FsdGVkX18GoUfFwWu/MLv58U8pOsd6AcjRrbzS0ssH5K6kyb3+0/kop5+9Nx1QCq1pO1H8QcgwRuSNGegB840mjyLqZ4JLXrVXFnyzLlmXQ6A72YPrmLVi2hLzwSFzO296uFDgmKCTXJlnR8MW4hZr67Dy8e2I+/Od5xV0CRd1e0Ojnoi0BiZoIacGzvI87oOX+hqjW3shlsMWt9skrBmWwDoMPU6kYp3YUoMjnngEjGEHzVkgZXxD/quBJlXdfyu7b5NQqoEQuUlTBNXVQhqa7RFuKM9l1G1+1L921+b4IRcMW5lPZU0Q1UV52OWCyUpJO1qbYU3rReAmuL2SwZZlHBOY03YUtaxCaJX66BkzyK/g8GWGwrGsVLnzw80cwHdUbZ/k/gxfcBf9qYPFB9+rEJJyIK2l5yi086XfsV/d73hjGRHXFLA3le1vKFE53lsNoDHNkqGh2av7FVUKNLtJfXitBvOqmQhEBiWZBcrmpjQJ6kBJbpHVwjdqF39CVQcj+Dgqu9OaPo6PlcrcgQnT+RcIKyv3GnNNjmDNxcw34vj1l2Bvb9o1JSfNf+JSIWKe6VtTP0yuPmhQi6XwPj7sehUo1vuV7aUBoIHWxRvkFRD1KHPaPeVORsv4okVqLJ/1NS0GkRpkzfVyEFR0MPvgLZtopxNFikXCbd83p2YqDrL4z4hp2VLQByNLHocX871MS3rqpEWEDQkZ4jgxC+kmGUcHgoNbrmAuiNMBtSlXz//0VMAxfhz6Kl9fFlu+6ruBekiZzMD9iKV//kOMB3MT7QGqkZblOnerz3lqiCILSfvvYzyYWfziTE2cMnO29CR2c33obXU5pLvjJbJ8feMHi13vmdCNLVTGfuXpYduIcXmGBjTQ64SGiRrqZ3cxgIC0LFwasttPR5mJ1VWzOvmb1fHndNEqULM2oOx4WT6jmoUwMhaxsOP13NzcHac5GmUlvw2Sd/OzbR4xvp0 T4VRCAkH R9n3U6fD/jAzNWjkkxEkcAwYpYbFqbaNWJ/MSOXXkIwun98GWiJcMYyo6YF0vwFNPV44eqT+tUB8jmzgSYxO7PduxJWPBz3DdsDQrJQd6rcjnCKpLYxYvGDP+nzSet2qgm1+gMWY+e8c1D4rk21WVhDBVZrPkR2+IkXYf4itbmGoxL+4pjl0FZ8jxX83UBH2znW9z3rBdPRqfNqXdiM6CWax0p8DOfsvoIE3JKiaHrNuioHU9hz8Ckylnws3xdmsyOC6q6yw+/DiL/H0mPsrMQMJv1uOS3H4ko4tShY2CTYzYhlkwUDOjPHV0kIYwWDOnFYi5nR58ZYH+so9QPAp2ROvMfBGk9/ELdfekwrnKiE23b5w3h1s8OgIE+2A5V9EfS4d1Q8xWn6M6wn6U2QFUr6Slsg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the helpers to simplify code. Cc: Paul Moore Cc: Stephen Smalley Cc: Eric Paris Acked-by: Paul Moore Signed-off-by: Kefeng Wang Reviewed-by: David Hildenbrand --- security/selinux/hooks.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index d06e350fedee..ee8575540a8e 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma, if (default_noexec && (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) { int rc = 0; - if (vma->vm_start >= vma->vm_mm->start_brk && - vma->vm_end <= vma->vm_mm->brk) { + if (vma_is_initial_heap(vma)) { rc = avc_has_perm(sid, sid, SECCLASS_PROCESS, PROCESS__EXECHEAP, NULL); - } else if (!vma->vm_file && - ((vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack) || + } else if (!vma->vm_file && (vma_is_initial_stack(vma) || vma_is_stack_for_current(vma))) { rc = avc_has_perm(sid, sid, SECCLASS_PROCESS, PROCESS__EXECSTACK, NULL);