Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1441105ybt; Sat, 27 Jun 2020 08:20:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLs9TjdbOQ/kBDEDubVQaGe+u0EPAHObZk4GJkIpfXE8OCkerS8qXjl9sDbOkRWN7wdxow X-Received: by 2002:a05:6402:1425:: with SMTP id c5mr8626449edx.135.1593271248280; Sat, 27 Jun 2020 08:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593271248; cv=none; d=google.com; s=arc-20160816; b=a9hFhKV91iILUacKWSCEwcH9tZL0E9RMPQW1EDSm3TVxrvsqqiRmvy3yc6X1QP7r1d a6s19a8iisM2Ze+r+slvefDwB2sjF34/YEA3QaaN0gnNzPLMBuud86Z93EXeCWhSZToO +cOz56civ6j9jWvRRlLUZ7w4YptnZofEbUhPxtx+avuAxYISeZA7pKJjMRJ69MZ/RcCL 6QHdGDflES4L8puRf1Fzx5Gf0SEbUsO8bFBbudt53eJTl0/QRGoxA0K83dsv53uPV1N1 Zi/FCxepsFNhFGMUyQ7opo623VXHRJHPMD+hN21UMPukAeAoJe6R7KvdfEwGpGEFi6mV 2jPw== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=NVRW4k5syQIZZZPcry9woxR/GxAuxmu6z7uAcEtQlBc=; b=EUwXhOKSvtMOuff93AoIEF+VXwd96oXKdanugghQM3cD6Fa/d9CIfPQvSIxjxFjJ0u U+G75jp1jD7y8Ahwt8Ea8Tm6srQ7T0I+sD9qwh2Jr7850WnwFwn6ymDLiwyBi4zsStww mTF4vHIKWm3Rq0V5jHVfbDHU8KtYU921hz+kg2bSK6Q+WpcS3DKXewAE0l/nBadJflH/ HOIzK6TxtgWyZQyOb11fSVDBBAQV1+mOXgZkuEj8sNFJAYty/UVPFPkvybC4jW0aC+nT UAV9fJLxz2x4/8hno/EyV3aWUDFiiwKxkUckJvi1e7lfkyxNDJ5cMb80+eMXClziBOlW Kx5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AXsLQE1s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id lf11si3171941ejb.475.2020.06.27.08.20.25; Sat, 27 Jun 2020 08:20:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AXsLQE1s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726807AbgF0PTV (ORCPT + 99 others); Sat, 27 Jun 2020 11:19:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31472 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725975AbgF0PTU (ORCPT ); Sat, 27 Jun 2020 11:19:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593271158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=NVRW4k5syQIZZZPcry9woxR/GxAuxmu6z7uAcEtQlBc=; b=AXsLQE1s+vyhB8v6w8zq26jeBTf5TJHGrW9kbh4d1sNaPNJ/YSW9zFmOBTZAHCcItu0xJ8 4AkeFhXuD7/Om0dXThpU1SYpZo0Yp881U+QRq2bhqjOf7KGKA7wOE4m4ZN9bFrOzZk40lD fJ2hk/N3T/LIXMpPw+yY5skHKrHVOBo= 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-142-g3zCIx4DOk2nVqhYO_wKXg-1; Sat, 27 Jun 2020 11:19:16 -0400 X-MC-Unique: g3zCIx4DOk2nVqhYO_wKXg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97C8E1005512; Sat, 27 Jun 2020 15:19:14 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.10.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2DDB60BF4; Sat, 27 Jun 2020 15:19:11 +0000 (UTC) From: Richard Guy Briggs To: containers@lists.linux-foundation.org, Linux-Audit Mailing List , LKML Cc: eparis@parisplace.org, Steve Grubb , omosnace@redhat.com, Paul Moore , nhorman@redhat.com, dwalsh@redhat.com, mpatel@redhat.com, Richard Guy Briggs Subject: [PATCH ghau51/ghau40 v9 06/11] libaudit: add support to get the task audit container identifier Date: Sat, 27 Jun 2020 11:18:06 -0400 Message-Id: <1593271091-30188-7-git-send-email-rgb@redhat.com> In-Reply-To: <1593271091-30188-1-git-send-email-rgb@redhat.com> References: <1593271091-30188-1-git-send-email-rgb@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the audit_get_containerid() call analogous to audit_getloginuid() and audit_get_session() calls to get our own audit container identifier. This is intended as a debug patch, not to be upstreamed. Signed-off-by: Richard Guy Briggs --- docs/Makefile.am | 2 +- docs/audit_get_containerid.3 | 25 +++++++++++++++++++++++++ lib/libaudit.c | 29 +++++++++++++++++++++++++++++ lib/libaudit.h | 1 + 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 docs/audit_get_containerid.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index 8fb030c6e5e4..209789bb2051 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -28,7 +28,7 @@ man_MANS = audit_add_rule_data.3 audit_add_watch.3 auditctl.8 auditd.8 \ auditd.conf.5 auditd-plugins.5 \ audit_delete_rule_data.3 audit_detect_machine.3 \ audit_encode_nv_string.3 audit_getloginuid.3 \ -audit_get_reply.3 audit_get_session.3 \ +audit_get_reply.3 audit_get_session.3 audit_get_containerid.3 \ audit_log_acct_message.3 audit_log_user_avc_message.3 \ audit_log_user_command.3 audit_log_user_comm_message.3 \ audit_log_user_message.3 audit_log_semanage_message.3 \ diff --git a/docs/audit_get_containerid.3 b/docs/audit_get_containerid.3 new file mode 100644 index 000000000000..ef62a25db970 --- /dev/null +++ b/docs/audit_get_containerid.3 @@ -0,0 +1,25 @@ +.TH "AUDIT_GET_CONTAINERID" "3" "Feb 2018" "Red Hat" "Linux Audit API" +.SH NAME +audit_get_containerid \- Get a program's container id value +.SH SYNOPSIS +.B #include +.sp +uin64_t audit_get_containerid(void); + +.SH DESCRIPTION +This function returns the task's audit container identifier attribute. + +.SH "RETURN VALUE" + +This function returns the audit container identifier value if it was set. It will return a \-1 if the audit container identifier is unset. However, since uint64_t is an unsigned type, you will see the converted value instead of \-1. + +.SH "ERRORS" + +This function returns \-2 on failure. Additionally, in the event of a real error, errno would be set. The function can set errno based on failures of open, read, or strtoull. + +.SH "SEE ALSO" + +.BR audit_getloginuid (3). + +.SH AUTHOR +Richard Guy Briggs diff --git a/lib/libaudit.c b/lib/libaudit.c index 2e7b18a70eb8..e64bc4628da4 100644 --- a/lib/libaudit.c +++ b/lib/libaudit.c @@ -951,6 +951,35 @@ uint32_t audit_get_session(void) return ses; } +/* + * This function will retrieve the audit container identifier or -2 if + * there is an error. + */ +uint64_t audit_get_containerid(void) +{ + uint64_t containerid; + int len, in; + char buf[32]; + + errno = 0; + in = open("/proc/self/audit_containerid", O_NOFOLLOW|O_RDONLY); + if (in < 0) + return -2; + do { + len = read(in, buf, sizeof(buf)); + } while (len < 0 && errno == EINTR); + close(in); + if (len < 0 || len >= sizeof(buf)) + return -2; + buf[len] = 0; + errno = 0; + containerid = strtoull(buf, 0, 10); + if (errno) + return -2; + else + return containerid; +} + int audit_rule_syscall_data(struct audit_rule_data *rule, int scall) { int word = AUDIT_WORD(scall); diff --git a/lib/libaudit.h b/lib/libaudit.h index a249463a0888..ec171e4d08f3 100644 --- a/lib/libaudit.h +++ b/lib/libaudit.h @@ -601,6 +601,7 @@ extern int audit_get_reply(int fd, struct audit_reply *rep, reply_t block, extern uid_t audit_getloginuid(void); extern int audit_setloginuid(uid_t uid); extern uint32_t audit_get_session(void); +extern uint64_t audit_get_containerid(void); extern int audit_detect_machine(void); extern int audit_determine_machine(const char *arch); extern char *audit_format_signal_info(char *buf, int len, char *op, struct audit_reply *rep, char *res); -- 1.8.3.1