Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1269098iob; Fri, 29 Apr 2022 01:15:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP1hRs1FlOUPREblem2ckQvJdnqsG4uCuOX+5NN3j+9zYmhRKWoaGZUo32wt7PrmWRM5Z3 X-Received: by 2002:a17:90a:4813:b0:1c9:e5c3:5abf with SMTP id a19-20020a17090a481300b001c9e5c35abfmr2601165pjh.139.1651220136783; Fri, 29 Apr 2022 01:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651220136; cv=none; d=google.com; s=arc-20160816; b=me8BuTj0K6pRkcEZgWbWaOHQWYXeccd/vC5euZ3aKc9T0oXbEK7+4LE6GsVb76o71T ck8KNiexBuCzSol9DLn4GNG8csm45M/j9E6/oE5p1AZLGPvNY6tQwhsPqiDEdve6cat0 zuA87O7Ezm0CJiUkT29HfpqfaC1tHCHPxWIj/yUPbA5KIK4sOfJzCsauvKd01Maig4ku AyoGFcBp3X3rpKnSc/5r2u480pNtBQ1pQRt6W+wCv6Ly/c8tou7y7QvqVTldlMihahqb LUbR8KsC6tjjs1qJIpge5Vr+JE+/ouysHS2vTzyIT47U2x0RlAT0JoWrUeW6X6TJW5Hf SyEQ== 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=efsbKnVljbpA44VkEsgc/rqvDihguP3Jfk2xwnWIRjI=; b=ixAkAw/JS87GGnNBTATNs9k7RNxCLJ0bEMViu4cDjCIEF/PEnGO/uXkrQmCl/mvXpx x99vxYYKo6q0iLkvRkHihF/RpioPWmyazw+GbIpqoFRWmSq3+En2Khl6fXtHxORhn22l F8l+zQyo8wpp0S5zy2RjfEeCz1rSvivpV8uNJ6qntvXZ9vxLAOAoXUldBVtChCn3G03v N04lTHlkTNsMd/ObdUfU4jOk+13/RxLfTD9KmO5stXP+FfPXjpiXF9AQHgi8LLLjM5bX +Enfv3h2xbTm6k/SShXLFYXbvea/y6mnlBjBCensBFXKRC97bnhlji1RT6FcGiJaURJg AJNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ZST/yzPb"; 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 m1-20020a170902f64100b0015898563942si6195396plg.445.2022.04.29.01.15.21; Fri, 29 Apr 2022 01:15:36 -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="ZST/yzPb"; 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 S1353558AbiD2AtQ (ORCPT + 99 others); Thu, 28 Apr 2022 20:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353180AbiD2AtD (ORCPT ); Thu, 28 Apr 2022 20:49:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC1DD887B0 for ; Thu, 28 Apr 2022 17:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651193146; 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=efsbKnVljbpA44VkEsgc/rqvDihguP3Jfk2xwnWIRjI=; b=ZST/yzPbtg8lP1Qvbk91NQHiAseKX6bsm5q4Xu9ijrAg6Z2g9tH4gPon2xDijx49SJNj5o h6lPxsP2xvU+deoKfNBhUPpITkW/u3QUm0iqEV3JZucuiCiuzVB2qDNWTPUJOW8ZVA7Q5q lw7kP84WyQsP0AHqGeKSbZVTtPZ8dC4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-iIghL1NFMjKc8yG4gehxoA-1; Thu, 28 Apr 2022 20:45:42 -0400 X-MC-Unique: iIghL1NFMjKc8yG4gehxoA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34C3D281180C; Fri, 29 Apr 2022 00:45:42 +0000 (UTC) Received: from madcap2.tricolour.com (ovpn-0-8.rdu2.redhat.com [10.22.0.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17CF1815A; Fri, 29 Apr 2022 00:45: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 Subject: [PATCH v2 3/3] fanotify: Allow audit to use the full permission event response Date: Thu, 28 Apr 2022 20:44:36 -0400 Message-Id: <23c7f206a465d88cc646a944515fcc6a365f5eb2.1651174324.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.79 on 10.11.54.5 X-Spam-Status: No, score=-3.4 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 autolearn=unavailable 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 Link: https://lore.kernel.org/r/23c7f206a465d88cc646a944515fcc6a365f5eb2.1651174324.git.rgb@redhat.com --- fs/notify/fanotify/fanotify.c | 4 +++- include/linux/audit.h | 8 ++++---- kernel/auditsc.c | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 00aff6e29bf8..bb16d9e0f31b 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -272,7 +272,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, + (char *)&event->extra_info_buf); 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 d06134ac6245..0897128ee43b 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -419,7 +419,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(unsigned int response); +extern void __audit_fanotify(__u16 response, __u16 type, char *buf); 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 +526,10 @@ static inline void audit_log_kern_module(char *name) __audit_log_kern_module(name); } -static inline void audit_fanotify(unsigned int response) +static inline void audit_fanotify(__u16 response, __u16 type, char *buf) { if (!audit_dummy_context()) - __audit_fanotify(response); + __audit_fanotify(response, type, buf); } static inline void audit_tk_injoffset(struct timespec64 offset) @@ -686,7 +686,7 @@ static inline void audit_log_kern_module(char *name) { } -static inline void audit_fanotify(unsigned int response) +static inline void audit_fanotify(__u16 response, __u16 type, char *buf) { } static inline void audit_tk_injoffset(struct timespec64 offset) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index ea2ee1181921..afdbc416069a 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(unsigned int response) +void __audit_fanotify(__u16 response, __u16 type, char *buf) { - 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, (__u32)*buf); + break; + case FAN_RESPONSE_INFO_AUDIT_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