vfs_default: Protect vfs_getxattrat_done() from accessing a freed req pointer
authorRalph Boehme <slow@samba.org>
Mon, 9 Mar 2020 10:54:37 +0000 (11:54 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 9 Mar 2020 18:07:34 +0000 (18:07 +0000)
If the fsp is forced closed by a SHUTDOWN_CLOSE whilst the request is in
flight (share forced closed by smbcontrol), then we set state->req = NULL in the
state destructor.

The existing state destructor prevents the state memory from being freed, so
when the thread completes and calls vfs_getxattrat_done(), just throw away the result
if state->req == NULL.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14301

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_default.c

index bd39eb47e9ab050a5d7f41d1ad6c53e9d9fc2c6b..cf24e66e048dfdb47e3cc0ebe980889a21a7e44c 100644 (file)
@@ -3289,6 +3289,15 @@ struct vfswrap_getxattrat_state {
 static int vfswrap_getxattrat_state_destructor(
                struct vfswrap_getxattrat_state *state)
 {
+       /*
+        * This destructor only gets called if the request is still
+        * in flight, which is why we deny it by returning -1. We
+        * also set the req pointer to NULL so the _done function
+        * can detect the caller doesn't want the result anymore.
+        *
+        * Forcing the fsp closed by a SHUTDOWN_CLOSE can cause this.
+        */
+       state->req = NULL;
        return -1;
 }
 
@@ -3519,6 +3528,16 @@ static void vfswrap_getxattrat_done(struct tevent_req *subreq)
        TALLOC_FREE(subreq);
        SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
        talloc_set_destructor(state, NULL);
+       if (req == NULL) {
+               /*
+                * We were shutdown closed in flight. No one wants the result,
+                * and state has been reparented to the NULL context, so just
+                * free it so we don't leak memory.
+                */
+               DBG_NOTICE("getxattr request abandoned in flight\n");
+               TALLOC_FREE(state);
+               return;
+       }
        if (ret != 0) {
                if (ret != EAGAIN) {
                        tevent_req_error(req, ret);