Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp344381ybe; Wed, 18 Sep 2019 18:33:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7kkAo2bmAVZQdDHBPNPamo2yQBpdqnbedoN+TJHCDFABhC0i/SXX5zmV6QHkjKwSTzKWF X-Received: by 2002:a50:91d8:: with SMTP id h24mr1292395eda.61.1568856825303; Wed, 18 Sep 2019 18:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568856825; cv=none; d=google.com; s=arc-20160816; b=dJa7+4muesCz6JdwsC5zL2eMtROPgZXo6p8dp+AL0qKX+Ub2PnDS3V1w7uoE+u69aW rtrHlj2Q2IhXLGuIKAriCfie6+5Hp2U8pHaNSoQJ8gcJNCiZwT64O/1RmGdDaQNeeDzf VYANrMWVo9r2eJSaY7I6Q3L3onOip5FjZf4rTLBkaW2ZlNGUNNNQS2O6LtGn9TgLMYrB RTYf9Nej64Z4oFQBdJWZeY83g88eNoAgf9bz/f7J29BOfaL2pY5zWfg1Rn6JgS5W9DS0 0r7uAJbfKCtH7S07Doq28+XZIbyVO1bqLq+yfNs5mE4kbPJxMJtBD04ZSzhtBq1t9sri 2IZA== 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=PnWsQr0sbHRKCCNEIuxzNHK3YEAYZ39+1Krtyo9l16Q=; b=AlpUp2qT179G86vGUmhyLihIhxiAOGPfVFb4txDCZYOxd0IZIC6Hzao8PvrjINLAB3 Yd7K+WKyniVNO4f0OJLuR4u/w3BCQacXWK+vrC5xDH+t2VBASFoo4hqYd1znTUKfRkIe DZeSxJX7xZOKJlvd4yL3uHHwagWhKJWEkszBcSkn+yG6LyJ5CFCtuaInLA3P5cI/LgWG t0U0R/LmsirInQbiY9LgqRAaseXY+apgj+FuYelXPspJpVh3e6eC+OHaRaL/sxdAueS8 Q09pjmhLfAgWDWeWJpqj098oaqxWCy8I9xjYQKuKhKBvbhvMN4+MlCW5U1Rmt+RXmte4 vEzQ== 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 a8si5011775edm.240.2019.09.18.18.33.22; Wed, 18 Sep 2019 18:33:45 -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 S2388064AbfISB1n (ORCPT + 99 others); Wed, 18 Sep 2019 21:27:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50522 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387591AbfISB1m (ORCPT ); Wed, 18 Sep 2019 21:27:42 -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 066FE3084295; Thu, 19 Sep 2019 01:27:42 +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 31F5B6B49C; Thu, 19 Sep 2019 01:27:33 +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 21/21] audit: add proc interface for capcontid Date: Wed, 18 Sep 2019 21:22:38 -0400 Message-Id: <67a482f9dcde6362bbca2a2facb24a3d68e0c07a.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.40]); Thu, 19 Sep 2019 01:27:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a /proc interface to capcontid for testing purposes. This isn't intended to be merged upstream. Container orchestrators/engines are expected to link to libaudit to use the functions audit_set_capcontid() and audit_get_capcontid. Signed-off-by: Richard Guy Briggs --- fs/proc/base.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index 26091800180c..283ef8e006e7 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1360,6 +1360,59 @@ static ssize_t proc_contid_write(struct file *file, const char __user *buf, .write = proc_contid_write, .llseek = generic_file_llseek, }; + +static ssize_t proc_capcontid_read(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + struct inode *inode = file_inode(file); + struct task_struct *task = get_proc_task(inode); + ssize_t length; + char tmpbuf[TMPBUFLEN]; + + if (!task) + return -ESRCH; + /* if we don't have caps, reject */ + if (!capable(CAP_AUDIT_CONTROL) && !audit_get_capcontid(current)) + return -EPERM; + length = scnprintf(tmpbuf, TMPBUFLEN, "%u", audit_get_capcontid(task)); + put_task_struct(task); + return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); +} + +static ssize_t proc_capcontid_write(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) +{ + struct inode *inode = file_inode(file); + u32 capcontid; + int rv; + struct task_struct *task = get_proc_task(inode); + + if (!task) + return -ESRCH; + if (*ppos != 0) { + /* No partial writes. */ + put_task_struct(task); + return -EINVAL; + } + + rv = kstrtou32_from_user(buf, count, 10, &capcontid); + if (rv < 0) { + put_task_struct(task); + return rv; + } + + rv = audit_set_capcontid(task, capcontid); + put_task_struct(task); + if (rv < 0) + return rv; + return count; +} + +static const struct file_operations proc_capcontid_operations = { + .read = proc_capcontid_read, + .write = proc_capcontid_write, + .llseek = generic_file_llseek, +}; #endif #ifdef CONFIG_FAULT_INJECTION @@ -3121,6 +3174,7 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns, REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), REG("sessionid", S_IRUGO, proc_sessionid_operations), REG("audit_containerid", S_IWUSR|S_IRUSR, proc_contid_operations), + REG("audit_capcontainerid", S_IWUSR|S_IRUSR|S_IRUSR, proc_capcontid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), @@ -3522,6 +3576,7 @@ static int proc_tid_comm_permission(struct inode *inode, int mask) REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), REG("sessionid", S_IRUGO, proc_sessionid_operations), REG("audit_containerid", S_IWUSR|S_IRUSR, proc_contid_operations), + REG("audit_capcontainerid", S_IWUSR|S_IRUSR|S_IRUSR, proc_capcontid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), -- 1.8.3.1