]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: don't keep invalid size= values
authordongshengyuan <545258830@qq.com>
Fri, 24 Jul 2026 08:38:19 +0000 (16:38 +0800)
committerdongshengyuan <545258830@qq.com>
Fri, 24 Jul 2026 08:38:19 +0000 (16:38 +0800)
size= is specified in bits, but arg_key_size stores bytes after
parsing. The parser used arg_key_size as temporary storage before
validation. When the value was not divisible by 8, the warning said
the option was ignored, but the invalid bit count remained.

Parse into a local variable and update arg_key_size only after
validation.

Repro:
build/systemd-cryptsetup attach sdscan /tmp/plain.img /tmp/key \
    plain,size=7

Before: warned ignored, then used key size 56 bits.
After: warned ignored, then kept the default key size 256 bits.

Follow-up for: 6131a78b4d247618715e042e14ad682f678d3b32

src/cryptsetup/cryptsetup.c

index 794983dcb69294a883d5aec7ce6f75050f781a66..379556f5d9e5641d3a91e553f89bf7e81a621d68 100644 (file)
@@ -193,19 +193,20 @@ static int parse_one_option(const char *option) {
                         return log_oom();
 
         } else if ((val = startswith(option, "size="))) {
+                unsigned key_size;
 
-                r = safe_atou(val, &arg_key_size);
+                r = safe_atou(val, &key_size);
                 if (r < 0) {
                         log_warning_errno(r, "Failed to parse %s, ignoring: %m", option);
                         return 0;
                 }
 
-                if (arg_key_size % 8) {
+                if (key_size % 8) {
                         log_warning("size= not a multiple of 8, ignoring.");
                         return 0;
                 }
 
-                arg_key_size /= 8;
+                arg_key_size = key_size / 8;
 
         } else if ((val = startswith(option, "sector-size="))) {