fanotify: Ensure consistent variable type for response
authorRichard Guy Briggs <rgb@redhat.com>
Fri, 3 Feb 2023 21:35:14 +0000 (16:35 -0500)
committerJan Kara <jack@suse.cz>
Tue, 7 Feb 2023 11:53:32 +0000 (12:53 +0100)
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 <sgrubb@redhat.com>
Link: https://lore.kernel.org/r/12617626.uLZWGnKmhe@x2
Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Tested-by: Steve Grubb <sgrubb@redhat.com>
Acked-by: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Message-Id: <3778cb0b3501bc4e686ba7770b20eb9ab0506cf4.1675373475.git.rgb@redhat.com>

fs/notify/fanotify/fanotify.h
fs/notify/fanotify/fanotify_user.c
include/linux/audit.h
kernel/auditsc.c

index 57f51a9a3015d5c2d1c652e95b1216b1462574c0..f899d610bc08e4087e3f68a3e8f29ef57c16cfec 100644 (file)
@@ -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 */
 };
index 4546da4a54f953cc5a8d0ddc3e2805330fe05006..caa1211bac8cd51178ce57254f6be695721e5ce8 100644 (file)
@@ -289,7 +289,7 @@ static int create_fd(struct fsnotify_group *group, const struct 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 = false;
@@ -310,9 +310,9 @@ static int process_access_response(struct fsnotify_group *group,
 {
        struct fanotify_perm_event *event;
        int fd = response_struct->fd;
-       int response = response_struct->response;
+       u32 response = response_struct->response;
 
-       pr_debug("%s: group=%p fd=%d response=%d\n", __func__, group,
+       pr_debug("%s: group=%p fd=%d response=%u\n", __func__, group,
                 fd, response);
        /*
         * make sure the response is valid, if invalid we do nothing and either
index 3608992848d3c5ad50958f1daeaf2c8ae250fd63..d6b7d0c7ce4382ba8b77b554e6f6d07b1e00c795 100644 (file)
@@ -416,7 +416,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 nentries,
@@ -523,7 +523,7 @@ 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(u32 response)
 {
        if (!audit_dummy_context())
                __audit_fanotify(response);
@@ -679,7 +679,7 @@ static inline void audit_log_kern_module(char *name)
 {
 }
 
-static inline void audit_fanotify(unsigned int response)
+static inline void audit_fanotify(u32 response)
 { }
 
 static inline void audit_tk_injoffset(struct timespec64 offset)
index 547c88be8a284acb9a0aa4bb5ce5d1a4a5f383fd..d1fb821de104dcfe6c1589c9e301f0cb48bc87a4 100644 (file)
@@ -2877,7 +2877,7 @@ void __audit_log_kern_module(char *name)
        context->type = AUDIT_KERN_MODULE;
 }
 
-void __audit_fanotify(unsigned int response)
+void __audit_fanotify(u32 response)
 {
        audit_log(audit_context(), GFP_KERNEL,
                AUDIT_FANOTIFY, "resp=%u", response);