Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3256011pxb; Wed, 13 Oct 2021 02:12:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTs34T86dgndUZ6OVccflqVSPVTfTrIfupq8SiW2KjnOiLMhSsg7SyR+Qv4LfL86WFPYR/ X-Received: by 2002:a63:374c:: with SMTP id g12mr26847974pgn.35.1634116329200; Wed, 13 Oct 2021 02:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634116329; cv=none; d=google.com; s=arc-20160816; b=ezK1VAUffut26ePT2FdW/STLQ7Jdmb9M9Pfuw5toI6Jz+4kKHbElUQ8heqn7PB/OHI Eey2uRmXa4a8DjKgQPV7xKZFJYC07L5dOjsOzN+uOj5p/59JM+rb1xWKazA11ptPsGeM P4jgqOYeUgVy/MkUehaViPGpcSPfb4wbfC6k8S9OiFh49uVdJtoBaPVp5wV0wxZ3nnvy paLTEdNGPiU5h80FmoYwWfJXlyfuR18+goFkBZBOmjalw2jSvlxQspQFF0ggjdyFIAY4 ElXEomEhxFgDnZV2fBKwL2WRRaFHp4bsNpgTqeHFO74kPdSgSACoxcGSBkxZe99pxZMr 1wSg== 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=CUq6J5SPHjf5IQYQ3l5uYdG06qKcy9LBJWf3prgMorw=; b=DOqUUqS0PzttbAXDUFrHFg9nobiny6k2aqWJhD8VX2LD16IRcYQZy9N1054QqHIe3v vZWnoChtqn3A3OYHCSb5M1rV8MLqipLBq58og5z+Zna2uZvTFexYLujK3UoDjgoxo6U3 V9dgVJDAb6G26WwI63usPyeElRul90bmASrLPgMJlrcMcoDpbNR8DXs0u+6V/WsIaouE 3MdYAIUNBymqJlWL5ix5CdTrw1YNtGhKNl2oE4xVpy221CcjoeR1pnUbeNnozN5otkCr GwzqKwYDdIP6j00CJX9QjGOUVNxIvgpV4m11bkFdc8PZ6sa2QPVwDrhsxwNgJ/HJX0yP O/TA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g187si3553783pgc.477.2021.10.13.02.11.56; Wed, 13 Oct 2021 02:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239008AbhJMJMO (ORCPT + 99 others); Wed, 13 Oct 2021 05:12:14 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:25127 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238942AbhJMJMM (ORCPT ); Wed, 13 Oct 2021 05:12:12 -0400 Received: from dggeme762-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HTmsq1PHSz1DHS1; Wed, 13 Oct 2021 17:08:31 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.44) by dggeme762-chm.china.huawei.com (10.3.19.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Wed, 13 Oct 2021 17:10:08 +0800 From: Gaosheng Cui To: , CC: , , , Subject: [PATCH -next,v2 2/2] audit: return early if the rule has a lower priority Date: Wed, 13 Oct 2021 17:12:08 +0800 Message-ID: <20211013091208.36209-3-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20211013091208.36209-1-cuigaosheng1@huawei.com> References: <20211013091208.36209-1-cuigaosheng1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.44] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme762-chm.china.huawei.com (10.3.19.108) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is not necessary for audit_filter_rules() functions to check audit fileds of the rule with a lower priority, and if we did, there might be some unintended effects, such as the ctx->ppid may be changed unexpectedly, so return early if the rule has a lower priority. Signed-off-by: Gaosheng Cui --- kernel/auditsc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 42d4a4320526..b517947bfa48 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -470,6 +470,9 @@ static int audit_filter_rules(struct task_struct *tsk, u32 sid; unsigned int sessionid; + if (ctx && rule->prio <= ctx->prio) + return 0; + cred = rcu_dereference_check(tsk->cred, tsk == current || task_creation); for (i = 0; i < rule->field_count; i++) { @@ -737,8 +740,6 @@ static int audit_filter_rules(struct task_struct *tsk, } if (ctx) { - if (rule->prio <= ctx->prio) - return 0; if (rule->filterkey) { kfree(ctx->filterkey); ctx->filterkey = kstrdup(rule->filterkey, GFP_ATOMIC); -- 2.30.0