* [PATCH] configfs: fix memleak in configfs_release_bin_file
@ 2021-06-18 7:59 Chung-Chiang Cheng
2021-06-22 6:04 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Chung-Chiang Cheng @ 2021-06-18 7:59 UTC (permalink / raw)
To: jlbec, hch, pantelis.antoniou
Cc: linux-kernel, linux-fsdevel, Chung-Chiang Cheng
When reading binary attributes in progress, buffer->bin_buffer is setup in
configfs_read_bin_file() but never freed.
Fixes: 03607ace807b4 ("configfs: implement binary attributes")
Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com>
---
fs/configfs/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index e26060dae70a..cdd23f4a51c8 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -466,9 +466,13 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file)
{
struct configfs_buffer *buffer = file->private_data;
- buffer->read_in_progress = false;
-
- if (buffer->write_in_progress) {
+ if (buffer->read_in_progress) {
+ buffer->read_in_progress = false;
+ vfree(buffer->bin_buffer);
+ buffer->bin_buffer = NULL;
+ buffer->bin_buffer_size = 0;
+ buffer->needs_read_fill = 1;
+ } else if (buffer->write_in_progress) {
struct configfs_fragment *frag = to_frag(file);
buffer->write_in_progress = false;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] configfs: fix memleak in configfs_release_bin_file
2021-06-18 7:59 [PATCH] configfs: fix memleak in configfs_release_bin_file Chung-Chiang Cheng
@ 2021-06-22 6:04 ` Christoph Hellwig
2021-06-22 7:40 ` Chung-Chiang Cheng
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2021-06-22 6:04 UTC (permalink / raw)
To: Chung-Chiang Cheng
Cc: jlbec, hch, pantelis.antoniou, linux-kernel, linux-fsdevel,
Chung-Chiang Cheng
Hmm. The issue looks real, but I think we should just call the vfree
unconditionally given that the buffer structure is zeroed on allocation
and freed just after, and also remove the pointless clearing of all the
flags. Does something like this work for you?
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 53913b84383a..1ab6afb84f04 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -393,11 +393,8 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file)
{
struct configfs_buffer *buffer = file->private_data;
- buffer->read_in_progress = false;
-
if (buffer->write_in_progress) {
struct configfs_fragment *frag = to_frag(file);
- buffer->write_in_progress = false;
down_read(&frag->frag_sem);
if (!frag->frag_dead) {
@@ -407,13 +404,9 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file)
buffer->bin_buffer_size);
}
up_read(&frag->frag_sem);
- /* vfree on NULL is safe */
- vfree(buffer->bin_buffer);
- buffer->bin_buffer = NULL;
- buffer->bin_buffer_size = 0;
- buffer->needs_read_fill = 1;
}
+ vfree(buffer->bin_buffer);
configfs_release(inode, file);
return 0;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] configfs: fix memleak in configfs_release_bin_file
2021-06-22 6:04 ` Christoph Hellwig
@ 2021-06-22 7:40 ` Chung-Chiang Cheng
2021-06-22 8:04 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Chung-Chiang Cheng @ 2021-06-22 7:40 UTC (permalink / raw)
To: Christoph Hellwig
Cc: jlbec, Pantelis Antoniou, linux-kernel, linux-fsdevel,
Chung-Chiang Cheng
It works for me. I've verified it with ACPI configfs that is the only
one using configfs binary attributes so far, and the memleak issue
is solved.
On Tue, Jun 22, 2021 at 2:04 PM Christoph Hellwig <hch@lst.de> wrote:
>
> Hmm. The issue looks real, but I think we should just call the vfree
> unconditionally given that the buffer structure is zeroed on allocation
> and freed just after, and also remove the pointless clearing of all the
> flags. Does something like this work for you?
>
> diff --git a/fs/configfs/file.c b/fs/configfs/file.c
> index 53913b84383a..1ab6afb84f04 100644
> --- a/fs/configfs/file.c
> +++ b/fs/configfs/file.c
> @@ -393,11 +393,8 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file)
> {
> struct configfs_buffer *buffer = file->private_data;
>
> - buffer->read_in_progress = false;
> -
> if (buffer->write_in_progress) {
> struct configfs_fragment *frag = to_frag(file);
> - buffer->write_in_progress = false;
>
> down_read(&frag->frag_sem);
> if (!frag->frag_dead) {
> @@ -407,13 +404,9 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file)
> buffer->bin_buffer_size);
> }
> up_read(&frag->frag_sem);
> - /* vfree on NULL is safe */
> - vfree(buffer->bin_buffer);
> - buffer->bin_buffer = NULL;
> - buffer->bin_buffer_size = 0;
> - buffer->needs_read_fill = 1;
> }
>
> + vfree(buffer->bin_buffer);
> configfs_release(inode, file);
> return 0;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] configfs: fix memleak in configfs_release_bin_file
2021-06-22 7:40 ` Chung-Chiang Cheng
@ 2021-06-22 8:04 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2021-06-22 8:04 UTC (permalink / raw)
To: Chung-Chiang Cheng
Cc: Christoph Hellwig, jlbec, Pantelis Antoniou, linux-kernel,
linux-fsdevel, Chung-Chiang Cheng
Thanks. I'v split this into one to move the vfree attribute to you
and a cleanup on top and applied the result to the configfs tree:
http://git.infradead.org/users/hch/configfs.git/shortlog/refs/heads/for-next
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-22 8:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 7:59 [PATCH] configfs: fix memleak in configfs_release_bin_file Chung-Chiang Cheng
2021-06-22 6:04 ` Christoph Hellwig
2021-06-22 7:40 ` Chung-Chiang Cheng
2021-06-22 8:04 ` Christoph Hellwig
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).