Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3573121pxb; Mon, 24 Jan 2022 12:32:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxU/hRbcn1xjMfTRIsrC/srvsENdmvGekAGdpZ5wJ08JP2qVBwiacmWdQn47s0Zvi1asZlG X-Received: by 2002:a17:902:aa88:b0:14a:bd99:24ad with SMTP id d8-20020a170902aa8800b0014abd9924admr16318513plr.162.1643056363077; Mon, 24 Jan 2022 12:32:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056363; cv=none; d=google.com; s=arc-20160816; b=j9fHCUYkEONdAEWOM9ZOtF2VY1dCQxlET+UWBPfuSlWDoEU240BTfKmvAfJF4/RUj6 oa7vOrz+4wkU8m0WfmISKyuS7DXIn0fFhTMlpvKlboSfFAiTFIqq5VpIBaGJjlwqiIJs fzMxCTjVYnVcVAj+qaByVQqeTzjY2+1jTv7REGrkZ1+6DpAyvcq19T0K8hVYS/mJSJI8 8sgOCNdXmZiS497wah+HSc0YtaC/AQ80FCFVQgh4TtMvnNx3lm5wZTRLsb7DPKTAddI8 ykQAtBffswU0odxoPCeDsnaYp8QY01qeAxG94UQA329OTaPzobiJs0wFmikjN3V/yusu ulJg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6PMlAuQpuOH7T09hpJPO38n2XU31ytuKP+d5GeAMkOE=; b=nDfEDSLbU6dxnl/l/SAMMNMZAtNI7b007n5r9s9cRG2ltwkmEOoE+FKgbfTjHvNwBo pAJgwwxggdDdezHMuFmKY23OP+9sL9sTEloNh0koGtakLdSBuPCEarm4mdEQjqYqJJM+ UYHOpSpf3sCHHlKH3M18Hg7jRW+vVmo9TXrqyjQRyCC4i24rjbVeF4Ioc0q9iVCdZIQz WArxhARzNhGvJdw1Fgf0tcMG3cnA0iumWhrvDjzmz5hhenbZQ0j+vj91GCMQMU4dMNst V2ktJRJeK3xJyfBkMax1L021JWlwMTkKR4ma0UKgHtZTz6/oF73g0nzYh4FWCweXG2E8 VeeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O9ukjqbH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si16130566plg.418.2022.01.24.12.32.20; Mon, 24 Jan 2022 12:32:43 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O9ukjqbH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355073AbiAXTj4 (ORCPT + 99 others); Mon, 24 Jan 2022 14:39:56 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33022 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349435AbiAXTeK (ORCPT ); Mon, 24 Jan 2022 14:34:10 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7B0D06141C; Mon, 24 Jan 2022 19:34:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 878CBC340E8; Mon, 24 Jan 2022 19:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052847; bh=Mux5XJTW3pJiVPcl/iFS7hUyFsEJtVaPya5qb4ckeX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O9ukjqbHFJI4u8EK1acklXuedqBmPLnXrLweHxEetECjZw82iZ4mMNVCasmYBYrr1 MBTvJLkCT8KO/moM68GiNrtPHZKITlHYxs45LsJfDexELOzbxZ5hzuHgnSjH3RoUX0 65gz8wDOWaHR28XHTHrRdZeQAxGGOU9IHucnPyIM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gaosheng Cui , Richard Guy Briggs , Paul Moore , Sasha Levin Subject: [PATCH 5.4 193/320] audit: ensure userspace is penalized the same as the kernel when under pressure Date: Mon, 24 Jan 2022 19:42:57 +0100 Message-Id: <20220124184000.210055259@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Moore [ Upstream commit 8f110f530635af44fff1f4ee100ecef0bac62510 ] Due to the audit control mutex necessary for serializing audit userspace messages we haven't been able to block/penalize userspace processes that attempt to send audit records while the system is under audit pressure. The result is that privileged userspace applications have a priority boost with respect to audit as they are not bound by the same audit queue throttling as the other tasks on the system. This patch attempts to restore some balance to the system when under audit pressure by blocking these privileged userspace tasks after they have finished their audit processing, and dropped the audit control mutex, but before they return to userspace. Reported-by: Gaosheng Cui Tested-by: Gaosheng Cui Reviewed-by: Richard Guy Briggs Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- kernel/audit.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kernel/audit.c b/kernel/audit.c index d67fce9e3f8b8..146edff0c73ec 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1528,6 +1528,20 @@ static void audit_receive(struct sk_buff *skb) nlh = nlmsg_next(nlh, &len); } 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)) { + DECLARE_WAITQUEUE(wait, current); + + /* wake kauditd to try and flush the queue */ + wake_up_interruptible(&kauditd_wait); + + add_wait_queue_exclusive(&audit_backlog_wait, &wait); + set_current_state(TASK_UNINTERRUPTIBLE); + schedule_timeout(audit_backlog_wait_time); + remove_wait_queue(&audit_backlog_wait, &wait); + } } /* Run custom bind function on netlink socket group connect or bind requests. */ @@ -1772,7 +1786,9 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, * task_tgid_vnr() since auditd_pid is set in audit_receive_msg() * using a PID anchored in the caller's namespace * 2. generator holding the audit_cmd_mutex - we don't want to block - * while holding the mutex */ + * while holding the mutex, although we do penalize the sender + * later in audit_receive() when it is safe to block + */ if (!(auditd_test_task(current) || audit_ctl_owner_current())) { long stime = audit_backlog_wait_time; -- 2.34.1