sys/dev/disk/dm: Always initialize target's status string
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 25 Oct 2015 12:33:42 +0000 (21:33 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 25 Oct 2015 14:49:09 +0000 (23:49 +0900)
Ioctl by dmsetup(8)'s "status" subcommand doesn't necessary
have a handler function from the way it's implemented.

In such a case, it seems prop_dictionary_t object of libprop
(in-kernel library) isn't properly initialized. This results
in dmsetup(8)'s "status" subcommand showing a binary junk.
This commit explicitly initializes it with C string "" to
fix this in above case where char *params remains == NULL.

This issue existed before f134a703 (touched related code).

Below can reproduce this issue. Using a kernel prior to this
commit will show some junk after each line of dmsetup status
output except for the last line. Target type and definition
of table can be anything, but the target needs to have more
than 1 entries for the table to reproduce this.

=====(A) using the existing code
  # kldload dm
  # echo "0 117218241 linear /dev/daX 0" > ./table.txt
  # echo "117218241 117218241 linear /dev/daY 0" >> ./table.txt
  # dmsetup create linear1 ./table.txt
  # dmsetup status /dev/mapper/linear1
  0 117218241 linear \9bΓΌ
  117218241 117218241 linear

=====(B) using this commit
  # kldload dm
  # echo "0 117218241 linear /dev/daX 0" > ./table.txt
  # echo "117218241 117218241 linear /dev/daY 0" >> ./table.txt
  # dmsetup create linear1 ./table.txt
  # dmsetup status /dev/mapper/linear1
  0 117218241 linear
  117218241 117218241 linear

sys/dev/disk/dm/dm_ioctl.c

index 4792c10..f6ff466 100644 (file)
@@ -911,10 +911,14 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
                } else {
                        params = NULL;
                }
+
                if (params != NULL) {
                        prop_dictionary_set_cstring(target_dict,
                            DM_TABLE_PARAMS, params);
                        kfree(params, M_DM);
+               } else {
+                       prop_dictionary_set_cstring(target_dict,
+                           DM_TABLE_PARAMS, "");
                }
 
                prop_array_add(cmd_array, target_dict);