From patchwork Wed Jul 12 14:38:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 119223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1192331vqm; Wed, 12 Jul 2023 07:32:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlGnpe5gKtACXkpPPDYqLBiWrXQu3Kj3bA3Sx07PAnTVVwjlNoBR9qDFWdDmMWPo6Fa3Jynt X-Received: by 2002:a17:906:4792:b0:991:d5ad:f1a7 with SMTP id cw18-20020a170906479200b00991d5adf1a7mr24558792ejc.51.1689172328934; Wed, 12 Jul 2023 07:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689172328; cv=none; d=google.com; s=arc-20160816; b=QsXWEtaTysyYSWs2tZzYfNeWiz7vbrCZZOYiSNBAN/S1GyP1cII+2yHZc+U8AmCuA+ yQet9N/+mYBZLEXNBx9BS5PM0wByxy4ZTITjRAZyPROaXGu1g1P2UOBJY5rQ/1FK/iKo odVFlqPtzEIuAi60k25yrUuAbixbUzU3Dqqh1H+nzIEkuquGjw8DVuuQAUqtcjL74OgS us+qRsBvTDMvDc+Kaz8QqCk8MGa2ff/LADPHwdJNYg3GLnXsJ3hRigthF+15PIbZzH2v kvJ1uNFcT17ES/Q78NDo6K8T2NCDMOwcmg9KRxbyPehQ0iuwvfAUUuoD/1NeYryxghpH zUkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cog3zFED0zqk0ayh/5AST+3VWG2EFfyBo0064QrevtA=; fh=FRon72YwFeIVU/LlfmPNxuVFiduvQKfa+Ydvnh8xLfc=; b=nzL63ztNOed+mrhxHRb6tta3E2HAlYUsW/VhbNBAmFCFquQht/pVbc+ZZVSLxr+Jeq cQv9AtflZksex6tI7BjxIAGDv0WlP6Gi3NZDs9dQkFgo/LKEgj3HyamcI5IWGbHzULn2 CdRuNYBhyj9Eg0oKwpLqqYjr3wNmJ3F78Q1l7ShMKYYNyp0v9H57mDqrntaMc3TZ22k9 SdFPxm2GouUVUoG9AVg88k5FEgFDbizr4QN4UtOMfdjU/C1If9wYwXqIA2XSc8omu9Kf jNJGfgDcIt1i7XWC+TX0zdlCaGkPhGkLLCHdLxOAYEHEjJfMkUjgYaApvOe/6DD91UG7 SuvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b27-20020a170906491b00b00982a3005cf7si4374079ejq.605.2023.07.12.07.31.45; Wed, 12 Jul 2023 07:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232187AbjGLOZ2 (ORCPT + 99 others); Wed, 12 Jul 2023 10:25:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232138AbjGLOZV (ORCPT ); Wed, 12 Jul 2023 10:25:21 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C4B619BE; Wed, 12 Jul 2023 07:25:16 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4R1KhZ0q0bzPk8H; Wed, 12 Jul 2023 22:22:54 +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, 12 Jul 2023 22:25:13 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , Kefeng Wang Subject: [PATCH 4/5] selinux: use vma_is_stack() and vma_is_heap() Date: Wed, 12 Jul 2023 22:38:30 +0800 Message-ID: <20230712143831.120701-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712143831.120701-1-wangkefeng.wang@huawei.com> References: <20230712143831.120701-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771225563603282975 X-GMAIL-MSGID: 1771225563603282975 Use the helpers to simplify code. Signed-off-by: Kefeng Wang Acked-by: Paul Moore --- 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 4e46cf3d67b6..289ef2d6a427 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3775,13 +3775,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_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_stack(vma) || vma_is_stack_for_current(vma))) { rc = avc_has_perm(sid, sid, SECCLASS_PROCESS, PROCESS__EXECSTACK, NULL);