* [PATCH] locks: fix a memory leak bug
@ 2019-08-19 23:47 Wenwen Wang
2019-08-20 9:51 ` Jeff Layton
0 siblings, 1 reply; 2+ messages in thread
From: Wenwen Wang @ 2019-08-19 23:47 UTC (permalink / raw)
To: Wenwen Wang
Cc: Alexander Viro, Jeff Layton, J. Bruce Fields,
open list:FILESYSTEMS (VFS and infrastructure),
open list
In __break_lease(), the file lock 'new_fl' is allocated in lease_alloc().
However, it is not deallocated in the following execution if
smp_load_acquire() fails, leading to a memory leak bug. To fix this issue,
free 'new_fl' before returning the error.
Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
fs/locks.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/locks.c b/fs/locks.c
index 686eae2..5993b2a 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1592,7 +1592,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
ctx = smp_load_acquire(&inode->i_flctx);
if (!ctx) {
WARN_ON_ONCE(1);
- return error;
+ goto free_lock;
}
percpu_down_read(&file_rwsem);
@@ -1672,6 +1672,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
spin_unlock(&ctx->flc_lock);
percpu_up_read(&file_rwsem);
locks_dispose_list(&dispose);
+free_lock:
locks_free_lock(new_fl);
return error;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] locks: fix a memory leak bug
2019-08-19 23:47 [PATCH] locks: fix a memory leak bug Wenwen Wang
@ 2019-08-20 9:51 ` Jeff Layton
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2019-08-20 9:51 UTC (permalink / raw)
To: Wenwen Wang
Cc: Alexander Viro, J. Bruce Fields,
open list:FILESYSTEMS (VFS and infrastructure),
open list
On Mon, 2019-08-19 at 18:47 -0500, Wenwen Wang wrote:
> In __break_lease(), the file lock 'new_fl' is allocated in lease_alloc().
> However, it is not deallocated in the following execution if
> smp_load_acquire() fails, leading to a memory leak bug. To fix this issue,
> free 'new_fl' before returning the error.
>
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
> fs/locks.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/locks.c b/fs/locks.c
> index 686eae2..5993b2a 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -1592,7 +1592,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
> ctx = smp_load_acquire(&inode->i_flctx);
> if (!ctx) {
> WARN_ON_ONCE(1);
> - return error;
> + goto free_lock;
> }
>
> percpu_down_read(&file_rwsem);
> @@ -1672,6 +1672,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
> spin_unlock(&ctx->flc_lock);
> percpu_up_read(&file_rwsem);
> locks_dispose_list(&dispose);
> +free_lock:
> locks_free_lock(new_fl);
> return error;
> }
Good catch! Merged for v5.4. Let me know if you think this needs to go
in earlier and/or to stable kernels.
Thanks,
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-20 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19 23:47 [PATCH] locks: fix a memory leak bug Wenwen Wang
2019-08-20 9:51 ` Jeff Layton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).