From nobody Thu May 7 23:15:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34E12C433F5 for ; Mon, 16 May 2022 20:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239892AbiEPUrx (ORCPT ); Mon, 16 May 2022 16:47:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244565AbiEPUpC (ORCPT ); Mon, 16 May 2022 16:45:02 -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 2DB7D483AA for ; Mon, 16 May 2022 13:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652732561; 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=WUrJCpET5ioJAiVvwk8zHzwkwHsTKZgoemTPe72om30=; b=fUttHnh4xG63oyrA6xXMNxjccF5iuBVqym5sBWSAO2gjmClV2bVXz4DGHx/mjXeC9pEgUv uLIDC7gEmV07DmzoP+4os/D/VFUlmD3zxooM+hcNf/6sPn0NL6XzFYOJXWAI4aOX5jncwX zeRzHh1odEUKBpRNaQ2tyO5kBTFDkuc= 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-SJvpVGTBOBqR-JkPz4J76Q-1; Mon, 16 May 2022 16:22:38 -0400 X-MC-Unique: SJvpVGTBOBqR-JkPz4J76Q-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 A4DA538149AA; Mon, 16 May 2022 20:22:37 +0000 (UTC) Received: from madcap2.tricolour.com (unknown [10.22.50.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B15840CF8E2; Mon, 16 May 2022 20:22:36 +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 1/3] fanotify: Ensure consistent variable type for response Date: Mon, 16 May 2022 16:22:22 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The user space API for the response variable is __u32. This patch makes sure that the whole path through the kernel uses u32 so that there is no sign extension or truncation of the user space response. Suggested-by: Steve Grubb Link: https://lore.kernel.org/r/12617626.uLZWGnKmhe@x2 Signed-off-by: Richard Guy Briggs Acked-by: Paul Moore --- fs/notify/fanotify/fanotify.h | 2 +- fs/notify/fanotify/fanotify_user.c | 6 +++--- include/linux/audit.h | 6 +++--- kernel/auditsc.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index a3d5b751cac5..d66668e06bee 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -425,7 +425,7 @@ FANOTIFY_PE(struct fanotify_event *event) struct fanotify_perm_event { struct fanotify_event fae; struct path path; - unsigned short response; /* userspace answer to the event */ + u32 response; /* userspace answer to the event */ unsigned short state; /* state of the event */ int fd; /* fd we passed to userspace for this event */ }; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanoti= fy_user.c index 9b32b76a9c30..721e777ea90b 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -289,7 +289,7 @@ static int create_fd(struct fsnotify_group *group, stru= ct path *path, */ static void finish_permission_event(struct fsnotify_group *group, struct fanotify_perm_event *event, - unsigned int response) + u32 response) __releases(&group->notification_lock) { bool destroy =3D false; @@ -310,9 +310,9 @@ static int process_access_response(struct fsnotify_grou= p *group, { struct fanotify_perm_event *event; int fd =3D response_struct->fd; - int response =3D response_struct->response; + u32 response =3D response_struct->response; =20 - pr_debug("%s: group=3D%p fd=3D%d response=3D%d\n", __func__, group, + pr_debug("%s: group=3D%p fd=3D%d response=3D%u\n", __func__, group, fd, response); /* * make sure the response is valid, if invalid we do nothing and either diff --git a/include/linux/audit.h b/include/linux/audit.h index d06134ac6245..217784d602b3 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(u32 response); 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 nentri= es, @@ -526,7 +526,7 @@ static inline void audit_log_kern_module(char *name) __audit_log_kern_module(name); } =20 -static inline void audit_fanotify(unsigned int response) +static inline void audit_fanotify(u32 response) { if (!audit_dummy_context()) __audit_fanotify(response); @@ -686,7 +686,7 @@ static inline void audit_log_kern_module(char *name) { } =20 -static inline void audit_fanotify(unsigned int response) +static inline void audit_fanotify(u32 response) { } =20 static inline void audit_tk_injoffset(struct timespec64 offset) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index ea2ee1181921..6973be0bf6c9 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2893,7 +2893,7 @@ void __audit_log_kern_module(char *name) context->type =3D AUDIT_KERN_MODULE; } =20 -void __audit_fanotify(unsigned int response) +void __audit_fanotify(u32 response) { audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, "resp=3D%u", response); --=20 2.27.0 From nobody Thu May 7 23:15:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3E51C433F5 for ; Mon, 16 May 2022 20:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346151AbiEPUsN (ORCPT ); Mon, 16 May 2022 16:48:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343963AbiEPUpD (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0E00F483A4 for ; Mon, 16 May 2022 13:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652732564; 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=8REHGxRCTBVJChx13xBRXD9eIFYC7+P4H0f287ctuHg=; b=JWcYHPtKBsOwopSE1O/kp6e2WovyMovIkvhEqzyZgD5WGAuXVq/xTHnbmhwe9m0Stmszl5 DKu5Fa0w9sBPF91P+qT0WMesqVEB8ybxKofFgIEMxElfIY/EyzcKAAC16ff7YhKKaMASqv qu2FUBPXDOl4dDC3s58tGJBK83GQ3yQ= 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-609-shmx3ctIOG-J73iNyuz9sw-1; Mon, 16 May 2022 16:22:39 -0400 X-MC-Unique: shmx3ctIOG-J73iNyuz9sw-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 2E8D080B71A; Mon, 16 May 2022 20:22:39 +0000 (UTC) Received: from madcap2.tricolour.com (unknown [10.22.50.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id D90EB40CF8E2; Mon, 16 May 2022 20:22:37 +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 2/3] fanotify: define struct members to hold response decision context Date: Mon, 16 May 2022 16:22:23 -0400 Message-Id: <1520f08c023d1e919b1a2af161d5a19367b6b4bf.1652730821.git.rgb@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds 2 structure members to the response returned from user space on a permission event. The first field is 32 bits for the context type. The context type will describe what the meaning is of the second field. The default is none. The patch defines one additional context type which means that the second field is a union containing a 32-bit rule number. This will allow for the creation of other context types in the future if other users of the API identify different needs. The second field size is defined by the context type and can be used to pass along the data described by the context. To support this, there is a macro for user space to check that the data being sent is valid. Of course, without this check, anything that overflows the bit field will trigger an EINVAL based on the use of FAN_INVALID_RESPONSE_MASK in process_access_response(). Suggested-by: Steve Grubb Link: https://lore.kernel.org/r/2745105.e9J7NaK4W3@x2 Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20201001101219.GE17860@quack2.suse.cz Signed-off-by: Richard Guy Briggs Reported-by: kernel test robot --- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/fanotify/fanotify.h | 2 + fs/notify/fanotify/fanotify_user.c | 74 +++++++++++++++++++----------- include/linux/fanotify.h | 3 ++ include/uapi/linux/fanotify.h | 22 ++++++++- 5 files changed, 75 insertions(+), 28 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 985e995d2a39..ea0e60488f12 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -262,7 +262,7 @@ static int fanotify_get_response(struct fsnotify_group = *group, } =20 /* userspace responded, convert to something usable */ - switch (event->response & ~FAN_AUDIT) { + switch (event->response & ~(FAN_AUDIT | FAN_EXTRA)) { case FAN_ALLOW: ret =3D 0; break; diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index d66668e06bee..eb7ec1f2a26e 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -426,8 +426,10 @@ struct fanotify_perm_event { struct fanotify_event fae; struct path path; u32 response; /* userspace answer to the event */ + u32 extra_info_type; unsigned short state; /* state of the event */ int fd; /* fd we passed to userspace for this event */ + union fanotify_response_extra extra_info; }; =20 static inline struct fanotify_perm_event * diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanoti= fy_user.c index 721e777ea90b..1c4067e29f2e 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -289,13 +289,22 @@ static int create_fd(struct fsnotify_group *group, st= ruct path *path, */ static void finish_permission_event(struct fsnotify_group *group, struct fanotify_perm_event *event, - u32 response) + struct fanotify_response *response) __releases(&group->notification_lock) { bool destroy =3D false; =20 assert_spin_locked(&group->notification_lock); - event->response =3D response; + event->response =3D response->response & ~FAN_EXTRA; + if (response->response & FAN_EXTRA) { + event->extra_info_type =3D response->extra_info_type; + switch (event->extra_info_type) { + case FAN_RESPONSE_INFO_AUDIT_RULE: + event->extra_info.audit_rule =3D response->extra_info.audit_rule; + } + } else { + event->extra_info_type =3D FAN_RESPONSE_INFO_NONE; + } if (event->state =3D=3D FAN_EVENT_CANCELED) destroy =3D true; else @@ -306,33 +315,40 @@ static void finish_permission_event(struct fsnotify_g= roup *group, } =20 static int process_access_response(struct fsnotify_group *group, - struct fanotify_response *response_struct) + struct fanotify_response *response_struct, + size_t count) { struct fanotify_perm_event *event; int fd =3D response_struct->fd; u32 response =3D response_struct->response; =20 - pr_debug("%s: group=3D%p fd=3D%d response=3D%u\n", __func__, group, - fd, response); + pr_debug("%s: group=3D%p fd=3D%d response=3D%u type=3D%u size=3D%lu\n", _= _func__, + group, fd, response, response_struct->extra_info_type, count); + if (fd < 0) + return -EINVAL; /* * make sure the response is valid, if invalid we do nothing and either * userspace can send a valid response or we will clean it up after the * timeout */ - switch (response & ~FAN_AUDIT) { - case FAN_ALLOW: - case FAN_DENY: - break; - default: - return -EINVAL; - } - - if (fd < 0) + if (FAN_INVALID_RESPONSE_MASK(response)) return -EINVAL; - if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) return -EINVAL; - + if (response & FAN_EXTRA) { + if (count < offsetofend(struct fanotify_response, extra_info_type)) + return -EINVAL; + switch (response_struct->extra_info_type) { + case FAN_RESPONSE_INFO_NONE: + break; + case FAN_RESPONSE_INFO_AUDIT_RULE: + if (count < offsetofend(struct fanotify_response, extra_info)) + return -EINVAL; + break; + default: + return -EINVAL; + } + } spin_lock(&group->notification_lock); list_for_each_entry(event, &group->fanotify_data.access_list, fae.fse.list) { @@ -340,7 +356,7 @@ static int process_access_response(struct fsnotify_grou= p *group, continue; =20 list_del_init(&event->fae.fse.list); - finish_permission_event(group, event, response); + finish_permission_event(group, event, response_struct); wake_up(&group->fanotify_data.access_waitq); return 0; } @@ -802,9 +818,13 @@ static ssize_t fanotify_read(struct file *file, char _= _user *buf, fsnotify_destroy_event(group, &event->fse); } else { if (ret <=3D 0) { + struct fanotify_response response =3D { + .fd =3D FAN_NOFD, + .response =3D FAN_DENY }; + spin_lock(&group->notification_lock); finish_permission_event(group, - FANOTIFY_PERM(event), FAN_DENY); + FANOTIFY_PERM(event), &response); wake_up(&group->fanotify_data.access_waitq); } else { spin_lock(&group->notification_lock); @@ -827,26 +847,25 @@ static ssize_t fanotify_read(struct file *file, char = __user *buf, =20 static ssize_t fanotify_write(struct file *file, const char __user *buf, s= ize_t count, loff_t *pos) { - struct fanotify_response response =3D { .fd =3D -1, .response =3D -1 }; + struct fanotify_response response; struct fsnotify_group *group; int ret; + size_t size =3D min(count, sizeof(struct fanotify_response)); =20 if (!IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) return -EINVAL; =20 group =3D file->private_data; =20 - if (count < sizeof(response)) + if (count < offsetofend(struct fanotify_response, response)) return -EINVAL; =20 - count =3D sizeof(response); - pr_debug("%s: group=3D%p count=3D%zu\n", __func__, group, count); =20 - if (copy_from_user(&response, buf, count)) + if (copy_from_user(&response, buf, size)) return -EFAULT; =20 - ret =3D process_access_response(group, &response); + ret =3D process_access_response(group, &response, count); if (ret < 0) count =3D ret; =20 @@ -857,6 +876,9 @@ static int fanotify_release(struct inode *ignored, stru= ct file *file) { struct fsnotify_group *group =3D file->private_data; struct fsnotify_event *fsn_event; + struct fanotify_response response =3D { + .fd =3D FAN_NOFD, + .response =3D FAN_ALLOW }; =20 /* * Stop new events from arriving in the notification queue. since @@ -876,7 +898,7 @@ static int fanotify_release(struct inode *ignored, stru= ct file *file) event =3D list_first_entry(&group->fanotify_data.access_list, struct fanotify_perm_event, fae.fse.list); list_del_init(&event->fae.fse.list); - finish_permission_event(group, event, FAN_ALLOW); + finish_permission_event(group, event, &response); spin_lock(&group->notification_lock); } =20 @@ -893,7 +915,7 @@ static int fanotify_release(struct inode *ignored, stru= ct file *file) fsnotify_destroy_event(group, fsn_event); } else { finish_permission_event(group, FANOTIFY_PERM(event), - FAN_ALLOW); + &response); } spin_lock(&group->notification_lock); } diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 419cadcd7ff5..63a8494e782e 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -113,6 +113,9 @@ #define ALL_FANOTIFY_EVENT_BITS (FANOTIFY_OUTGOING_EVENTS | \ FANOTIFY_EVENT_FLAGS) =20 +/* This mask is to check for invalid bits of a user space permission respo= nse */ +#define FAN_INVALID_RESPONSE_MASK(x) ((x) & ~(FAN_ALLOW | FAN_DENY | FAN_A= UDIT | FAN_EXTRA)) + /* Do not use these old uapi constants internally */ #undef FAN_ALL_CLASS_BITS #undef FAN_ALL_INIT_FLAGS diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index e8ac38cc2fd6..a94f4143601f 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -179,15 +179,35 @@ struct fanotify_event_info_error { __u32 error_count; }; =20 +/* + * User space may need to record additional information about its decision. + * The extra information type records what kind of information is included. + * The default is none. We also define an extra informaion buffer whose + * size is determined by the extra information type. + * + * If the context type is Rule, then the context following is the rule num= ber + * that triggered the user space decision. + */ + +#define FAN_RESPONSE_INFO_NONE 0 +#define FAN_RESPONSE_INFO_AUDIT_RULE 1 + +union fanotify_response_extra { + __u32 audit_rule; +}; + struct fanotify_response { __s32 fd; __u32 response; + __u32 extra_info_type; + union fanotify_response_extra extra_info; }; =20 /* Legit userspace responses to a _PERM event */ #define FAN_ALLOW 0x01 #define FAN_DENY 0x02 -#define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ +#define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ +#define FAN_EXTRA 0x20 /* Bitmask to indicate additional information */ =20 /* No fd set in event */ #define FAN_NOFD -1 --=20 2.27.0 From nobody Thu May 7 23:15:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 699CDC433F5 for ; Mon, 16 May 2022 20:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347392AbiEPUsA (ORCPT ); Mon, 16 May 2022 16:48:00 -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-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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=3DFANOTIFY msg=3Daudit(1600385147.372:590): resp=3D2 fan_type=3D1 fan_= ctx=3D17 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, =20 /* 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); =20 pr_debug("%s: group=3D%p event=3D%p about to return ret=3D%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 =20 #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_respon= se_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 nentri= es, @@ -526,10 +527,10 @@ static inline void audit_log_kern_module(char *name) __audit_log_kern_module(name); } =20 -static inline void audit_fanotify(u32 response) +static inline void audit_fanotify(u32 response, u32 type, union fanotify_r= esponse_extra *info) { if (!audit_dummy_context()) - __audit_fanotify(response); + __audit_fanotify(response, type, info); } =20 static inline void audit_tk_injoffset(struct timespec64 offset) @@ -686,7 +687,7 @@ static inline void audit_log_kern_module(char *name) { } =20 -static inline void audit_fanotify(u32 response) +static inline void audit_fanotify(u32 response, u32 type, union fanotify_r= esponse_extra *info) { } =20 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 =20 #include "audit.h" =20 @@ -2893,10 +2894,21 @@ void __audit_log_kern_module(char *name) context->type =3D AUDIT_KERN_MODULE; } =20 -void __audit_fanotify(u32 response) +void __audit_fanotify(u32 response, u32 type, union fanotify_response_extr= a *info) { - audit_log(audit_context(), GFP_KERNEL, - AUDIT_FANOTIFY, "resp=3D%u", response); + switch (type) { + case FAN_RESPONSE_INFO_AUDIT_RULE: + audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, + "resp=3D%u fan_type=3D%u fan_ctx=3D%u", + response, type, info->audit_rule); + break; + case FAN_RESPONSE_INFO_NONE: + default: + audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, + "resp=3D%u fan_type=3D%u fan_ctx=3D?", + response, type); + break; + } } =20 void __audit_tk_injoffset(struct timespec64 offset) --=20 2.27.0