@@ -2486,165 +2486,162 @@ static int _dm_target_query_integrity(struct crypt_device *cd,
24862486
24872487 tgt -> u .integrity .sector_size = SECTOR_SIZE ;
24882488
2489- /* Features section */
2490- if (params ) {
2491- /* Number of arguments */
2492- val64 = strtoull (params , & params , 10 );
2493- if (* params != ' ' )
2494- goto err ;
2495- params ++ ;
2489+ /* Features section, number of arguments (always included) */
2490+ val64 = strtoull (params , & params , 10 );
2491+ if (* params != ' ' )
2492+ goto err ;
2493+ params ++ ;
24962494
2497- features = (int )val64 ;
2498- for (i = 0 ; i < features ; i ++ ) {
2499- r = - EINVAL ;
2500- if (!params )
2495+ features = (int )val64 ;
2496+ for (i = 0 ; i < features ; i ++ ) {
2497+ r = - EINVAL ;
2498+ if (!params )
2499+ goto err ;
2500+ arg = strsep (& params , " " );
2501+ if (sscanf (arg , "journal_sectors:%u" , & val ) == 1 )
2502+ tgt -> u .integrity .journal_size = val * SECTOR_SIZE ;
2503+ else if (sscanf (arg , "journal_watermark:%u" , & val ) == 1 )
2504+ tgt -> u .integrity .journal_watermark = val ;
2505+ else if (sscanf (arg , "sectors_per_bit:%" PRIu64 , & val64 ) == 1 ) {
2506+ if (val64 > UINT_MAX )
25012507 goto err ;
2502- arg = strsep (& params , " " );
2503- if (sscanf (arg , "journal_sectors:%u" , & val ) == 1 )
2504- tgt -> u .integrity .journal_size = val * SECTOR_SIZE ;
2505- else if (sscanf (arg , "journal_watermark:%u" , & val ) == 1 )
2506- tgt -> u .integrity .journal_watermark = val ;
2507- else if (sscanf (arg , "sectors_per_bit:%" PRIu64 , & val64 ) == 1 ) {
2508- if (val64 > UINT_MAX )
2508+ /* overloaded value for bitmap mode */
2509+ tgt -> u .integrity .journal_watermark = (unsigned int )val64 ;
2510+ } else if (sscanf (arg , "commit_time:%u" , & val ) == 1 )
2511+ tgt -> u .integrity .journal_commit_time = val ;
2512+ else if (sscanf (arg , "bitmap_flush_interval:%u" , & val ) == 1 )
2513+ /* overloaded value for bitmap mode */
2514+ tgt -> u .integrity .journal_commit_time = val ;
2515+ else if (sscanf (arg , "interleave_sectors:%u" , & val ) == 1 )
2516+ tgt -> u .integrity .interleave_sectors = val ;
2517+ else if (sscanf (arg , "block_size:%u" , & val ) == 1 )
2518+ tgt -> u .integrity .sector_size = val ;
2519+ else if (sscanf (arg , "buffer_sectors:%u" , & val ) == 1 )
2520+ tgt -> u .integrity .buffer_sectors = val ;
2521+ else if (!strncmp (arg , "internal_hash:" , 14 ) && !integrity ) {
2522+ str = & arg [14 ];
2523+ arg = strsep (& str , ":" );
2524+ if (get_flags & DM_ACTIVE_INTEGRITY_PARAMS ) {
2525+ integrity = strdup (arg );
2526+ if (!integrity ) {
2527+ r = - ENOMEM ;
25092528 goto err ;
2510- /* overloaded value for bitmap mode */
2511- tgt -> u .integrity .journal_watermark = (unsigned int )val64 ;
2512- } else if (sscanf (arg , "commit_time:%u" , & val ) == 1 )
2513- tgt -> u .integrity .journal_commit_time = val ;
2514- else if (sscanf (arg , "bitmap_flush_interval:%u" , & val ) == 1 )
2515- /* overloaded value for bitmap mode */
2516- tgt -> u .integrity .journal_commit_time = val ;
2517- else if (sscanf (arg , "interleave_sectors:%u" , & val ) == 1 )
2518- tgt -> u .integrity .interleave_sectors = val ;
2519- else if (sscanf (arg , "block_size:%u" , & val ) == 1 )
2520- tgt -> u .integrity .sector_size = val ;
2521- else if (sscanf (arg , "buffer_sectors:%u" , & val ) == 1 )
2522- tgt -> u .integrity .buffer_sectors = val ;
2523- else if (!strncmp (arg , "internal_hash:" , 14 ) && !integrity ) {
2524- str = & arg [14 ];
2525- arg = strsep (& str , ":" );
2526- if (get_flags & DM_ACTIVE_INTEGRITY_PARAMS ) {
2527- integrity = strdup (arg );
2528- if (!integrity ) {
2529- r = - ENOMEM ;
2530- goto err ;
2531- }
25322529 }
2530+ }
25332531
2534- if (str ) {
2535- len = crypt_hex_to_bytes (str , & str2 , 1 );
2536- if (len < 0 ) {
2537- r = len ;
2538- goto err ;
2539- }
2540-
2541- r = 0 ;
2542- if (get_flags & DM_ACTIVE_CRYPT_KEY ) {
2543- vk = crypt_alloc_volume_key (len , str2 );
2544- if (!vk )
2545- r = - ENOMEM ;
2546- } else if (get_flags & DM_ACTIVE_CRYPT_KEYSIZE ) {
2547- vk = crypt_alloc_volume_key (len , NULL );
2548- if (!vk )
2549- r = - ENOMEM ;
2550- }
2551- crypt_safe_free (str2 );
2552- if (r < 0 )
2553- goto err ;
2554- }
2555- } else if (!strncmp (arg , "meta_device:" , 12 ) && !meta_device ) {
2556- if (get_flags & DM_ACTIVE_DEVICE ) {
2557- str = crypt_lookup_dev (& arg [12 ]);
2558- r = device_alloc (cd , & meta_device , str );
2559- free (str );
2560- if (r < 0 && r != - ENOTBLK )
2561- goto err ;
2532+ if (str ) {
2533+ len = crypt_hex_to_bytes (str , & str2 , 1 );
2534+ if (len < 0 ) {
2535+ r = len ;
2536+ goto err ;
25622537 }
2563- } else if (!strncmp (arg , "journal_crypt:" , 14 ) && !journal_crypt ) {
2564- str = & arg [14 ];
2565- arg = strsep (& str , ":" );
2566- if (get_flags & DM_ACTIVE_INTEGRITY_PARAMS ) {
2567- journal_crypt = strdup (arg );
2568- if (!journal_crypt ) {
2538+
2539+ r = 0 ;
2540+ if (get_flags & DM_ACTIVE_CRYPT_KEY ) {
2541+ vk = crypt_alloc_volume_key (len , str2 );
2542+ if (!vk )
2543+ r = - ENOMEM ;
2544+ } else if (get_flags & DM_ACTIVE_CRYPT_KEYSIZE ) {
2545+ vk = crypt_alloc_volume_key (len , NULL );
2546+ if (!vk )
25692547 r = - ENOMEM ;
2570- goto err ;
2571- }
25722548 }
2549+ crypt_safe_free (str2 );
2550+ if (r < 0 )
2551+ goto err ;
2552+ }
2553+ } else if (!strncmp (arg , "meta_device:" , 12 ) && !meta_device ) {
2554+ if (get_flags & DM_ACTIVE_DEVICE ) {
2555+ str = crypt_lookup_dev (& arg [12 ]);
2556+ r = device_alloc (cd , & meta_device , str );
2557+ free (str );
2558+ if (r < 0 && r != - ENOTBLK )
2559+ goto err ;
2560+ }
2561+ } else if (!strncmp (arg , "journal_crypt:" , 14 ) && !journal_crypt ) {
2562+ str = & arg [14 ];
2563+ arg = strsep (& str , ":" );
2564+ if (get_flags & DM_ACTIVE_INTEGRITY_PARAMS ) {
2565+ journal_crypt = strdup (arg );
2566+ if (!journal_crypt ) {
2567+ r = - ENOMEM ;
2568+ goto err ;
2569+ }
2570+ }
25732571
2574- if (str ) {
2575- len = crypt_hex_to_bytes (str , & str2 , 1 );
2576- if (len < 0 ) {
2577- r = len ;
2578- goto err ;
2579- }
2580-
2581- r = 0 ;
2582- if (get_flags & DM_ACTIVE_JOURNAL_CRYPT_KEY ) {
2583- journal_crypt_key = crypt_alloc_volume_key (len , str2 );
2584- if (!journal_crypt_key )
2585- r = - ENOMEM ;
2586- } else if (get_flags & DM_ACTIVE_JOURNAL_CRYPT_KEYSIZE ) {
2587- journal_crypt_key = crypt_alloc_volume_key (len , NULL );
2588- if (!journal_crypt_key )
2589- r = - ENOMEM ;
2590- }
2591- crypt_safe_free (str2 );
2592- if (r < 0 )
2593- goto err ;
2572+ if (str ) {
2573+ len = crypt_hex_to_bytes (str , & str2 , 1 );
2574+ if (len < 0 ) {
2575+ r = len ;
2576+ goto err ;
25942577 }
2595- } else if (!strncmp (arg , "journal_mac:" , 12 ) && !journal_integrity ) {
2596- str = & arg [12 ];
2597- arg = strsep (& str , ":" );
2598- if (get_flags & DM_ACTIVE_INTEGRITY_PARAMS ) {
2599- journal_integrity = strdup (arg );
2600- if (!journal_integrity ) {
2578+
2579+ r = 0 ;
2580+ if (get_flags & DM_ACTIVE_JOURNAL_CRYPT_KEY ) {
2581+ journal_crypt_key = crypt_alloc_volume_key (len , str2 );
2582+ if (!journal_crypt_key )
2583+ r = - ENOMEM ;
2584+ } else if (get_flags & DM_ACTIVE_JOURNAL_CRYPT_KEYSIZE ) {
2585+ journal_crypt_key = crypt_alloc_volume_key (len , NULL );
2586+ if (!journal_crypt_key )
26012587 r = - ENOMEM ;
2602- goto err ;
2603- }
26042588 }
2589+ crypt_safe_free (str2 );
2590+ if (r < 0 )
2591+ goto err ;
2592+ }
2593+ } else if (!strncmp (arg , "journal_mac:" , 12 ) && !journal_integrity ) {
2594+ str = & arg [12 ];
2595+ arg = strsep (& str , ":" );
2596+ if (get_flags & DM_ACTIVE_INTEGRITY_PARAMS ) {
2597+ journal_integrity = strdup (arg );
2598+ if (!journal_integrity ) {
2599+ r = - ENOMEM ;
2600+ goto err ;
2601+ }
2602+ }
26052603
2606- if (str ) {
2607- len = crypt_hex_to_bytes (str , & str2 , 1 );
2608- if (len < 0 ) {
2609- r = len ;
2610- goto err ;
2611- }
2612-
2613- r = 0 ;
2614- if (get_flags & DM_ACTIVE_JOURNAL_MAC_KEY ) {
2615- journal_integrity_key = crypt_alloc_volume_key (len , str2 );
2616- if (!journal_integrity_key )
2617- r = - ENOMEM ;
2618- } else if (get_flags & DM_ACTIVE_JOURNAL_MAC_KEYSIZE ) {
2619- journal_integrity_key = crypt_alloc_volume_key (len , NULL );
2620- if (!journal_integrity_key )
2621- r = - ENOMEM ;
2622- }
2623- crypt_safe_free (str2 );
2624- if (r < 0 )
2625- goto err ;
2604+ if (str ) {
2605+ len = crypt_hex_to_bytes (str , & str2 , 1 );
2606+ if (len < 0 ) {
2607+ r = len ;
2608+ goto err ;
26262609 }
2627- } else if (!strcmp (arg , "recalculate" )) {
2628- * act_flags |= CRYPT_ACTIVATE_RECALCULATE ;
2629- } else if (!strcmp (arg , "reset_recalculate" )) {
2630- * act_flags |= CRYPT_ACTIVATE_RECALCULATE_RESET ;
2631- } else if (!strcmp (arg , "fix_padding" )) {
2632- tgt -> u .integrity .fix_padding = true;
2633- } else if (!strcmp (arg , "fix_hmac" )) {
2634- tgt -> u .integrity .fix_hmac = true;
2635- } else if (!strcmp (arg , "legacy_recalculate" )) {
2636- tgt -> u .integrity .legacy_recalc = true;
2637- } else if (!strcmp (arg , "allow_discards" )) {
2638- * act_flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS ;
2639- } else /* unknown option */
2640- goto err ;
2641- }
26422610
2643- /* All parameters should be processed */
2644- if (params && * params ) {
2645- r = - EINVAL ;
2611+ r = 0 ;
2612+ if (get_flags & DM_ACTIVE_JOURNAL_MAC_KEY ) {
2613+ journal_integrity_key = crypt_alloc_volume_key (len , str2 );
2614+ if (!journal_integrity_key )
2615+ r = - ENOMEM ;
2616+ } else if (get_flags & DM_ACTIVE_JOURNAL_MAC_KEYSIZE ) {
2617+ journal_integrity_key = crypt_alloc_volume_key (len , NULL );
2618+ if (!journal_integrity_key )
2619+ r = - ENOMEM ;
2620+ }
2621+ crypt_safe_free (str2 );
2622+ if (r < 0 )
2623+ goto err ;
2624+ }
2625+ } else if (!strcmp (arg , "recalculate" )) {
2626+ * act_flags |= CRYPT_ACTIVATE_RECALCULATE ;
2627+ } else if (!strcmp (arg , "reset_recalculate" )) {
2628+ * act_flags |= CRYPT_ACTIVATE_RECALCULATE_RESET ;
2629+ } else if (!strcmp (arg , "fix_padding" )) {
2630+ tgt -> u .integrity .fix_padding = true;
2631+ } else if (!strcmp (arg , "fix_hmac" )) {
2632+ tgt -> u .integrity .fix_hmac = true;
2633+ } else if (!strcmp (arg , "legacy_recalculate" )) {
2634+ tgt -> u .integrity .legacy_recalc = true;
2635+ } else if (!strcmp (arg , "allow_discards" )) {
2636+ * act_flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS ;
2637+ } else /* unknown option */
26462638 goto err ;
2647- }
2639+ }
2640+
2641+ /* All parameters should be processed */
2642+ if (params && * params ) {
2643+ r = - EINVAL ;
2644+ goto err ;
26482645 }
26492646
26502647 if (data_device )
0 commit comments