From: Markus Elfring <Markus.Elfring@web.de>
To: virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org,
kernel-janitors@vger.kernel.org,
Miklos Szeredi <miklos@szeredi.hu>,
Stefan Hajnoczi <stefanha@redhat.com>,
Vivek Goyal <vgoyal@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] virtiofs: Improve error handling in virtio_fs_get_tree()
Date: Fri, 29 Dec 2023 09:38:47 +0100 [thread overview]
Message-ID: <5745d81c-3c06-4871-9785-12a469870934@web.de> (raw)
In-Reply-To: <c5c14b02-660a-46e1-9eb3-1a16d7c84922@web.de>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 09:15:07 +0100
The kfree() function was called in two cases by
the virtio_fs_get_tree() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.
* Thus use another label.
* Move an error code assignment into an if branch.
* Delete an initialisation (for the variable “fc”)
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/fuse/virtio_fs.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 2f8ba9254c1e..0746f54ec743 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1415,10 +1415,10 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
{
struct virtio_fs *fs;
struct super_block *sb;
- struct fuse_conn *fc = NULL;
+ struct fuse_conn *fc;
struct fuse_mount *fm;
unsigned int virtqueue_size;
- int err = -EIO;
+ int err;
/* This gets a reference on virtio_fs object. This ptr gets installed
* in fc->iq->priv. Once fuse_conn is going away, it calls ->put()
@@ -1431,13 +1431,15 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
}
virtqueue_size = virtqueue_get_vring_size(fs->vqs[VQ_REQUEST].vq);
- if (WARN_ON(virtqueue_size <= FUSE_HEADER_OVERHEAD))
- goto out_err;
+ if (WARN_ON(virtqueue_size <= FUSE_HEADER_OVERHEAD)) {
+ err = -EIO;
+ goto lock_mutex;
+ }
err = -ENOMEM;
fc = kzalloc(sizeof(*fc), GFP_KERNEL);
if (!fc)
- goto out_err;
+ goto lock_mutex;
fm = kzalloc(sizeof(*fm), GFP_KERNEL);
if (!fm)
@@ -1476,6 +1478,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
out_err:
kfree(fc);
+lock_mutex:
mutex_lock(&virtio_fs_mutex);
virtio_fs_put(fs);
mutex_unlock(&virtio_fs_mutex);
--
2.43.0
next prev parent reply other threads:[~2023-12-29 8:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-29 8:34 [PATCH 0/2] virtiofs: Adjustments for two function implementations Markus Elfring
2023-12-29 8:36 ` [PATCH 1/2] virtiofs: Improve three size determinations Markus Elfring
2024-01-02 20:41 ` Vivek Goyal
2023-12-29 8:38 ` Markus Elfring [this message]
2023-12-29 8:51 ` [PATCH 2/2] virtiofs: Improve error handling in virtio_fs_get_tree() Matthew Wilcox
2023-12-29 9:10 ` Markus Elfring
2023-12-29 14:21 ` Matthew Wilcox
2024-01-02 9:35 ` [2/2] " Markus Elfring
2024-01-02 10:17 ` Matthew Wilcox
2024-01-02 10:47 ` Markus Elfring
2024-01-02 16:28 ` Matthew Wilcox
2024-01-02 16:50 ` Markus Elfring
2024-01-02 20:21 ` [PATCH 2/2] " Vivek Goyal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5745d81c-3c06-4871-9785-12a469870934@web.de \
--to=markus.elfring@web.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=stefanha@redhat.com \
--cc=vgoyal@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).