[lxc-devel] [lxc/master] utils: Copying source filename to avoid missing info.

jcfaracco on Github lxc-bot at linuxcontainers.org
Thu Sep 5 04:44:56 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1233 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190904/c6310d5d/attachment.bin>
-------------- next part --------------
From b76066febbe77cff3dd60d0834bb1925c27289b1 Mon Sep 17 00:00:00 2001
From: Julio Faracco <jcfaracco at gmail.com>
Date: Thu, 5 Sep 2019 01:43:21 -0300
Subject: [PATCH] utils: Copying source filename to avoid missing info.

Some applications use information from LOOP_GET_STATUS64. The file
associated with loop device is pointed inside structure field
`lo_file_name`. The current code is setting up a loop device without
this information. A legacy example of code checking this is cryptsetup:

    static char *_ioctl_backing_file(const char *loop)
    {
        struct loop_info64 lo64 = {0};
        int loop_fd;

        loop_fd = open(loop, O_RDONLY);
        if (loop_fd < 0)
            return NULL;

        if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0) {
            close(loop_fd);
            return NULL;
        }

        lo64.lo_file_name[LO_NAME_SIZE-2] = '*';
        lo64.lo_file_name[LO_NAME_SIZE-1] = 0;

        close(loop_fd);
        return strdup((char*)lo64.lo_file_name);
    }

It will return an empty string because lo_file_name was not set.

Signed-off-by: Julio Faracco <jcfaracco at gmail.com>
---
 src/lxc/utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 9ddbabfc85..2ff156f172 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1557,6 +1557,8 @@ int lxc_prepare_loop_dev(const char *source, char *loop_dev, int flags)
 	memset(&lo64, 0, sizeof(lo64));
 	lo64.lo_flags = flags;
 
+	strlcpy(lo64.lo_file_name, source, LO_NAME_SIZE);
+
 	ret = ioctl(fd_loop, LOOP_SET_STATUS64, &lo64);
 	if (ret < 0) {
 		SYSERROR("Failed to set loop status64");


More information about the lxc-devel mailing list