From mboxrd@z Thu Jan 1 00:00:00 1970 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 us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3DF90C433EF for ; Wed, 15 Dec 2021 17:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639590232; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rymug8Auh9mUTcTT/9aZaCSQQ59vQU/uYt1oaClAdmQ=; b=gKL2U9R/owytI99zSDlIsBDb2rtFcUcT0eJt7o0vFV+3WTNzS9YCHbJ3HH/7R09gsOdL96 rUSsU+B9Lc4nA1tuGsY91R9lUGWsn8X5ZhwGJxUefK7bxRbmUBofBl+/iE5NSLLqIfOFhP DAQGXLoQrj0i3podNNQN3JayGoWMmaA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-Zmv7OVWANfCU2sPoebb82g-1; Wed, 15 Dec 2021 12:43:48 -0500 X-MC-Unique: Zmv7OVWANfCU2sPoebb82g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C72781EE91; Wed, 15 Dec 2021 17:42:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3957E5BD10; Wed, 15 Dec 2021 17:42:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CA03E4BB7C; Wed, 15 Dec 2021 17:42:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1BFHgSe9018208 for ; Wed, 15 Dec 2021 12:42:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2F2EA1037F3A; Wed, 15 Dec 2021 17:42:28 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.2.14.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A80910246F6; Wed, 15 Dec 2021 17:42:26 +0000 (UTC) Date: Wed, 15 Dec 2021 12:42:24 -0500 From: Richard Guy Briggs To: Paul Moore Subject: Re: [PATCH] audit: ensure userspace is penalized the same as the kernel when under pressure Message-ID: <20211215174224.GS1550715@madcap2.tricolour.ca> References: <163949858723.23091.5301356986109432893.stgit@olly> MIME-Version: 1.0 In-Reply-To: <163949858723.23091.5301356986109432893.stgit@olly> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: linux-audit@redhat.com Cc: linux-audit@redhat.com, Gaosheng Cui X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On 2021-12-14 11:16, Paul Moore wrote: > 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. I can't speak to the exact wait queue mechanism here, but this seems like a reasonable action in this location. FWIW: Reviewed-by > Reported-by: Gaosheng Cui > Signed-off-by: Paul Moore > --- > kernel/audit.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/kernel/audit.c b/kernel/audit.c > index 4cebadb5f30d..eab7282668ab 100644 > --- a/kernel/audit.c > +++ b/kernel/audit.c > @@ -1540,6 +1540,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); > + } > } > > /* Log information about who is connecting to the audit multicast socket */ > @@ -1824,7 +1838,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; > > > -- > Linux-audit mailing list > Linux-audit@redhat.com > https://listman.redhat.com/mailman/listinfo/linux-audit > - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635 -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit