Blame SOURCES/0001-device_id-fix-segfault-verifying-serial-for-non-pv.patch

688916
From b01433cdc841133500a0ed4041b9b35838d45e87 Mon Sep 17 00:00:00 2001
688916
From: David Teigland <teigland@redhat.com>
688916
Date: Fri, 2 Dec 2022 11:59:09 -0600
688916
Subject: [PATCH] device_id: fix segfault verifying serial for non-pv
688916
688916
The recent change that verifies sys_serial system.devices entries
688916
using the PVID did not exclude non-PV devices from being checked.
688916
The verification code would attempt to use du->pvid which was null
688916
for the non-PVs causing a segfault.
688916
688916
(cherry picked from commit 6613a61d3b5ce4d12a6fef79195eac34f30ef4da)
688916
---
688916
 lib/device/device_id.c           |  6 ++-
688916
 test/shell/devicesfile-serial.sh | 79 ++++++++++++++++++++++++++++++++
688916
 2 files changed, 83 insertions(+), 2 deletions(-)
688916
688916
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
688916
index aae875776..96726a448 100644
688916
--- a/lib/device/device_id.c
688916
+++ b/lib/device/device_id.c
688916
@@ -2237,8 +2237,8 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
688916
 		 * number is correct, since serial numbers may not be unique.
688916
 		 * Search for the PVID on other devs in device_ids_check_serial.
688916
 		 */
688916
-		if ((du->idtype == DEV_ID_TYPE_SYS_SERIAL) &&
688916
-		    (!du->pvid || memcmp(dev->pvid, du->pvid, ID_LEN))) {
688916
+		if ((du->idtype == DEV_ID_TYPE_SYS_SERIAL) && du->pvid &&
688916
+		    memcmp(dev->pvid, du->pvid, ID_LEN)) {
688916
 			log_debug("suspect device id serial %s for %s", du->idname, dev_name(dev));
688916
 			str_list_add(cmd->mem, &cmd->device_ids_check_serial, dm_pool_strdup(cmd->mem, du->idname));
688916
 			*device_ids_invalid = 1;
688916
@@ -2570,6 +2570,8 @@ void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
688916
 	dm_list_iterate_items(dul, &dus_check) {
688916
 		if (!dul->du->dev)
688916
 			continue;
688916
+		if (!dul->du->pvid)
688916
+			continue;
688916
 		/* save previously matched devs so they can be dropped from
688916
 		   lvmcache at the end if they are no longer used */
688916
 		if (!(dil = dm_pool_zalloc(cmd->mem, sizeof(*dil))))
688916
diff --git a/test/shell/devicesfile-serial.sh b/test/shell/devicesfile-serial.sh
688916
index b7bfce29e..a88c1906a 100644
688916
--- a/test/shell/devicesfile-serial.sh
688916
+++ b/test/shell/devicesfile-serial.sh
688916
@@ -772,6 +772,85 @@ grep $SERIAL1 out2
688916
 grep $dev3 out3
688916
 grep $SERIAL3 out3
688916
 
688916
+# non-PV devices
688916
+
688916
+aux wipefs_a $dev1
688916
+aux wipefs_a $dev2
688916
+aux wipefs_a $dev3
688916
+aux wipefs_a $dev4
688916
+
688916
+echo $SERIAL1 > $SYS_DIR/dev/block/$MAJOR1:$MINOR1/device/serial
688916
+echo $SERIAL2 > $SYS_DIR/dev/block/$MAJOR2:$MINOR2/device/serial
688916
+echo $SERIAL2 > $SYS_DIR/dev/block/$MAJOR3:$MINOR3/device/serial
688916
+echo $SERIAL4 > $SYS_DIR/dev/block/$MAJOR4:$MINOR4/device/serial
688916
+
688916
+rm $DF
688916
+touch $DF
688916
+vgcreate $vg4 $dev4
688916
+lvmdevices --adddev "$dev1"
688916
+lvmdevices --adddev "$dev2"
688916
+lvmdevices --adddev "$dev3"
688916
+cat $DF
688916
+
688916
+grep $dev1 $DF |tee out1
688916
+grep $dev2 $DF |tee out2
688916
+grep $dev3 $DF |tee out3
688916
+grep $dev4 $DF |tee out4
688916
+
688916
+grep $SERIAL1 out1
688916
+grep $SERIAL2 out2
688916
+grep $SERIAL2 out3
688916
+grep $SERIAL4 out4
688916
+
688916
+pvs |tee out
688916
+grep $dev4 out
688916
+not grep $dev1 out
688916
+not grep $dev2 out
688916
+not grep $dev3 out
688916
+
688916
+pvcreate $dev1
688916
+pvs |tee out
688916
+grep $dev1 out
688916
+grep $dev4 out
688916
+not grep $dev2 out
688916
+not grep $dev3 out
688916
+
688916
+pvcreate $dev2
688916
+pvs |tee out
688916
+grep $dev1 out
688916
+grep $dev4 out
688916
+grep $dev2 out
688916
+not grep $dev3 out
688916
+
688916
+pvcreate $dev3
688916
+pvs |tee out
688916
+grep $dev1 out
688916
+grep $dev4 out
688916
+grep $dev2 out
688916
+grep $dev3 out
688916
+
688916
+PVID1=`pvs "$dev1" --noheading -o uuid | tr -d - | awk '{print $1}'`
688916
+PVID2=`pvs "$dev2" --noheading -o uuid | tr -d - | awk '{print $1}'`
688916
+PVID3=`pvs "$dev3" --noheading -o uuid | tr -d - | awk '{print $1}'`
688916
+PVID4=`pvs "$dev4" --noheading -o uuid | tr -d - | awk '{print $1}'`
688916
+OPVID1=`pvs "$dev1" --noheading -o uuid | awk '{print $1}'`
688916
+OPVID2=`pvs "$dev2" --noheading -o uuid | awk '{print $1}'`
688916
+OPVID3=`pvs "$dev3" --noheading -o uuid | awk '{print $1}'`
688916
+OPVID4=`pvs "$dev4" --noheading -o uuid | awk '{print $1}'`
688916
+
688916
+grep $dev1 $DF |tee out1
688916
+grep $dev2 $DF |tee out2
688916
+grep $dev3 $DF |tee out3
688916
+grep $dev4 $DF |tee out4
688916
+
688916
+grep $PVID1 out1
688916
+grep $PVID2 out2
688916
+grep $PVID3 out3
688916
+grep $PVID4 out4
688916
+
688916
+vgcreate $vg2 $dev2 $dev3
688916
+vgs | grep $vg2
688916
+
688916
 remove_base
688916
 rmmod brd
688916
 
688916
-- 
688916
2.38.1
688916