Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp341288ybe; Wed, 18 Sep 2019 18:30:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNiEqjJqi0C1j6AhSqqwVOqNn7CBYSADErDdFbb3zj3Y7Lq0YXJ44zlqiMs10wPX33LUQK X-Received: by 2002:a17:906:583:: with SMTP id 3mr11773490ejn.74.1568856630306; Wed, 18 Sep 2019 18:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568856630; cv=none; d=google.com; s=arc-20160816; b=xl4fkOCtk5MIFWqvb8PblTlo2H9/3hyUJYTAL89RpJg8z3g/87je+5S4hKm3ZlGXM9 tBcaJC4omdwfMtCO1XR2KPJDEuTKBFZQgIp/HTPHvgMb+TNhxdSHMABikXMsMP+hCo5v otm29mA4Gnir7LXLmY8CnVFiPBA+tKTFjd7wVlLLUSfLf2aPJJcWUH9zAsBDD9oMOgDJ QqRPL9Gsu/AtYR4aeUheIk0nIdbKnammX+RAF8/67bYPu0x65hy0+eKHeSsa+2Hz9o23 eP9m3wgXNM9eBzVZ3lwps6r7x1gCPb4EGUKcylOIUbNpvHTSLrYVnuELu8+Ki+2BydaP x/xQ== 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=74X6P6Xo68eSlk/mF7B8WeXzNuKmkUjnf5StqzIZblA=; b=sfANe85HEoGt+d87/12s55vNqfzIkUpj9Emm3DRrAqw5PSD0nVHSiT/izzGa2lm3T+ Ac2GUtD3HgdhU4XRG15eTtPf3YuGt+3L3+IKBb0V5FlJ4UTl3mOnZIiaBgas3gd34a0Q BATXCCbeDFMrAAcE/cz7BFb9W8eGm2oh1dVO+9M3ftR6zOvRWqCdm61mqFGfZnJD61jl 8dCgAzEVF/K+X/Q8mBDaogrvmppnF0h16bJP1AqDxFFbMRT0x/5KYfdi8swRApGhIeLi 4cXwXBSfrcX2QBczgIRf3vL1Jg516tYDj484wM/n1qv7kyQLXobUj1sfQ3NmTs4RfYa5 lksQ== 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 jr9si3832140ejb.118.2019.09.18.18.30.07; Wed, 18 Sep 2019 18:30:30 -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 S1731779AbfISBXz (ORCPT + 99 others); Wed, 18 Sep 2019 21:23:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41778 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731729AbfISBXw (ORCPT ); Wed, 18 Sep 2019 21:23:52 -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 016EE10DCC82; Thu, 19 Sep 2019 01:23:48 +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 7094960C44; Thu, 19 Sep 2019 01:23:42 +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 03/21] audit: read container ID of a process Date: Wed, 18 Sep 2019 21:22:20 -0400 Message-Id: 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.6.2 (mx1.redhat.com [10.5.110.64]); Thu, 19 Sep 2019 01:23:52 +0000 (UTC) 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 Acked-by: Neil Horman Reviewed-by: Ondrej Mosnacek --- fs/proc/base.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index e2e7c9f4702f..26091800180c 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1224,7 +1224,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf, }; #ifdef CONFIG_AUDIT -#define TMPBUFLEN 11 +#define TMPBUFLEN 21 static ssize_t proc_loginuid_read(struct file * file, char __user * buf, size_t count, loff_t *ppos) { @@ -1308,6 +1308,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]; + + if (!task) + return -ESRCH; + /* if we don't have caps, reject */ + if (!capable(CAP_AUDIT_CONTROL)) + return -EPERM; + length = scnprintf(tmpbuf, TMPBUFLEN, "%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) { @@ -1338,6 +1356,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, }; @@ -3101,7 +3120,7 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDIT 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), @@ -3502,7 +3521,7 @@ static int proc_tid_comm_permission(struct inode *inode, int mask) #ifdef CONFIG_AUDIT 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