Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3349020iob; Mon, 16 May 2022 20:18:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHxQ2BgjQwK7GgSZNPMU6K1mo5RKfUUsFwHulWxZ9y1Z7E9RGXf1i9J1/4407AtHB3W8DN X-Received: by 2002:a17:906:7311:b0:6fe:178c:a6ff with SMTP id di17-20020a170906731100b006fe178ca6ffmr13942618ejc.489.1652757484112; Mon, 16 May 2022 20:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652757484; cv=none; d=google.com; s=arc-20160816; b=y3ydX3sVfiyeqcFREz00VQuRL0dohBjRrqr6jAIL4WlIgI3O6Z6OF9Z3vZ51WGZenc kJnfr/6Tn57qRVxDVGCB7o7GOY+ic90duWlsD2F3X7lbualpuBAEpBu/p3MbMrg1T2Bd wcKU28AH8iLGSydpfclAGRbY+Z0LHpPdP7s9ow73VC+r6MnzZyF5DyWgM0JNKFJ0QH4P ogAxF0RZ+spZgkjpRQXeBuX+5l0yjVSRGkvqjaE+1PLXCLufcxk2i5F+b+6VE/YBvWEw 5xHnH9ZzXThAMQE7V3ZZjK9ZDkrKOrMs/piD6yOLJlyoVtzZ6Nao2Yh2u3IDTUlJ6FZD zrLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a3sk0Kg+x7hgril7kpmaVqy1YQpLRjOv9hNg1DEjNQg=; b=BcRSRHkUX9nqj9bQybK3YEu4J3L0rXAzciUKwl6/v6PGlLcjeBMwRMJ6pweM1REfuL we1EKeTo44sgdsiEovujou85fyHbNaQH38a98TCo7UdUL4HHRfajoBFuHHe+bxm24vp7 NzM+WGb+VyIzpePZvdT14gHkHKURKt3UFnVMR3pgZc5SsxR54NStqWSSApx2IQvFuUpy n21yS3E53CH5YEt7YBhaX2MgnEx1mM5T2DYDRM+MyGMRVyw4O4r85EFCZwsVTAynP1/i WJdWx4rOoKzZFxi1JhWZv4EA6x9yvBEmytOYewOASQ81heSdlR9qvzhIoYEbi7SX9XVi gokg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ePg3+2jq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp38-20020a1709071b2600b006e7ec2be6bbsi1871286ejc.411.2022.05.16.20.17.38; Mon, 16 May 2022 20:18:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ePg3+2jq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S244863AbiEPUr6 (ORCPT + 99 others); Mon, 16 May 2022 16:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344946AbiEPUpD (ORCPT ); Mon, 16 May 2022 16:45:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4131483AD for ; Mon, 16 May 2022 13:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652732565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a3sk0Kg+x7hgril7kpmaVqy1YQpLRjOv9hNg1DEjNQg=; b=ePg3+2jqtqUm0Q2T8M31swBHWERSABD68Mpsw3oHQmXwQrcpTehvL5/0v0CtZm8XEPi7kL j+AJCp9XiFLDIQ5UIwyHeCQZ8lbLHI6N/qNMzDpmc5db2lX5b45Dw4KrDuThMqBWsEQQ9g rZv8ZUreSAzYRMF5Nt2YApAiMu/yI/w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-380-X4qdOPM-Phqj4Q5GmDnttg-1; Mon, 16 May 2022 16:22:41 -0400 X-MC-Unique: X4qdOPM-Phqj4Q5GmDnttg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B64C58032EA; Mon, 16 May 2022 20:22:40 +0000 (UTC) Received: from madcap2.tricolour.com (unknown [10.22.50.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 625D940CF8E2; Mon, 16 May 2022 20:22:39 +0000 (UTC) From: Richard Guy Briggs To: Linux-Audit Mailing List , LKML , linux-fsdevel@vger.kernel.org Cc: Paul Moore , Eric Paris , Steve Grubb , Richard Guy Briggs , Jan Kara , Amir Goldstein Subject: [PATCH v3 3/3] fanotify: Allow audit to use the full permission event response Date: Mon, 16 May 2022 16:22:24 -0400 Message-Id: <81264e038b7b1e0d8fd8bafb25452fb777cd664a.1652730821.git.rgb@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch passes the full value so that the audit function can use all of it. The audit function was updated to log the additional information in the AUDIT_FANOTIFY record. The following is an example of the new record format: type=FANOTIFY msg=audit(1600385147.372:590): resp=2 fan_type=1 fan_ctx=17 Suggested-by: Steve Grubb Link: https://lore.kernel.org/r/3075502.aeNJFYEL58@x2 Signed-off-by: Richard Guy Briggs --- fs/notify/fanotify/fanotify.c | 4 +++- include/linux/audit.h | 9 +++++---- kernel/auditsc.c | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index ea0e60488f12..85ce36e59e0c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -273,7 +273,9 @@ static int fanotify_get_response(struct fsnotify_group *group, /* Check if the response should be audited */ if (event->response & FAN_AUDIT) - audit_fanotify(event->response & ~FAN_AUDIT); + audit_fanotify(event->response & ~FAN_AUDIT, + event->extra_info_type, + &event->extra_info); pr_debug("%s: group=%p event=%p about to return ret=%d\n", __func__, group, event, ret); diff --git a/include/linux/audit.h b/include/linux/audit.h index 217784d602b3..737f1c109aa1 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -14,6 +14,7 @@ #include #include #include +#include #define AUDIT_INO_UNSET ((unsigned long)-1) #define AUDIT_DEV_UNSET ((dev_t)-1) @@ -419,7 +420,7 @@ extern void __audit_log_capset(const struct cred *new, const struct cred *old); extern void __audit_mmap_fd(int fd, int flags); extern void __audit_openat2_how(struct open_how *how); extern void __audit_log_kern_module(char *name); -extern void __audit_fanotify(u32 response); +extern void __audit_fanotify(u32 response, u32 type, union fanotify_response_extra *info); extern void __audit_tk_injoffset(struct timespec64 offset); extern void __audit_ntp_log(const struct audit_ntp_data *ad); extern void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, @@ -526,10 +527,10 @@ static inline void audit_log_kern_module(char *name) __audit_log_kern_module(name); } -static inline void audit_fanotify(u32 response) +static inline void audit_fanotify(u32 response, u32 type, union fanotify_response_extra *info) { if (!audit_dummy_context()) - __audit_fanotify(response); + __audit_fanotify(response, type, info); } static inline void audit_tk_injoffset(struct timespec64 offset) @@ -686,7 +687,7 @@ static inline void audit_log_kern_module(char *name) { } -static inline void audit_fanotify(u32 response) +static inline void audit_fanotify(u32 response, u32 type, union fanotify_response_extra *info) { } static inline void audit_tk_injoffset(struct timespec64 offset) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 6973be0bf6c9..cb93c6ed07cd 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -64,6 +64,7 @@ #include #include #include // struct open_how +#include #include "audit.h" @@ -2893,10 +2894,21 @@ void __audit_log_kern_module(char *name) context->type = AUDIT_KERN_MODULE; } -void __audit_fanotify(u32 response) +void __audit_fanotify(u32 response, u32 type, union fanotify_response_extra *info) { - audit_log(audit_context(), GFP_KERNEL, - AUDIT_FANOTIFY, "resp=%u", response); + switch (type) { + case FAN_RESPONSE_INFO_AUDIT_RULE: + audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, + "resp=%u fan_type=%u fan_ctx=%u", + response, type, info->audit_rule); + break; + case FAN_RESPONSE_INFO_NONE: + default: + audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, + "resp=%u fan_type=%u fan_ctx=?", + response, type); + break; + } } void __audit_tk_injoffset(struct timespec64 offset) -- 2.27.0