Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5711388img; Wed, 27 Mar 2019 13:45:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgGbPenx0tW5FGQRUER9ZY5ZAv0hc/qJxeJBmM9wKhsZWjEnODp3c26ROqsNSlHsP3ZGJB X-Received: by 2002:a63:6c41:: with SMTP id h62mr35705070pgc.371.1553719534162; Wed, 27 Mar 2019 13:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553719534; cv=none; d=google.com; s=arc-20160816; b=iI0DOfzba+sHLHARCsTMh2GNwmjlZ1fzQWqcE9+mL7kdRCd535iUaghRQ/yjHbeslj Ak0zK6HHA6FsQ3T2biZk1NihHcciYfkAO7Q/iRL/9sELz5zKh8gml8tumqqY0YZSlbeH u8bdLHWEECoN1RtuB2o2hwu4c1Fj1b1zh4VzqpTqe+TOSwaWNsW1qSJ9HOLXVF2QrKdx /RMR3IbErFL03NOXwUb9osl6m6hWKzJL934lbk62sxiaY7yQFKCkAHrkQ2FKm6DUUcUX xqkAHhRvCkAaYRQ133Zvq1eYDllpUIxWgRqt3/SYihh8Gyp3ExGsmfGBPx4W1Sn/Ikcg hlQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=KZJmoyAqUqbMB9q3YWMVJZoUVK/xcklwjtBjD0Nm+dI=; b=cyybM/32QJpCcqFgXquNukdkCvIvpdBJv4qhsmOzIpmSWdbt+xHUwohJ9PDQgKuvqH V9h+bMFNJrFAAB8QKaAJ3tfuyiXVMKrw2huq1ISVZUdQa5u/wvRz3+lmQqZzqOef1pZy IVZr3L1JgTn5tYRrNLroCc4PwI8liwRt4xPYoaiJtvD4Z5Dr2g8gKholVTjbesqVWF6C lzVs6Gz+IICgwCV6zYb8mb5DVsbaE5nD0fZrFMhLVvmIwhs8j16tzZ1MYtEsg9NWz98G itSvEd9nnYamkBF00VHVQ/pJig+3TaIxlWRHrhUufWiOas/a/AQqlb/l9OFML1RFCA+2 cgHw== 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 t26si19140108pgu.504.2019.03.27.13.45.18; Wed, 27 Mar 2019 13:45:34 -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 S1728922AbfC0Uoh (ORCPT + 99 others); Wed, 27 Mar 2019 16:44:37 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:37355 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727328AbfC0Uoc (ORCPT ); Wed, 27 Mar 2019 16:44:32 -0400 Received: by mail-oi1-f193.google.com with SMTP id v84so14042890oif.4 for ; Wed, 27 Mar 2019 13:44:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KZJmoyAqUqbMB9q3YWMVJZoUVK/xcklwjtBjD0Nm+dI=; b=IuwAPSPS0AF02IBz13Ez8Hw/JoBjcEfaHcAM2A2mTDt9Ke09rSU6P7mlDwiwWcZcaE uYT1OqRxrLcpGK8JOWVSErXRFW/cSWTRt5RkvKyNg8Z5xKORyGfihNKgf57SRjF+THIa WOZEc7RcMePUQWKYiRa7B6/s2+DAu5TTdZlRpGTgwc4jMvYqzyE9d3bG8P3ouA1UPtoJ vFDpEc+rjbnjXgrwNDHPbEQIPJ4p4erYhOPNnmMh6mjvL76phh26K+rZ5NBm7gY5Ge1p 3irhv7Iqze2n8Cg50oHiE41SzXQU2IDrzuVhZRfr4gynkK4dqMJ28fl7xh2RKHxE8Ou7 5gvA== X-Gm-Message-State: APjAAAXm92wT3fsfzkZ0Oa08TMSoIeOjghL97odaNNrVLqpzBado/g8u 6kDFzHU0KnPkB1/S0x4hbL4MzKAgRfjOHDiaboB9bQ== X-Received: by 2002:aca:4507:: with SMTP id s7mr10402500oia.127.1553719471862; Wed, 27 Mar 2019 13:44:31 -0700 (PDT) MIME-Version: 1.0 References: <25543e3db4d8f3853119f92c09a60664555249a2.1552665316.git.rgb@redhat.com> In-Reply-To: <25543e3db4d8f3853119f92c09a60664555249a2.1552665316.git.rgb@redhat.com> From: Ondrej Mosnacek Date: Wed, 27 Mar 2019 21:44:20 +0100 Message-ID: Subject: Re: [PATCH ghak90 V5 03/10] audit: read container ID of a process To: Richard Guy Briggs Cc: 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, Paul Moore , Steve Grubb , David Howells , Simo Sorce , Eric Paris , "Serge E. Hallyn" , "Eric W . Biederman" , nhorman@tuxdriver.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 15, 2019 at 7:33 PM Richard Guy Briggs wrote: > 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 Reviewed-by: Ondrej Mosnacek > --- > 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 2505c46c8701..0b833cbdf5b6 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -1295,6 +1295,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) > { > @@ -1325,6 +1343,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, > }; > @@ -3039,7 +3058,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), > @@ -3428,7 +3447,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 > -- Ondrej Mosnacek Software Engineer, Security Technologies Red Hat, Inc.