From d0e8cc2caf98e53e03372bcfa05a4c906a19c586 Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Tue, 13 Jan 2026 23:42:10 +0900 Subject: [PATCH] mount.nilfs2: check return value of mnt_fs_set_root() In nilfs_mnt_context_complete_root(), the return value of mnt_fs_set_root() is ignored. Since mnt_fs_set_root() involves memory allocation, it can fail and return a negative error code (e.g., -ENOMEM). Fix this by checking the return value and reporting an error if it fails. Signed-off-by: Ryusuke Konishi --- sbin/mount/mount_libmount.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sbin/mount/mount_libmount.c b/sbin/mount/mount_libmount.c index 6ce0936..8ac9796 100644 --- a/sbin/mount/mount_libmount.c +++ b/sbin/mount/mount_libmount.c @@ -457,9 +457,15 @@ static int nilfs_mnt_context_complete_root(struct libmnt_context *cxt) } fs = nilfs_find_mount(cxt, mtab, mnt_context_get_target(cxt), NULL); - if (fs) - mnt_fs_set_root(mnt_context_get_fs(cxt), mnt_fs_get_root(fs)); - + if (fs) { + res = mnt_fs_set_root(mnt_context_get_fs(cxt), + mnt_fs_get_root(fs)); + if (res < 0) { + error(_("%s: failed to copy root of the mount: %s"), + progname, strerror(-res)); + goto failed; + } + } res = 0; failed: return res;