Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2000765pxb; Mon, 11 Oct 2021 18:33:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj/tQAqkwc9KOE8ZykP7BGJFRfw8cnsESLIM7qn+SMRVnRFOsS7JipKTwrVOvgnBJdreOO X-Received: by 2002:a17:906:454a:: with SMTP id s10mr29817313ejq.11.1634002437966; Mon, 11 Oct 2021 18:33:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634002437; cv=none; d=google.com; s=arc-20160816; b=dQ/UFPlUWArAx5AtwoFclmTGbtueTcZZh50V2vNd2aSQdzgjV4cgGofXeKpQ6BLLOE EcWAENVaVSjr5EVSDcPg9tSwJe3vr6xNOUJFnscnKcRSsSmite5S/vfi6cmR8UhkMozK 4QfAf3Mi0c0j9TTftYy4vKToRsjMIdnKrqX/OUrtqpHVTYy0eyXyt8jRLJqQS15hQ0up mbNG4K5Bsbe3OECN4b4+JiiCDqT9/ku4046HFQeNdsJ5Vghr0YlJQufbyms0PYNr9agE wmtSi3NcU61dqQ4MEtkZvDhdPzJfd6gfwG6H4beQRt0dswcjboTrxWk7MvhxoEWBhdc5 8U4g== 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 :message-id:date:subject:cc:to:from; bh=xMdUAiP6QFrTHTdMiZ8CmakCShys8nLwv/Ckh/3gui8=; b=YpFoiU0CxukglNLf+WDV3fzm+cqXf0OnAsdMr6lBUYrQEbrAkZCYqkrDvzPpYFj+b4 kJ2TYu61wNfz1N6Kc9FmtKkJoIhRdGWbBwIBmIzVvInyqUmJgEBuScCYL7YYIGU7z5mI z6GSE1Lhd8G2juSAVX/YBzI+i1NVIrjGap/aEZmkoUm8RPaAIEPVrxeNSzuhx+0eYSKB VBtqCChWVxj+wVCs/ItUlM7nXhXvAfzojL/AgP0DS6US7CNMjPits5CSjQyGhciGijW+ axH9YOeaLxvI7WV2EEyD+HRcUjEYNtH3Z0MXNPi+0NNM1te/AQ3cl8NA0xcGT8mDu/16 7rfA== 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 v11si12802296eje.169.2021.10.11.18.33.19; Mon, 11 Oct 2021 18:33:57 -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 S231873AbhJLBcl (ORCPT + 99 others); Mon, 11 Oct 2021 21:32:41 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:13720 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbhJLBcl (ORCPT ); Mon, 11 Oct 2021 21:32:41 -0400 Received: from dggeme762-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HSyk71006zWP0G; Tue, 12 Oct 2021 09:29:03 +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; Tue, 12 Oct 2021 09:30:38 +0800 From: Gaosheng Cui To: , CC: , , , Subject: [PATCH -next] audit: return early if the rule has a lower priority Date: Tue, 12 Oct 2021 09:32:40 +0800 Message-ID: <20211012013240.63072-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.44] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 4ba3b8573ff4..eee14dfad0fa 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