From patchwork Mon May 8 07:58:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eiichi Tsukata X-Patchwork-Id: 13234194 X-Patchwork-Delegate: paul@paul-moore.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C92FC77B75 for ; Mon, 8 May 2023 07:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233630AbjEHH64 (ORCPT ); Mon, 8 May 2023 03:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjEHH6x (ORCPT ); Mon, 8 May 2023 03:58:53 -0400 Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E35B9036; Mon, 8 May 2023 00:58:52 -0700 (PDT) Received: from pps.filterd (m0127844.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3487QqkH011998; Mon, 8 May 2023 00:58:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=+5ZIFcAXGaOEr6fcSRGPnoy06NRtoIMGpCCS8rABMCY=; b=c8Z5x9+TFKK1HnH7g4bfDAG41bjVGVVVltgsthZaNT9+6GNDfiN/eeG84j/L80lGitAd gIA7f5ZiD3DBCh8TAlGjdBNm2JaiQZ0axM092kZWrqe4KyX+khugUT3TIF+rT1cDfEVt Vw+PphrtcZPRLv3Pwv8rhpqNrSz7E2HCgus4y9wT86PpT4eW4BrGcVU101rKDcWH38S+ hWCsvrkbzFEIYjwkanqdDj1bucTFA/afMHZT7MWueYL/Dr49T1KuhcWdzeD8Kf2s9BzN y6462MqSFizuGNwrmfED4a3QE7F2h2SxR1IWx666KxGK3TPkldNYCy34ckwHLgfwFnGO sQ== Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3qdpe43n4a-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 May 2023 00:58:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ANX1N8usmCIzUOlZpL5jCnNRX1n34900FjZEgy0tVA0GRJLw92W3Rsa0VjWZqBq+mQkxj/a2DWrAzrVK0OppPJvbqNY/6+pVCLD6Niz+hsCE9mw230qiIJ6IMInXmEhanNpdNyjB+VVc1PybwEiLZLYU94DmSqk5x5XXgxMosKhu/ZAHh5xKuOFZUqv5elayXeHKd/+2QPAb/JP2tc/OwH1cGsSfDo9JlODDGA3IpiMNzyWfmoG/+/Oo4yBJreZLcRvFPjlPRVLqlo/iH2xi1Galpa9Zc9gJsOOFSaH4s34GTJj+GkJW/wC4H6QBqCscvSBykfUCfvj0Dcn0/WiHww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+5ZIFcAXGaOEr6fcSRGPnoy06NRtoIMGpCCS8rABMCY=; b=aeB8elVbC3S/gWAjTAsjZ5AMm8hvI16kx+ajWjynI62J0nJbeoi6UnLmAY9TLR/wBfPbM6OSG9geyE5C1ZaI2br3PK7eSLXDVq6aqO8DgBkbjyF+YJ0sb5fKWzpy1lhaocXfZgW1GO9Oy4amcF2ffrwidWD8dTSdET6nYdpgfDtOh6bIPWDpPztYujL8U4xpsRaOGIE1GMxUdhAMVn33SjfDtr6v5sD7rQLiC+cyr/q08enSICfWJH+MPuu2XPqR0MhQCb0op4jd5uQ4kfExG9ext6vqKCLlHwv61IXQkSyIHQknLESYhTWlBXBJACbnTVI9O3P/wGYPf6YuEuZ+3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+5ZIFcAXGaOEr6fcSRGPnoy06NRtoIMGpCCS8rABMCY=; b=KJamil1AJFUaATJCaDLzjFwyZE8+kvlusv17OW39WtR/cNM/S7hQaPPWpR0PsF96LjqOt72m1dk5F9JCVWHoRY+s6E3ImbFCk3FPNlxYMWyqXZC3FFwTHg5JBvi1TNlGf7Wj01Vvji//eGwTR1eeCBUgQfaC8BR+OxEbz8lJFdulI6xd/Ex0kq9vCmuWKWFPqrT47OcSiemPCwkuqMuDmje4L27NGXznhaOTx3DSigqbzLtQDAbEtP3yVyIIkHm8RwB6/hpvJLf5EsTCoAKPkp+Qa4nbzeZf2ZSG5UsdaIhAba/lUBobgkV0qkdUnpve0zgzTMnaLWso5dsFDaqRtg== Received: from CH0PR02MB8041.namprd02.prod.outlook.com (2603:10b6:610:106::10) by SN4PR0201MB8821.namprd02.prod.outlook.com (2603:10b6:806:201::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Mon, 8 May 2023 07:58:46 +0000 Received: from CH0PR02MB8041.namprd02.prod.outlook.com ([fe80::e48:dd5d:b7e4:4d54]) by CH0PR02MB8041.namprd02.prod.outlook.com ([fe80::e48:dd5d:b7e4:4d54%2]) with mapi id 15.20.6363.032; Mon, 8 May 2023 07:58:46 +0000 From: Eiichi Tsukata To: paul@paul-moore.com, eparis@redhat.com, linux-kernel@vger.kernel.org, audit@vger.kernel.org Cc: Eiichi Tsukata Subject: [PATCH 1/4] audit: refactor queue full checks Date: Mon, 8 May 2023 07:58:09 +0000 Message-Id: <20230508075812.76077-2-eiichi.tsukata@nutanix.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230508075812.76077-1-eiichi.tsukata@nutanix.com> References: <20230508075812.76077-1-eiichi.tsukata@nutanix.com> X-ClientProxiedBy: BYAPR08CA0070.namprd08.prod.outlook.com (2603:10b6:a03:117::47) To CH0PR02MB8041.namprd02.prod.outlook.com (2603:10b6:610:106::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR02MB8041:EE_|SN4PR0201MB8821:EE_ X-MS-Office365-Filtering-Correlation-Id: 73e9b20c-5ea1-4916-f7a2-08db4f9a0d05 x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o3XCBNnrheKatITZaBPX6jkuml0Xl2YRwbA/AjS/1ZI9e70TiXGmyjCcmUNAz/nu1WZnslYmc/cNexe1BnT7AsS+YUo+lmCieEkvnckdtROtZXVUY0TlUe6Yb94XR/IjW/4x5C1nJzmkLHQkky0SbyysLp5YtHLKVIDc7MMacUZwv6X1X36R8JYuAQVHXIhG1NcCs+xwy5mUgd0PCINuKj5TBmkBWCNqNd/QqYodkel7WnOyhf58/JPrMj3tR2qBJc8Z9+lOfp6FVIGCoY6A575qiJh3gtXYckot0+MvP/UiEAlxSEnEISLxuv16Xwd9eH/euYL8ehpRUDTwv0qJb3OWD4foz482HYv5VqlLOQw+heQ84SeynTwYmV70sZ3Y5nUhAz5OqeDH0K8tEy87x01yjynfgZ7gv11rQxs8QqIcdb4D/PW8pTHyjZYdN5jqzsjCxSNU6UeMPt38j03FpFr0Od2MO0qmMEZNjJp0MKv4dSyl8JDXz0EWS6Hz2HvthFFvLKkjTq8t2JSTCeGACP7Xw+S/tvSg/j+18MmdQnh+yJzOeYsuGYRaXoC11+i7WVtnEiKUZ8/89eQdp1H5hz2CplFlN3NFDtSklYGYoRPZv0riIDFEjqIIpU8Nm+4i X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH0PR02MB8041.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(366004)(39860400002)(346002)(136003)(376002)(451199021)(52116002)(66946007)(66476007)(4326008)(478600001)(316002)(6486002)(86362001)(36756003)(66556008)(83380400001)(107886003)(2616005)(6512007)(6506007)(1076003)(26005)(6666004)(8676002)(8936002)(5660300002)(44832011)(41300700001)(2906002)(38350700002)(38100700002)(186003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: meh14MsGagUsV/DL6yxsq91wtJK5UDbhCVHw9Ns+1DQHrGqVdzWCUBr76gyo+MAscUl22XVcR4I2v6u1uCFeeYiP0uXXKMim/G57EoFwl9NOb5pC94R7dpOzpja3vyRERgqOBe4A+S+/JRjq061C1bZ2llev7P8Q90nJO63Rl1rM0nkmhlwoVcGnwji0y72w3uRAorl7xXKWeoyZjbw/5mEol9PNULzpk3GDS5//HZ9QxF9DLjEZIL9A9Y0rI4bpqGuUmuayNxlcPqXXVj5au+6kTOC2VS/26MBsYffgej89Yi9E5SxLEh8VBXv4lljGG2hrxMYdlxWQ/ck1dCLVZ4nFs+GEVXCjkIP/ls1kvsF7vBaDuE+zGJxDvlczM6BV8w0HFKVaZzfQ9sgDnI7nY4Kk0m90+OH4oipUvtkn+KCK8/K2UsjXQQDuyu8JYMri9l+0f3ZV0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lLhqGfK/QnKHFLE4pBfxp9y2A74tLzMiO2NfQtwOn1+ynNLqSl3DU75hRnwYl8zTKROCxvQi9bwip6N3MggYwbPOFnGAiE0UwoGdma+Q== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73e9b20c-5ea1-4916-f7a2-08db4f9a0d05 X-MS-Exchange-CrossTenant-AuthSource: CH0PR02MB8041.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2023 07:58:46.6945 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qVdCVjdWAXl+mQx5KDGMBYOX02g/9vP6PCO4x3SGwpKYqc3ETbUYU/5DKZ7RFABJsrOWqTcOpvt8ywtrixt3ZXZ+RhINH5b5EQj2R1+0q24= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0201MB8821 X-Proofpoint-GUID: ozbbm-1Dj_EPgrl8u8CWGgYQAzniaqRD X-Proofpoint-ORIG-GUID: ozbbm-1Dj_EPgrl8u8CWGgYQAzniaqRD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-08_05,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: audit@vger.kernel.org Currently audit queue full checks are done in multiple places. Consolidate them into one audit_queue_full(). Signed-off-by: Eiichi Tsukata --- kernel/audit.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 9bc0b0301198..c15694e1a76b 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -341,6 +341,12 @@ static inline int audit_rate_check(void) return retval; } +static inline int audit_queue_full(const struct sk_buff_head *queue) +{ + return audit_backlog_limit && + (skb_queue_len(queue) > audit_backlog_limit); +} + /** * audit_log_lost - conditionally log lost audit message event * @message: the message stating reason for lost audit message @@ -579,8 +585,7 @@ static void kauditd_hold_skb(struct sk_buff *skb, int error) * record on the retry queue unless it's full, in which case drop it */ if (error == -EAGAIN) { - if (!audit_backlog_limit || - skb_queue_len(&audit_retry_queue) < audit_backlog_limit) { + if (!audit_queue_full(&audit_retry_queue)) { skb_queue_tail(&audit_retry_queue, skb); return; } @@ -589,8 +594,7 @@ static void kauditd_hold_skb(struct sk_buff *skb, int error) } /* if we have room in the hold queue, queue the message */ - if (!audit_backlog_limit || - skb_queue_len(&audit_hold_queue) < audit_backlog_limit) { + if (!audit_queue_full(&audit_hold_queue)) { skb_queue_tail(&audit_hold_queue, skb); return; } @@ -613,8 +617,7 @@ static void kauditd_hold_skb(struct sk_buff *skb, int error) */ static void kauditd_retry_skb(struct sk_buff *skb, __always_unused int error) { - if (!audit_backlog_limit || - skb_queue_len(&audit_retry_queue) < audit_backlog_limit) { + if (!audit_queue_full(&audit_retry_queue)) { skb_queue_tail(&audit_retry_queue, skb); return; } @@ -1564,8 +1567,7 @@ static void audit_receive(struct sk_buff *skb) audit_ctl_unlock(); /* can't block with the ctrl lock, so penalize the sender now */ - if (audit_backlog_limit && - (skb_queue_len(&audit_queue) > audit_backlog_limit)) { + if (audit_queue_full(&audit_queue)) { DECLARE_WAITQUEUE(wait, current); /* wake kauditd to try and flush the queue */ @@ -1866,8 +1868,7 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, if (!(auditd_test_task(current) || audit_ctl_owner_current())) { long stime = audit_backlog_wait_time; - while (audit_backlog_limit && - (skb_queue_len(&audit_queue) > audit_backlog_limit)) { + while (audit_queue_full(&audit_queue)) { /* wake kauditd to try and flush the queue */ wake_up_interruptible(&kauditd_wait);