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

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