Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp345447ybe; Wed, 18 Sep 2019 18:34:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+R5joRBaOfFvCJPLUAnzPZ6Cwn+ep/lHZDDqJzOXHMea5JffVtt6XvYI/9APy+faJrGUE X-Received: by 2002:a17:906:3717:: with SMTP id d23mr12208474ejc.266.1568856899550; Wed, 18 Sep 2019 18:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568856899; cv=none; d=google.com; s=arc-20160816; b=rVe2CzElceREXKiY+05tScnN/gZcBB5hFYh5FO10cqcyrlD90LZinV6A+AT0SD3G4q 5pi7JNrpXaW+XaMNOgHB60K+lx+rFYNllQzyUUEZp8HbkAdNWioUju0k7G4kISQQPW6V fy/QqwA0qxqs2YufJbtJ9SBMyLd2RH5akdZslZFkNXiUw8QbxXZHwOFmUHN06EC5YoGW FKhLfqwcEQFx4PvFyydp2ZLN9bV4JXfQLtAgtaEPChuZH34sJ88s5/fksC7i1b9MzVvR CYLf2QNkVf7sJBiylegsSN5rDevoy2v1zbjE6yJAwgYjCERFgrCe1SUdhHnXlqs/6Ksj k0YQ== 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=cGj+GNGA7M0WQqpqb98wuz/HL4FLnUyMUNmLfFV+mmU=; b=Zytsi05Y7mTqoAbHdmriAEy1tIJWRQjhbUF2sKLo2h2W4YKxulTO2vOcGKe0aF+wXj /AUU73c4CenjwWMsoE/dSIOm0c/zfKABxOdZRCd6d92UrWuuPnTpi3Dyxp7dUZc/RNLY sbMFkFG/FrIPqoyZR7fVckEuWwwej12nZ0sy28hcwz5RQV6DW4umnqBE0t6NqkI8/WsA b7chCmoXQzI/7OwUnr3mss2h5fKA6HhcPoaYQ9CMjUDWRvqltrajr0NcHiM9PV4srKzR OzgO2hY4eSze7CuM/riVyx6Fq3QDEa8U9t38Lcv0VnqoZqgYFhLnjNTjVMKGmzdi08ny DqHQ== 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 n8si335871ejh.169.2019.09.18.18.34.36; Wed, 18 Sep 2019 18:34:59 -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 S1732034AbfISB1Y (ORCPT + 99 others); Wed, 18 Sep 2019 21:27:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45526 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727324AbfISB1X (ORCPT ); Wed, 18 Sep 2019 21:27:23 -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 5638E307D971; Thu, 19 Sep 2019 01:27:23 +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 A7B3460F88; Thu, 19 Sep 2019 01:27: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 19/21] audit: check cont depth Date: Wed, 18 Sep 2019 21:22:36 -0400 Message-Id: <8cb68e43b55b1b0a021710402ded89444edaf13c.1568834525.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.48]); Thu, 19 Sep 2019 01:27:23 +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 depth of audit container identifier nesting to limit abuse. Signed-off-by: Richard Guy Briggs --- kernel/audit.c | 21 +++++++++++++++++++++ kernel/audit.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/kernel/audit.c b/kernel/audit.c index 848fd1c8c579..a70c9184e5d9 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2667,6 +2667,22 @@ int audit_signal_info(int sig, struct task_struct *t) return audit_signal_info_syscall(t); } +static int audit_contid_depth(struct audit_cont *cont) +{ + struct audit_cont *parent; + int depth = 1; + + if (!cont) + return 0; + + parent = cont->parent; + while (parent) { + depth++; + parent = parent->parent; + } + return depth; +} + struct audit_cont *audit_cont(struct task_struct *tsk) { if (!tsk->audit || !tsk->audit->cont) @@ -2785,6 +2801,11 @@ int audit_set_contid(struct task_struct *task, u64 contid) rc = -ENOSPC; goto conterror; } + /* Set max contid depth */ + if (audit_contid_depth(audit_cont(current->real_parent)) >= AUDIT_CONTID_DEPTH) { + rc = -EMLINK; + goto conterror; + } if (!newcont) { newcont = kmalloc(sizeof(struct audit_cont), GFP_ATOMIC); if (newcont) { diff --git a/kernel/audit.h b/kernel/audit.h index 89b7de323c13..cb25341c1a0f 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -231,6 +231,8 @@ struct audit_contid_status { u64 id; }; +#define AUDIT_CONTID_DEPTH 5 + /* Indicates that audit should log the full pathname. */ #define AUDIT_NAME_FULL -1 -- 1.8.3.1