Skip to contentSkip to conversation

NFSv4.2: destination file needs to be released after inter-server copy is done.

PATCH In review Dai Ngo 2 participants 4 messages Mar 3, 2021 – Mar 9, 2021

Subsystems (2)
lore
Share & tools
lore

Dai Ngo

author reviewer
#0 lore raw

PATCH 1/1 NFSv4.2: destination file needs to be released after inter-server copy is done.

This patch is to fix the resource leak problem of the source file when doing inter-server copy. The fix is to close and release the file in __nfs42_ssc_close after the copy is done.

---
 fs/nfs/nfs4file.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs4file.c +6 -0
index 57b3821d975a..20163fe702a7 100644
@@ -405,6 +405,12 @@ static void __nfs42_ssc_close(struct file *filep)
 	struct nfs_open_context *ctx = nfs_file_open_context(filep);
 
 	ctx->state->flags = 0;
+
+	if (!filep)
+		return;
+	get_file(filep);
+	filp_close(filep, NULL);
+	fput(filep);
 }
 
 static const struct nfs4_ssc_client_ops nfs4_ssc_clnt_ops_tbl = {
Signature · 1 line
2.9.5
#1 lore raw
Quoted 15 lines · Dai Ngo

This patch is to fix the resource leak problem of the source file when doing inter-server copy. The fix is to close and release the file in __nfs42_ssc_close after the copy is done.

---
 fs/nfs/nfs4file.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs4file.c +0 -0
index 57b3821d975a..20163fe702a7 100644

fs/nfs/nfs4file.c static void __nfs42_ssc_close(struct file *filep) · line 414

Quoted 10 lines
fs/nfs/nfs4file.c +6 -0
@@ -405,6 +405,12 @@ static void __nfs42_ssc_close(struct file *filep)
        struct nfs_open_context *ctx = nfs_file_open_context(filep);
 
        ctx->state->flags = 0;
+
+       if (!filep)
+               return;
+       get_file(filep);
+       filp_close(filep, NULL);
+       fput(filep);
 }

I don't understand this logic. There is no reason to call filp_close()? All this would be done by doing a fput(). Also fput() would drop a reference on the mount point. So we are doing this then we can't call that extra disconnect that was added by another patch. Anyway I don't see why there is any reason to call anything but the fput(), I'm not sure why __nfs42_ssc_close() is a better function and doesn't lead to the "use_after_free".

Quoted 5 lines
fs/nfs/nfs4file.c +0 -1
 static const struct nfs4_ssc_client_ops nfs4_ssc_clnt_ops_tbl = {
--

2.9.5

author reviewer
#2 lore raw

Thanks Olga for reviewing the patch, reply inline below:

Quoted 17 lines · Olga Kornievskaia
Quoted 16 lines · Dai Ngo

This patch is to fix the resource leak problem of the source file when doing inter-server copy. The fix is to close and release the file in __nfs42_ssc_close after the copy is done.

---
  fs/nfs/nfs4file.c | 6 ++++++
  1 file changed, 6 insertions(+)
fs/nfs/nfs4file.c +0 -0
index 57b3821d975a..20163fe702a7 100644
@@ -405,6 +405,12 @@ static void __nfs42_ssc_close(struct file *filep)
         struct nfs_open_context *ctx = nfs_file_open_context(filep);
 
Quoted 10 lines

fs/nfs/nfs4file.c static void __nfs42_ssc_close(struct file *filep) · line 414

Quoted 8 lines
fs/nfs/nfs4file.c +6 -0
         ctx->state->flags = 0;
+
+       if (!filep)
+               return;
+       get_file(filep);
+       filp_close(filep, NULL);
+       fput(filep);
  }

I don't understand this logic. There is no reason to call filp_close()?

This is to follow the steps done in nfsd_file_put/.../nfsd_file_free. However since this is the source file the flush is probably not needed, just there to be safe. I will remove it.

Quoted 3 lines

All this would be done by doing a fput(). Also fput() would drop a reference on the mount point. So we are doing this then we can't call that extra disconnect that was added by another patch.

nfsd4_interssc_disconnect does not need to access the source file. I tested both patches together and did not see any problem. If there is use-after_free condition the code detects it and there would be warning messages in /var/log/messages.

Quoted 3 lines

Anyway I don't see why there is any reason to call anything but the fput(), I'm not sure why __nfs42_ssc_close() is a better function and doesn't lead to the "use_after_free".

Since __nfs42_ssc_open was called open the file, I think __nfs42_ssc_close is an appropriate place to close the file.

-Dai

Quoted 5 lines
Quoted 5 lines
fs/nfs/nfs4file.c +0 -1
  static const struct nfs4_ssc_client_ops nfs4_ssc_clnt_ops_tbl = {
--

2.9.5

#3 lore raw
Quoted 32 lines · On Mon, Mar 8, 2021 at 3:10 PM <[email protected]> wrote:

Thanks Olga for reviewing the patch, reply inline below:

Quoted 17 lines · Olga Kornievskaia
Quoted 16 lines · Dai Ngo

This patch is to fix the resource leak problem of the source file when doing inter-server copy. The fix is to close and release the file in __nfs42_ssc_close after the copy is done.

---
  fs/nfs/nfs4file.c | 6 ++++++
  1 file changed, 6 insertions(+)
fs/nfs/nfs4file.c +0 -0
index 57b3821d975a..20163fe702a7 100644
@@ -405,6 +405,12 @@ static void __nfs42_ssc_close(struct file *filep)
         struct nfs_open_context *ctx = nfs_file_open_context(filep);
 
Quoted 10 lines

fs/nfs/nfs4file.c static void __nfs42_ssc_close(struct file *filep) · line 414

Quoted 8 lines
fs/nfs/nfs4file.c +6 -0
         ctx->state->flags = 0;
+
+       if (!filep)
+               return;
+       get_file(filep);
+       filp_close(filep, NULL);
+       fput(filep);
  }

I don't understand this logic. There is no reason to call filp_close()?

Quoted 3 lines

This is to follow the steps done in nfsd_file_put/.../nfsd_file_free. However since this is the source file the flush is probably not needed, just there to be safe. I will remove it.

As I said before the only thing that's needed is the fput() which was originally in the code (but got incorrectly changed to nfsd_put()). I prefer to keep it there because this deals with cleaning up the SSC state. I don't see any significant reason to move it out.

Quoted 8 lines
Quoted 3 lines

All this would be done by doing a fput(). Also fput() would drop a reference on the mount point. So we are doing this then we can't call that extra disconnect that was added by another patch.

nfsd4_interssc_disconnect does not need to access the source file. I tested both patches together and did not see any problem. If there is use-after_free condition the code detects it and there would be warning messages in /var/log/messages.

We don't need and don't want to do the nfsd4_interssc_disconnect in the non-error path. All the ref-counting on the superblock is accomplished already. The other patch is not needed and neither is correct, it makes the incorrect refcounts in failure cases.

I nack both patches. The only patch which I will send that's needed is this:

fs/nfsd/nfs4proc.c +0 -0
index 8d6d2678abad..3581ce737e85 100644
@@ -1304,7 +1304,7 @@ nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt,

struct nfsd_file *src,
struct nfsd_file *dst)

 {
        nfs42_ssc_close(src->nf_file);
-       /* 'src' is freed by nfsd4_do_async_copy */
+       fput(src->nf_file);
        nfsd_file_put(dst);
        mntput(ss_mnt);

}

Quoted 6 lines
Quoted 3 lines

Anyway I don't see why there is any reason to call anything but the fput(), I'm not sure why __nfs42_ssc_close() is a better function and doesn't lead to the "use_after_free".

Since __nfs42_ssc_open was called open the file, I think __nfs42_ssc_close is an appropriate place to close the file.

Again let's keep the cleaning of the server's SSC state in one place.

Quoted 7 lines

-Dai

Quoted 5 lines
Quoted 5 lines
fs/nfs/nfs4file.c +0 -1
  static const struct nfs4_ssc_client_ops nfs4_ssc_clnt_ops_tbl = {
--

2.9.5