Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp501688ybe; Wed, 18 Sep 2019 22:10:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXdBEN/uagCOh9d7bVetn4UIlat6QVw1MfDhIyfh0+dl0jlUYzYY+j5soaJlGnfIevpCPn X-Received: by 2002:a50:ef12:: with SMTP id m18mr13972338eds.18.1568869855543; Wed, 18 Sep 2019 22:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568869855; cv=none; d=google.com; s=arc-20160816; b=CTRtSwFRasXBDYv+2WvdyGmAyn4x2zSwnxQg0LeTVlH/YyGN4ZL2d2ubK8MsSoaxdW 4ivCumUfX1K3ZQ1XlNAE7C6oAbAzgM7reMzjld2tB0BkU8/00NXhKIu2SezCo/ooO96U MZm+1S28fFa+DmI6CaPuns4/L8fOSYB47Yz2yBjZXfiUmDGW31kEGNvCn2H2p4Sre85U ELJuTVbtuQIzvBYLNNrg2wKdz47V/HUlVveFOfGPVoSV7SdtECvSh72+qvmDeROXeXxc WsUM6U/HBvEH9M8pqhxdMLNrHZ7yCZMPIb89MirwNWcSlDiax6mmgrpwBZD8i2plYd2r yRnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=5UqVsB8OgH3jRI39XpbxUP/cx/cFFd9hFdT+My3pv9w=; b=Th+0F4F/2Ax+YlmlBgsQiMmbX+22dlKmsrjInqHbqAPcyPNWL2z4z3KP9ME0UkhUFY OFY6ZFBiruoz7kK8ZbGrHj7E30fbciEeKGIcE6ZC+s7qljYKXgJ5w31JvNBjIwIXbkdr DGS4I+8WeWi0ZrY7g6U2C2wDpkQPsyJ7NIKIqMb1XCIX2hrjLLxKe5Ln3WRmoNv+tKHv SpjWyPB9zoj0lEKtFJIpcDw2cIUkBT1ChU61RVbs3UGnB6L8srpFQdA7sc0zakfLOkW9 xSoIkDa4W7mv4Yqj5DjDoA91jazq9Si3tqR8znYbYQUGiAnZ84jP5JuRtBFwR/4IvZCV 262Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id op4si3999469ejb.77.2019.09.18.22.10.28; Wed, 18 Sep 2019 22:10:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387579AbfISBYl (ORCPT + 99 others); Wed, 18 Sep 2019 21:24:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55385 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbfISBYk (ORCPT ); Wed, 18 Sep 2019 21:24:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 141B5C057F31; Thu, 19 Sep 2019 01:24:35 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1E7E60C18; Thu, 19 Sep 2019 01:24:18 +0000 (UTC) From: Richard Guy Briggs To: containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org Cc: Paul Moore , sgrubb@redhat.com, omosnace@redhat.com, dhowells@redhat.com, simo@redhat.com, eparis@parisplace.org, serge@hallyn.com, ebiederm@xmission.com, nhorman@tuxdriver.com, dwalsh@redhat.com, mpatel@redhat.com, Richard Guy Briggs Subject: [PATCH ghak90 V7 06/21] audit: contid limit of 32k imposed to avoid DoS Date: Wed, 18 Sep 2019 21:22:23 -0400 Message-Id: <230e91cd3e50a3d8015daac135c24c4c58cf0a21.1568834524.git.rgb@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 19 Sep 2019 01:24:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Set an arbitrary limit on the number of audit container identifiers to limit abuse. Signed-off-by: Richard Guy Briggs --- kernel/audit.c | 8 ++++++++ kernel/audit.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/kernel/audit.c b/kernel/audit.c index 53d13d638c63..329916534dd2 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -139,6 +139,7 @@ struct audit_net { struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS]; /* Hash for contid-based rules */ struct list_head audit_contid_hash[AUDIT_CONTID_BUCKETS]; +int audit_contid_count = 0; static struct kmem_cache *audit_buffer_cache; @@ -2384,6 +2385,7 @@ void audit_cont_put(struct audit_cont *cont) put_task_struct(cont->owner); list_del_rcu(&cont->list); kfree_rcu(cont, rcu); + audit_contid_count--; } } @@ -2456,6 +2458,11 @@ int audit_set_contid(struct task_struct *task, u64 contid) goto conterror; } } + /* Set max contids */ + if (audit_contid_count > AUDIT_CONTID_COUNT) { + rc = -ENOSPC; + goto conterror; + } if (!newcont) { newcont = kmalloc(sizeof(struct audit_cont), GFP_ATOMIC); if (newcont) { @@ -2465,6 +2472,7 @@ int audit_set_contid(struct task_struct *task, u64 contid) newcont->owner = current; refcount_set(&newcont->refcount, 1); list_add_rcu(&newcont->list, &audit_contid_hash[h]); + audit_contid_count++; } else { rc = -ENOMEM; goto conterror; diff --git a/kernel/audit.h b/kernel/audit.h index 162de8366b32..543f1334ba47 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -219,6 +219,10 @@ static inline int audit_hash_contid(u64 contid) return (contid & (AUDIT_CONTID_BUCKETS-1)); } +extern int audit_contid_count; + +#define AUDIT_CONTID_COUNT 1 << 16 + /* Indicates that audit should log the full pathname. */ #define AUDIT_NAME_FULL -1 -- 1.8.3.1