[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/vfscore: fix use of uninitialized struct vnode fields



struct vnode as it is returned by vfscore_vget is in a mostly
uninitialized state. Apart from v_ino, v_mount, v_refcnt and v_op,
most fields are uninitialized. This causes highly unpredictable issues
with underlying filesystem implementations not initializing the
remaining fields themselves.

A concrete example is ramfs, which does not initialize v_flags. This
causes some vnodes to have the VROOT flag set. As a consequence,
sys_unlink spuriously returns EBUSY, causing SQLite to experience
delays and I/O errors while performing operations on the rollback
journal.

Allocate struct vnode using calloc instead of malloc to make sure that
all struct fields are properly initialized (this avoids v_data to be a
wild reference, and correctly initializes v_type, among others).

Please, note that while this prevents further issues with other
uninitialized fields, calloc has an additional (minor) performance
overhead over malloc.  Alternatively, one can initialize v_flags to
zero in ramfs_lookup (uk_9pfs_lookup is doing this).

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@xxxxxxxxx>
---
 lib/vfscore/vnode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/vfscore/vnode.c b/lib/vfscore/vnode.c
index 51bd756..6b5ea12 100644
--- a/lib/vfscore/vnode.c
+++ b/lib/vfscore/vnode.c
@@ -191,7 +191,7 @@ vfscore_vget(struct mount *mp, uint64_t ino, struct vnode 
**vpp)
                return 1;
        }
 
-       vp = malloc(sizeof(*vp));
+       vp = calloc(1, sizeof(*vp));
        if (!vp) {
                VNODE_UNLOCK();
                return 0;
-- 
2.24.1

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.