Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2612882pxb; Sun, 17 Oct 2021 20:30:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOjSxWNkI/HE7D1tSeczAf227fP5NYPPTGkcBFA43HMFHZsmyVjTPKCy2uXzLTu9n0+HpH X-Received: by 2002:a17:90a:bb91:: with SMTP id v17mr2469893pjr.116.1634527832725; Sun, 17 Oct 2021 20:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634527832; cv=none; d=google.com; s=arc-20160816; b=fhHR7QHvoML6ZvupDIwM0La/E7+tcrAy3eegIJRieVG6RrlxO+Z/mLkVAMhZcSsKVB ixKaV37G4KmHw8PMQzljI2AZ544YDE1bNbRkV99d0VHt6lEkk+yVhybjrB3aSA4dVVDC pAhRa00XnmuBMaxBOBp+4Oqbq8j3Wq8nYLJngSOEKhUxCB1oZxAuZNOUM6kX77d6/m/0 vleJQs8HArOKku5RzD6GlcyLH6gcxw0TRWz9L9W+pZjSoDsQUTq5+edQHskWo4UoOzRU 7vpGdqefax6IglJZWSW6hv0jZTj1yI0kn1Op8uv0/vXv9xdrcewZGqpr0rsniDB+pcVG UuIA== 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=oT4n4zrTi4P8o8gYuglvJfKRcG7hCFA2nHEaJU2E9scHJlTMtJipCfUg5iTaaIbJhZ uDUN2B9r2Y2CdRay0Z6zNyRGLeC4HO/jpqGhX8/f2gyfRK2FnU6zVN/OLPA/YJ6sH7Xh P4b2pja+OnnLQSl80kvb7Bwxy9PQbeIvC7VM6uUewyDpvTTL38xqdnTZWP56ru3D43uF /2DXH6pzLTpB77W9kcuk5TPwYRAdutqq7vpQwwRTCLmQUQQVpR3pL27RoFDxsBYyaKmg 6senLfEp5Q8cFNj7z7Y9MnzO29nnJkK3RGpIEXmPw3a3zccNZNqLFlL/P/5IoH0HWZ9j wbkA== 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 y4si39113pfq.244.2021.10.17.20.30.21; Sun, 17 Oct 2021 20:30:32 -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 S243725AbhJPHYI (ORCPT + 98 others); Sat, 16 Oct 2021 03:24:08 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:28948 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239896AbhJPHYG (ORCPT ); Sat, 16 Oct 2021 03:24:06 -0400 Received: from dggeme762-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HWZGG6WhSzbn8s; Sat, 16 Oct 2021 15:17:26 +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; Sat, 16 Oct 2021 15:21:53 +0800 From: Gaosheng Cui To: , , CC: , , Subject: [PATCH -next,v3 2/2] audit: return early if the rule has a lower priority Date: Sat, 16 Oct 2021 15:23:51 +0800 Message-ID: <20211016072351.237745-3-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20211016072351.237745-1-cuigaosheng1@huawei.com> References: <20211016072351.237745-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: dggems702-chm.china.huawei.com (10.3.19.179) 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