Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp15636591ybl; Tue, 31 Dec 2019 11:52:19 -0800 (PST) X-Google-Smtp-Source: APXvYqzrDX7sGYFHGzoTCTF3ZKcYZDgYV5xFjcmnzRioSHxlSZ/L7pxm4rHFicdNKrD2FAwQHHKe X-Received: by 2002:aa7:d4d2:: with SMTP id t18mr77226831edr.223.1577821938900; Tue, 31 Dec 2019 11:52:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577821938; cv=none; d=google.com; s=arc-20160816; b=HE170/q3e3GXh3YALJuh8ChId1x+mfAOZSPGVJyGjfKImbAfW3kPjcvpcrNqaMpQ1A TUgvWf8Xrs3h+QCFrK4GwAllfmhyTeRw/deWNknmqYwjkD/NuZwwjH5r+c+CjeyHDwwi 9jhWzAkivajxOU0likzKsj9ub8ekGosaOcmUZAdy6VAr6dgXQEBdV762zDQhss7ap/2E bjHDDOAxWrSCCdRaxCX+ox1M49/ePn1uF2Fb0kAiV7XdLvBihL8u+1cEWaAP83yznjRh s2Asr1yT2ktMqBhdT6rr7W6GBjq95slRlgeO5P7yrFBYUOw9fKwsTcOZXi+aanby3fBr KxQg== 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:dkim-signature; bh=74X6P6Xo68eSlk/mF7B8WeXzNuKmkUjnf5StqzIZblA=; b=zTfCwqJh8eEgKEblwE8+rd20Kn0qK04Oeeob3ecozHMYYfCYPBlxQxiyD2cqJLCMFH 8sMvFc/Pkp2PGhVJyqXLP5fey2yHO546P+MHhPGn8YtOq8S9gosDpzbULNUPtWb71TDJ Rqqd+Fx4UrEBVwerOFk1ap6E0fvC+D1/Nr/Bm+iKcBU26mEjfTd29N1kuIFaBIU4ZJMB uPObZ6OpyNX9G4sO6o4YShWfxBx3jYkDe9xm57Vby+1SPBAYQqr9O0tcGl6Sdda/yAa2 s6OuEkE4HenFeJ1YWfCDFwuGH/34FWRlIoIrNodNBYViP98tYrpMGMn93mRJTI65dwa7 lxbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ur8Zpcdh; 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=pass (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 x25si31570461eds.41.2019.12.31.11.51.55; Tue, 31 Dec 2019 11:52:18 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ur8Zpcdh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfLaTuI (ORCPT + 99 others); Tue, 31 Dec 2019 14:50:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34174 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727183AbfLaTuD (ORCPT ); Tue, 31 Dec 2019 14:50:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577821803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:in-reply-to: references:references:references; bh=74X6P6Xo68eSlk/mF7B8WeXzNuKmkUjnf5StqzIZblA=; b=Ur8ZpcdhXF+m1bLTkJrewTbrfcx7hVmYNI8E+OcWU2nvSAk+/gbSl/uzsN+csrewXklGQp 8nhr8Tvj5FET/7swvsYqgeEc2L9JBdwfcDkNRdbOZtvHIlZg3ELEifke9W6jiZjWXRuS4G d093IK9VB+4ksPzweIYW67u3tn8Y4a0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-245-94s_6TXZNr252yh2tFxKDg-1; Tue, 31 Dec 2019 14:50:01 -0500 X-MC-Unique: 94s_6TXZNr252yh2tFxKDg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78449477; Tue, 31 Dec 2019 19:49:59 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4AE481C0A; Tue, 31 Dec 2019 19:49:48 +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 V8 03/16] audit: read container ID of a process Date: Tue, 31 Dec 2019 14:48:16 -0500 Message-Id: <05ba38492e83101df4d2aea72c3adda041e46fcf.1577736799.git.rgb@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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