]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: only do image locks for regular image files
authorLennart Poettering <lennart@poettering.net>
Thu, 14 Oct 2021 13:38:03 +0000 (15:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 Oct 2021 16:03:32 +0000 (18:03 +0200)
If an image file is actually a block device taking a lock on it doesn't
really make sense for us: it will interfere with udev's block device
probing logic, and it's not going to propagated across the network
anyway (which is what we are after here). Hence simply don't do it.

Follow-up for 2aaf565a2da8eb0ea9adf84028c9d0ab7a90e53e

src/home/homework-luks.c

index b38535ddc35b5ec544b1ea007f1a7122316917c1..050c9cd6d553273e7a47fc52dbf69741acb2d6cb 100644 (file)
@@ -1058,6 +1058,21 @@ static int lock_image_fd(int image_fd, const char *ip) {
         if (r < 0)
                 return log_error_errno(r, "Failed to parse $SYSTEMD_LUKS_LOCK environment variable: %m");
         if (r > 0) {
+                struct stat st;
+
+                if (fstat(image_fd, &st) < 0)
+                        return log_error_errno(errno, "Failed to stat image file: %m");
+                if (S_ISBLK(st.st_mode)) {
+                        /* Locking block devices doesn't really make sense, as this might interfear with
+                         * udev's workings, and these locks aren't network propagated anyway, hence not what
+                         * we are after here. */
+                        log_debug("Not locking image file '%s', since it's a block device.", ip);
+                        return 0;
+                }
+                r = stat_verify_regular(&st);
+                if (r < 0)
+                        return log_error_errno(r, "Image file to lock is not a regular file: %m");
+
                 if (flock(image_fd, LOCK_EX|LOCK_NB) < 0) {
 
                         if (errno == EWOULDBLOCK)