* [PATCH] fs/fuse/virtio_fs: Fix a potential memory allocation failure
@ 2021-03-24 12:38 zhouchuangao
2021-03-24 13:58 ` Connor Kuehl
0 siblings, 1 reply; 3+ messages in thread
From: zhouchuangao @ 2021-03-24 12:38 UTC (permalink / raw
To: Vivek Goyal, Stefan Hajnoczi, Miklos Szeredi, virtualization,
linux-fsdevel, linux-kernel
Cc: zhouchuangao
Allocate memory for struct fuse_conn may fail, we should not jump to
out_err to kfree(fc).
Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
---
fs/fuse/virtio_fs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 4ee6f73..1f333c6 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1430,11 +1430,11 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
err = -ENOMEM;
fc = kzalloc(sizeof(struct fuse_conn), GFP_KERNEL);
if (!fc)
- goto out_err;
+ goto out_err_fc;
fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
if (!fm)
- goto out_err;
+ goto out_err_fm;
fuse_conn_init(fc, fm, get_user_ns(current_user_ns()),
&virtio_fs_fiq_ops, fs);
@@ -1468,8 +1468,9 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
fsc->root = dget(sb->s_root);
return 0;
-out_err:
+out_err_fm:
kfree(fc);
+out_err_fc:
mutex_lock(&virtio_fs_mutex);
virtio_fs_put(fs);
mutex_unlock(&virtio_fs_mutex);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fs/fuse/virtio_fs: Fix a potential memory allocation failure
2021-03-24 12:38 [PATCH] fs/fuse/virtio_fs: Fix a potential memory allocation failure zhouchuangao
@ 2021-03-24 13:58 ` Connor Kuehl
0 siblings, 0 replies; 3+ messages in thread
From: Connor Kuehl @ 2021-03-24 13:58 UTC (permalink / raw
To: zhouchuangao, Vivek Goyal, Stefan Hajnoczi, Miklos Szeredi,
virtualization, linux-fsdevel, linux-kernel
On 3/24/21 7:38 AM, zhouchuangao wrote:
> Allocate memory for struct fuse_conn may fail, we should not jump to
> out_err to kfree(fc).
Why not? If fc's allocation fails then it is NULL and calling kfree() on
a NULL pointer is a noop[1].
Connor
[1]
https://www.kernel.org/doc/html/latest/core-api/mm-api.html?highlight=kfree#c.kfree
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs/fuse/virtio_fs: Fix a potential memory allocation failure
@ 2021-03-24 13:58 ` Connor Kuehl
0 siblings, 0 replies; 3+ messages in thread
From: Connor Kuehl @ 2021-03-24 13:58 UTC (permalink / raw
To: zhouchuangao, Vivek Goyal, Stefan Hajnoczi, Miklos Szeredi,
virtualization, linux-fsdevel, linux-kernel
On 3/24/21 7:38 AM, zhouchuangao wrote:
> Allocate memory for struct fuse_conn may fail, we should not jump to
> out_err to kfree(fc).
Why not? If fc's allocation fails then it is NULL and calling kfree() on
a NULL pointer is a noop[1].
Connor
[1]
https://www.kernel.org/doc/html/latest/core-api/mm-api.html?highlight=kfree#c.kfree
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-24 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-24 12:38 [PATCH] fs/fuse/virtio_fs: Fix a potential memory allocation failure zhouchuangao
2021-03-24 13:58 ` Connor Kuehl
2021-03-24 13:58 ` Connor Kuehl
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.