Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp30768imm; Tue, 31 Jul 2018 13:13:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdxfwLDqbRyru/GN6w7Z91XZz59TDHMoNbThAsHIISY8vnE1sdY7kxA4yKUOD7+UiBntL9j X-Received: by 2002:a63:416:: with SMTP id 22-v6mr21809088pge.229.1533068019198; Tue, 31 Jul 2018 13:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533068019; cv=none; d=google.com; s=arc-20160816; b=kyWnwRRWNJEyyZAJNYCtrSA7VDQyb9qtYSKzgq8NoUe9LT+CDR2HU5MVHYCYPUrbmj Rt/zVHWJcKsCCjjcnlFQHxp07oUcImALabfvjbwFcTUNLvOb9+X4VsVlSvKaR/ROigoJ tM1jeVVhNTyb0g/5qLQutB/OsNuaQrzRSMHy5YI3FvkZb42JzV6VIcC+L0Xsz+k17r15 hrENwJAdjLX1VXs8fjXud3Q56nDtbU2uRCnKkICdfkhgqgfiXOPBqSUnOOWFU5LgIXC1 PXvOK0CTJ/2laUdpmhmOlsTpcehbVLnt5vfKm48U1V9gUgo3h0/eHOWfNexRERknI01/ DEIQ== 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 :arc-authentication-results; bh=A3xsj/yPUoJzpzam0kl61ni1QcGPYEfq8JcLCGvxY50=; b=IlOal/8/+VvDBL7lco+KlKLm0/GU8thCQkeMIGKMM1sUrLFXyS7RPX8OlbNvfUtKLp w9lvGS+gnhPAM40hkFdbVXjXWtiqsAY6PPyPcHKzyMjMcG/3DOpFHmc2rFAQFY8GRm59 2SqpcPlwGUIe/j1UhkjU+RjUnriht/IpALrBT7yqJ4sAYnL42AuUm9ftgv5IFraDHS2k +BnDPYc69khGBG+jLiit9fbkSQQmm8OWw85vyy090y0zDJl6Uc0VRlqkNG63JCOzzNJe IiSwLAvUH2ydWl31MvcBKRKgwKi5ApPuup0hqxUCf4Q/8NvwI8cBDvLHsBg9J93VgsgT f9yA== 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 z6-v6si12165631plo.503.2018.07.31.13.13.19; Tue, 31 Jul 2018 13:13:39 -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 S1732792AbeGaVxw (ORCPT + 99 others); Tue, 31 Jul 2018 17:53:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36236 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726518AbeGaVxw (ORCPT ); Tue, 31 Jul 2018 17:53:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD26887A74; Tue, 31 Jul 2018 20:11:52 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-17.rdu2.redhat.com [10.10.112.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id D37162026D7E; Tue, 31 Jul 2018 20:11:49 +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: luto@kernel.org, carlos@redhat.com, viro@zeniv.linux.org.uk, dhowells@redhat.com, simo@redhat.com, eparis@parisplace.org, serge@hallyn.com, ebiederm@xmission.com, Richard Guy Briggs Subject: [PATCH ghak90 (was ghak32) V4 10/10] debug audit: read container ID of a process Date: Tue, 31 Jul 2018 16:07:45 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 31 Jul 2018 20:11:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 31 Jul 2018 20:11:53 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rgb@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for reading the audit container identifier from the proc filesystem. This is a read from the proc entry of the form /proc/PID/audit_containerid where PID is the process ID of the task whose audit container identifier is sought. The read expects up to a u64 value (unset: 18446744073709551615). This read requires CAP_AUDIT_CONTROL. Signed-off-by: Richard Guy Briggs Acked-by: Serge Hallyn --- fs/proc/base.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 1b3cda1..95fc64a 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1261,6 +1261,24 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .llseek = generic_file_llseek, }; +static ssize_t proc_contid_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*2]; + + if (!task) + return -ESRCH; + /* if we don't have caps, reject */ + if (!capable(CAP_AUDIT_CONTROL)) + return -EPERM; + length = scnprintf(tmpbuf, TMPBUFLEN*2, "%llu", audit_get_contid(task)); + put_task_struct(task); + return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); +} + static ssize_t proc_contid_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { @@ -1291,6 +1309,7 @@ static ssize_t proc_contid_write(struct file *file, const char __user *buf, } static const struct file_operations proc_contid_operations = { + .read = proc_contid_read, .write = proc_contid_write, .llseek = generic_file_llseek, }; @@ -2987,7 +3006,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALL REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), REG("sessionid", S_IRUGO, proc_sessionid_operations), - REG("audit_containerid", S_IWUSR, proc_contid_operations), + REG("audit_containerid", S_IWUSR|S_IRUSR, proc_contid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), @@ -3373,7 +3392,7 @@ static int proc_tid_comm_permission(struct inode *inode, int mask) #ifdef CONFIG_AUDITSYSCALL REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), REG("sessionid", S_IRUGO, proc_sessionid_operations), - REG("audit_containerid", S_IWUSR, proc_contid_operations), + REG("audit_containerid", S_IWUSR|S_IRUSR, proc_contid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), -- 1.8.3.1