Skip to contentSkip to conversation

Various multipath-tools patches

PATCH In review Bart Van Assche 4 participants 24 messages Mar 1, 2018 – Mar 8, 2018 Device mapper

lore
Share & tools
lore
#0 lore raw

cover Various multipath-tools patches

Hello Christophe,

This series contains the following patches:
- Four patches address Coverity complaints.
- One patch makes a function argument const.
- One patch addresses a bug that I discovered while inspecting the multipath command line tool output.

Please consider these patches for the multipath-tools project.

Thanks,

Bart.

Bart Van Assche (6):
multipathd/main.c: Fix indentation
libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is

    '\0'-terminated

libmultipath, alloc_path_with_pathinfo(): Declare third argument const
kpartx: Improve reliability of find_loop_by_file()
libmultipath: Fix sgio_get_vpd()
Introduce the ibmultipath/unaligned.h header file

 kpartx/lopart.c                       |  7 ++++---
 libmpathpersist/mpath_pr_ioctl.c      |  8 ++++----
 libmultipath/checkers/hp_sw.c         |  4 ++--
 libmultipath/discovery.c              | 22 +++++++++++---------
 libmultipath/discovery.h              |  2 +-
 libmultipath/prioritizers/alua_rtpg.c | 13 ++++++------
 libmultipath/prioritizers/alua_spc3.h | 35 ++------------------------------
 libmultipath/prioritizers/ontap.c     |  4 ++--
 libmultipath/unaligned.h              | 38 +++++++++++++++++++++++++++++++++++
 multipathd/main.c                     |  4 ++--
 10 files changed, 74 insertions(+), 63 deletions(-)
 create mode 100644 libmultipath/unaligned.h
Signature · 1 line
2.16.2
#1 lore raw

PATCH 1/6 multipathd/main.c: Fix indentation

This patch avoids that gcc reports the following:

main.c: In function 'uev_pathfail_check':
main.c:1022:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]

     if (!pp)
     ^~

main.c:1024:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
r = io_err_stat_handle_pathfail(pp);
^

---
 multipathd/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
multipathd/main.c +2 -2
index 27cf234623d0..ccbb0ad13d32 100644
@@ -1020,8 +1020,8 @@ uev_pathfail_check(struct uevent *uev, struct vectors *vecs)
 	lock(&vecs->lock);
 	pthread_testcancel();
 	pp = find_path_by_devt(vecs->pathvec, devt);
-    if (!pp)
-        goto out_lock;
+	if (!pp)
+		goto out_lock;
 	r = io_err_stat_handle_pathfail(pp);
 	if (r)
 		condlog(3, "io_err_stat: %s: cannot handle pathfail uevent",
Signature · 1 line
2.16.2
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] multipathd/main.c: Fix indentation

Quoted 5 lines · Bart Van Assche

This patch avoids that gcc reports the following:

main.c: In function 'uev_pathfail_check':
main.c:1022:5: warning: this 'if' clause does not guard... [- Wmisleading-indentation]

Quoted 8 lines
     if (!pp)
     ^~

main.c:1024:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
r = io_err_stat_handle_pathfail(pp);
^

Quoted 21 lines
---
 multipathd/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
multipathd/main.c +2 -2
index 27cf234623d0..ccbb0ad13d32 100644
@@ -1020,8 +1020,8 @@ uev_pathfail_check(struct uevent *uev, struct
 vectors *vecs)
 	lock(&vecs->lock);
 	pthread_testcancel();
 	pp = find_path_by_devt(vecs->pathvec, devt);
-    if (!pp)
-        goto out_lock;
+	if (!pp)
+		goto out_lock;
 	r = io_err_stat_handle_pathfail(pp);
 	if (r)

condlog(3, "io_err_stat: %s: cannot handle pathfail
uevent",

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#3 lore raw

PATCH 2/6 libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is '\0'-terminated

In reply to Bart Van Assche

Discovered by Coverity (CID 173257).

---
 libmultipath/discovery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/discovery.c +2 -2
index 4b31ddef23f0..fe50ce5062ea 100644
@@ -52,8 +52,8 @@ alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
 	if (!pp)
 		return PATHINFO_FAILED;
 
-	if(wwid)
-		strncpy(pp->wwid, wwid, sizeof(pp->wwid));
+	if (wwid)
+		strlcpy(pp->wwid, wwid, sizeof(pp->wwid));
 
 	if (safe_sprintf(pp->dev, "%s", devname)) {
 		condlog(0, "pp->dev too small");
Signature · 1 line
2.16.2
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is '\0'-terminated

Quoted 3 lines · Bart Van Assche

Discovered by Coverity (CID 173257).

Quoted 20 lines
---
 libmultipath/discovery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/discovery.c +2 -2
index 4b31ddef23f0..fe50ce5062ea 100644
@@ -52,8 +52,8 @@ alloc_path_with_pathinfo (struct config *conf,
 struct udev_device *udevice,
 	if (!pp)
 		return PATHINFO_FAILED;
 
-	if(wwid)
-		strncpy(pp->wwid, wwid, sizeof(pp->wwid));
+	if (wwid)
+		strlcpy(pp->wwid, wwid, sizeof(pp->wwid));
 
 	if (safe_sprintf(pp->dev, "%s", devname)) {

condlog(0, "pp->dev too small");

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#5 lore raw

PATCH 3/6 libmultipath, alloc_path_with_pathinfo(): Declare third argument const

In reply to Bart Van Assche

Since the third argument of this function is not modified inside that function, declare it const.

---
 libmultipath/discovery.c | 2 +-
 libmultipath/discovery.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libmultipath/discovery.c +1 -1
index fe50ce5062ea..d84715e15db1 100644
@@ -34,7 +34,7 @@
 
 int
 alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
-			  char *wwid, int flag, struct path **pp_ptr)
+			  const char *wwid, int flag, struct path **pp_ptr)
 {
 	int err = PATHINFO_FAILED;
 	struct path * pp;
libmultipath/discovery.h +1 -1
index b151cc7a39a8..bd5e6678a26d 100644
@@ -38,7 +38,7 @@ int get_state (struct path * pp, struct config * conf, int daemon, int state);
 int get_vpd_sgio (int fd, int pg, char * str, int maxlen);
 int pathinfo (struct path * pp, struct config * conf, int mask);
 int alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
-			      char *wwid, int flag, struct path **pp_ptr);
+			      const char *wwid, int flag, struct path **pp_ptr);
 int store_pathinfo (vector pathvec, struct config *conf,
 		    struct udev_device *udevice, int flag,
 		    struct path **pp_ptr);
Signature · 1 line
2.16.2
#6 lore raw

Re: [PATCH 3/6] libmultipath, alloc_path_with_pathinfo(): Declare third argument const

Quoted 4 lines · Bart Van Assche

Since the third argument of this function is not modified inside that function, declare it const.

ACK, but this hunk is part of my previously posted patch "libmultipath:
const qualifier for wwid and alias", which includes some more changes along similar lines and is part of a larger patch set that tries to improve "const" usage in libmultipath.

Quoted 38 lines
---
 libmultipath/discovery.c | 2 +-
 libmultipath/discovery.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libmultipath/discovery.c +1 -1
index fe50ce5062ea..d84715e15db1 100644
@@ -34,7 +34,7 @@
 
 int
 alloc_path_with_pathinfo (struct config *conf, struct udev_device
 *udevice,
-			  char *wwid, int flag, struct path
 **pp_ptr)
+			  const char *wwid, int flag, struct path
 **pp_ptr)

{

libmultipath/discovery.c +0 -0
 	int err = PATHINFO_FAILED;
 	struct path * pp;
libmultipath/discovery.h +1 -1
index b151cc7a39a8..bd5e6678a26d 100644
@@ -38,7 +38,7 @@ int get_state (struct path * pp, struct config *
 conf, int daemon, int state);
 int get_vpd_sgio (int fd, int pg, char * str, int maxlen);
 int pathinfo (struct path * pp, struct config * conf, int mask);
 int alloc_path_with_pathinfo (struct config *conf, struct
 udev_device *udevice,
-			      char *wwid, int flag, struct path
 **pp_ptr);
+			      const char *wwid, int flag, struct

path **pp_ptr);
int store_pathinfo (vector pathvec, struct config *conf,

libmultipath/discovery.h +0 -0
 		    struct udev_device *udevice, int flag,
 		    struct path **pp_ptr);
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#7 lore raw

Re: [PATCH 3/6] libmultipath, alloc_path_with_pathinfo(): Declare third argument const

Quoted 10 lines · Martin Wilck
Quoted 4 lines · Bart Van Assche

Since the third argument of this function is not modified inside that function, declare it const.

ACK, but this hunk is part of my previously posted patch "libmultipath:
const qualifier for wwid and alias", which includes some more changes along similar lines and is part of a larger patch set that tries to improve "const" usage in libmultipath.

Hello Martin,

If this patch duplicates some of your work then I'm fine with dropping this patch.

Bart.

#8 lore raw

PATCH 4/6 kpartx: Improve reliability of find_loop_by_file()

In reply to Bart Van Assche

Avoid that the strchr() call in this function examines uninitialized data on the stack. This patch avoids that Coverity reports the following:

CID 173252: Error handling issues (CHECKED_RETURN)
"read(int, void *, size_t)" returns the number of bytes read, but it is ignored.

---
 kpartx/lopart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
kpartx/lopart.c +4 -3
index 02b29e8cf91d..69c1eda1cc5c 100644
@@ -64,7 +64,7 @@ char *find_loop_by_file(const char *filename)
 	DIR *dir;
 	struct dirent *dent;
 	char dev[64], *found = NULL, *p;
-	int fd;
+	int fd, bytes_read;
 	struct stat statbuf;
 	struct loop_info loopinfo;
 	const char VIRT_BLOCK[] = "/sys/devices/virtual/block";
@@ -86,14 +86,15 @@ char *find_loop_by_file(const char *filename)
 		if (fd < 0)
 			continue;
 
-		if (read(fd, dev, sizeof(dev)) <= 0) {
+		bytes_read = read(fd, dev, sizeof(dev) - 1);
+		if (bytes_read <= 0) {
 			close(fd);
 			continue;
 		}
 
 		close(fd);
 
-		dev[sizeof(dev)-1] = '\0';
+		dev[bytes_read] = '\0';
 		p = strchr(dev, '\n');
 		if (p != NULL)
 			*p = '\0';
Signature · 1 line
2.16.2
Reviewed-by on v1 4/6
#9 lore raw

Re: [PATCH 4/6] kpartx: Improve reliability of find_loop_by_file()

Quoted 9 lines · Bart Van Assche

Avoid that the strchr() call in this function examines uninitialized data on the stack. This patch avoids that Coverity reports the following:

CID 173252: Error handling issues (CHECKED_RETURN) "read(int, void *, size_t)" returns the number of bytes read, but
it is ignored.

Quoted 35 lines
---
 kpartx/lopart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
kpartx/lopart.c +4 -3
index 02b29e8cf91d..69c1eda1cc5c 100644
@@ -64,7 +64,7 @@ char *find_loop_by_file(const char *filename)
 	DIR *dir;
 	struct dirent *dent;
 	char dev[64], *found = NULL, *p;
-	int fd;
+	int fd, bytes_read;
 	struct stat statbuf;
 	struct loop_info loopinfo;
 	const char VIRT_BLOCK[] = "/sys/devices/virtual/block";
@@ -86,14 +86,15 @@ char *find_loop_by_file(const char *filename)
 		if (fd < 0)
 			continue;
 
-		if (read(fd, dev, sizeof(dev)) <= 0) {
+		bytes_read = read(fd, dev, sizeof(dev) - 1);
+		if (bytes_read <= 0) {
 			close(fd);
 			continue;
 		}
 
 		close(fd);
 
-		dev[sizeof(dev)-1] = '\0';
+		dev[bytes_read] = '\0';
 		p = strchr(dev, '\n');
 		if (p != NULL)
 			*p = '\0';
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#10 lore raw

PATCH 5/6 libmultipath: Fix sgio_get_vpd()

In reply to Bart Van Assche

Pass the VPD page number to sgio_get_vpd() such that the page needed by the caller is queried instead of page 0x83. Fix the statement that computes the length of the page returned by do_inq(). Fix the return code check in the caller of sgio_get_vpd().

---
 libmultipath/discovery.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
libmultipath/discovery.c +5 -4
index d84715e15db1..780feb253797 100644
@@ -836,8 +836,9 @@ detect_alua(struct path * pp, struct config *conf)
 
 #define DEFAULT_SGIO_LEN 254
 
+/* Query VPD page @pg. Returns 0 upon success and -1 upon failure. */
 static int
-sgio_get_vpd (unsigned char * buff, int maxlen, int fd)
+sgio_get_vpd (unsigned char * buff, int maxlen, int fd, int pg)
 {
 	int len = DEFAULT_SGIO_LEN;
 
@@ -846,8 +847,8 @@ sgio_get_vpd (unsigned char * buff, int maxlen, int fd)
 		return -1;
 	}
 retry:
-	if (0 == do_inq(fd, 0, 1, 0x83, buff, len)) {
-		len = buff[3] + (buff[2] << 8);
+	if (0 == do_inq(fd, 0, 1, pg, buff, len)) {
+		len = buff[3] + (buff[2] << 8) + 4;
 		if (len >= maxlen)
 			return len;
 		if (len > DEFAULT_SGIO_LEN)
@@ -1099,7 +1100,7 @@ get_vpd_sgio (int fd, int pg, char * str, int maxlen)
 	unsigned char buff[4096];
 
 	memset(buff, 0x0, 4096);
-	if (sgio_get_vpd(buff, 4096, fd) <= 0) {
+	if (sgio_get_vpd(buff, 4096, fd, pg) < 0) {
 		condlog(3, "failed to issue vpd inquiry for pg%02x",
 			pg);
 		return -errno;
Signature · 1 line
2.16.2
#11 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 7 lines · Bart Van Assche

Pass the VPD page number to sgio_get_vpd() such that the page needed by the caller is queried instead of page 0x83. Fix the statement that computes the length of the page returned by do_inq(). Fix the return code check in the caller of sgio_get_vpd().

---

Bart, thanks for the patch. Please consider rebasing your work on my previously submitted patches which have already been positively reviewed ([1], [2]):

libmultipath: get_vpd_sgio: support VPD 0xc9
libmultipath: sgio_get_vpd: add page argument
libmultipath: fix return code of sgio_get_vpd()

Otherwise, ACK.

[1] https://www.redhat.com/archives/dm-devel/2018-January/msg00241.html
[2] https://www.redhat.com/archives/dm-devel/2018-January/msg00370.html

Martin

Quoted 42 lines
 libmultipath/discovery.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
libmultipath/discovery.c +2 -1
index d84715e15db1..780feb253797 100644
@@ -836,8 +836,9 @@ detect_alua(struct path * pp, struct config
 *conf)
 
 #define DEFAULT_SGIO_LEN 254
 
+/* Query VPD page @pg. Returns 0 upon success and -1 upon failure.
 */
 static int
-sgio_get_vpd (unsigned char * buff, int maxlen, int fd)
+sgio_get_vpd (unsigned char * buff, int maxlen, int fd, int pg)
 {
libmultipath/discovery.c +2 -2
 	int len = DEFAULT_SGIO_LEN;
@@ -846,8 +847,8 @@ sgio_get_vpd (unsigned char * buff, int maxlen,
 int fd)
 		return -1;
 	}
 retry:
-	if (0 == do_inq(fd, 0, 1, 0x83, buff, len)) {
-		len = buff[3] + (buff[2] << 8);
+	if (0 == do_inq(fd, 0, 1, pg, buff, len)) {
+		len = buff[3] + (buff[2] << 8) + 4;
 		if (len >= maxlen)
 			return len;
libmultipath/discovery.c +1 -1
 		if (len > DEFAULT_SGIO_LEN)
@@ -1099,7 +1100,7 @@ get_vpd_sgio (int fd, int pg, char * str, int
 maxlen)
 	unsigned char buff[4096];
 
 	memset(buff, 0x0, 4096);
-	if (sgio_get_vpd(buff, 4096, fd) <= 0) {
+	if (sgio_get_vpd(buff, 4096, fd, pg) < 0) {
 		condlog(3, "failed to issue vpd inquiry for pg%02x",
 			pg);

return -errno;

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#12 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 16 lines · Martin Wilck
Quoted 10 lines · Bart Van Assche

Pass the VPD page number to sgio_get_vpd() such that the page needed
by the caller is queried instead of page 0x83. Fix the statement that
computes the length of the page returned by do_inq(). Fix the return
code check in the caller of sgio_get_vpd().

---

Bart, thanks for the patch. Please consider rebasing your work on my previously submitted patches which have already been positively reviewed ([1], [2]):

Quoted 5 lines

libmultipath: get_vpd_sgio: support VPD 0xc9
libmultipath: sgio_get_vpd: add page argument
libmultipath: fix return code of sgio_get_vpd()

Otherwise, ACK.

Sorry, I found a glitch.

With the change of the "len" calculation and the return value check, we
need to make sure sufficient data has been read:

@@ -1100,13 +1101,19 @@ get_vpd_sgio (int fd, int pg, char * str, int maxlen)
unsigned char buff[4096];

memset(buff, 0x0, 4096);
- if (sgio_get_vpd(buff, 4096, fd, pg) <= 0) {
+ buff_len = sgio_get_vpd(buff, 4096, fd, pg);
+ if (buff_len < 0) {
condlog(3, "failed to issue vpd inquiry for pg%02x",
pg);
- return -errno;
+ return errno != 0 ? -errno : -1;
}

- if (buff[1] != pg) {
+ if (buff_len < 4) {
+ condlog(3, "vpd pg%02x error, short read", pg);
+ return -ENODATA;
+ }
+
+ if ( buff[1] != pg) {
condlog(3, "vpd pg%02x error, invalid vpd page %02x",
pg, buff[1]);
return -ENODATA;

As you can see I added also a small hunk that makes it explcicit that we don't return 0 on failure by accident.

Regards,
Martin

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#13 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 22 lines · Martin Wilck
Quoted 21 lines · Martin Wilck
Quoted 10 lines · Bart Van Assche

Pass the VPD page number to sgio_get_vpd() such that the page needed
by the caller is queried instead of page 0x83. Fix the statement that
computes the length of the page returned by do_inq(). Fix the return
code check in the caller of sgio_get_vpd().

---

Bart, thanks for the patch. Please consider rebasing your work on my
previously submitted patches which have already been positively reviewed ([1], [2]):

libmultipath: get_vpd_sgio: support VPD 0xc9
libmultipath: sgio_get_vpd: add page argument
libmultipath: fix return code of sgio_get_vpd()

Quoted 7 lines
Quoted 1 line

Otherwise, ACK.

Sorry, I found a glitch.

With the change of the "len" calculation and the return value check, we
need to make sure sufficient data has been read:

Replying to self - this is actually not necessary, as we're looking at the response buffer of a successful VPD INQUIRY, so we have to assume that at least the header has been read correctly.

All we need to change is the return code and the respective comment, because the function actually returns the number of INQUIRY bytes if INQUIRY was successful (before my patch "libmultipath: fix return code of sgio_get_vpd()", the function behaved rather strange, returning -1 on failure, 0 on success, and len > buffer length on buffer overflow).

Unless you object, I'll repost your series rebased on mine.

Martin

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#14 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 1 line · Martin Wilck

Unless you object, I'll repost your series rebased on mine.

Hello Martin,

Before you start working on that: has your patch series already been posted on the dm-devel mailing list?

Thanks,

Bart.

#15 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 8 lines · Bart Van Assche
Quoted 1 line · Martin Wilck

Unless you object, I'll repost your series rebased on mine.

Hello Martin,

Before you start working on that: has your patch series already been posted
on the dm-devel mailing list?

Yes. "PATCH v2 00/20] Various multipath-tools fixes" ff.
https://www.redhat.com/archives/dm-devel/2018-January/msg00219.html

Regards,
Martin

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#16 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 4 lines · Martin Wilck
Quoted 3 lines · Bart Van Assche
Quoted 1 line · Martin Wilck

Unless you object, I'll repost your series rebased on mine.

Quoted 8 lines
Quoted 5 lines

Hello Martin,

Before you start working on that: has your patch series already been posted
on the dm-devel mailing list?

Yes. "PATCH v2 00/20] Various multipath-tools fixes" ff.
https://www.redhat.com/archives/dm-devel/2018-January/msg00219.html

Ah, thanks, but unfortunately these patches are no longer in my mailbox. I pulled these from https://github.com/openSUSE/multipath-tools. I'm fine with my patches being rebased on top of your series, whether or not the following issues get addressed:
* Several patches that are on the upstream-queue branch introduce trailing whitespace.
* The macro FREE_CONST() should never have been introduced. Introducing such a macro namely introduces the risk of calling free() for a string constant, something that should never happen. Have you considered to declare dynamically allocated strings, e.g. the result of strdup(), as char * instead of const char * ? I think with that change the FREE_CONST() macro definitions can be removed again.

Thanks,

Bart.

#17 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 27 lines · Bart Van Assche
Quoted 6 lines · Martin Wilck
Quoted 5 lines · Bart Van Assche
Quoted 1 line · Martin Wilck

Unless you object, I'll repost your series rebased on mine.

Hello Martin,

Quoted 7 lines
Quoted 4 lines

Before you start working on that: has your patch series already been
posted
on the dm-devel mailing list?

Yes. "PATCH v2 00/20] Various multipath-tools fixes" ff.
https://www.redhat.com/archives/dm-devel/2018-January/msg00219.html

Ah, thanks, but unfortunately these patches are no longer in my mailbox. I
pulled these from https://github.com/openSUSE/multipath-tools. I'm fine with
my patches being rebased on top of your series, whether or not the following
issues get addressed:
* Several patches that are on the upstream-queue branch introduce trailing
whitespace.
* The macro FREE_CONST() should never have been introduced. Introducing such

Quoted 8 lines

a macro namely introduces the risk of calling free() for a string
constant,
something that should never happen. Have you considered to declare dynamically allocated strings, e.g. the result of strdup(), as char
*
instead of const char * ? I think with that change the FREE_CONST()
macro
definitions can be removed again.

Another philosophical issue :-) I disagree with you here. The name FREE_CONST is obvious enough that people should think twice before using it. I have indeed considered what you propse, but I like being able to use "const char*" when I work with strings that shouldn't be changed. An accidental write to a const location is much easier to overlook than a FREE_CONST(). Freeing a "const char*" isn't always wrong, just if the pointer was passed in from elsewhere.

This issue is philosophical but not religious to me, so if you and maybe others are offended so much by FREE_CONST, I may ditch it again.

Regards,
Martin

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#18 lore raw

Re: [PATCH 5/6] libmultipath: Fix sgio_get_vpd()

Quoted 5 lines · Martin Wilck
Quoted 4 lines · Bart Van Assche

Yes. "PATCH v2 00/20] Various multipath-tools fixes" ff.

Quoted 2 lines

https://www.redhat.com/archives/dm-devel/2018-January/msg00219.ht
ml

Quoted 7 lines
Quoted 7 lines

Ah, thanks, but unfortunately these patches are no longer in my mailbox. I
pulled these from https://github.com/openSUSE/multipath-tools. I'm fine with
my patches being rebased on top of your series, whether or not the following
issues get addressed:

I pushed my latest state, including my rebase of your patches, to https://github.com/openSUSE/multipath-tools/commits/upstream-queue.
I plan to merge also Ben's and Chongyun's late submissions, but I didn't get around to it yet.

Regards,
Martin

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#19 lore raw

PATCH 6/6 Introduce the ibmultipath/unaligned.h header file

In reply to Bart Van Assche

This patch avoids that Coverity reports the following for the code in libmultipath/prioritizers/alua_rtpg.c:

CID 173256: Integer handling issues (SIGN_EXTENSION)

    Suspicious implicit sign extension: "buf[0]" with type "unsigned char" (8 bits, unsigned) is promoted in "((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 4" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned).  If "((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 4" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.
---
 libmpathpersist/mpath_pr_ioctl.c      |  8 ++++----
 libmultipath/checkers/hp_sw.c         |  4 ++--
 libmultipath/discovery.c              |  9 +++++----
 libmultipath/prioritizers/alua_rtpg.c | 13 ++++++------
 libmultipath/prioritizers/alua_spc3.h | 35 ++------------------------------
 libmultipath/prioritizers/ontap.c     |  4 ++--
 libmultipath/unaligned.h              | 38 +++++++++++++++++++++++++++++++++++
 7 files changed, 60 insertions(+), 51 deletions(-)
 create mode 100644 libmultipath/unaligned.h
libmpathpersist/mpath_pr_ioctl.c +4 -4
index 29df8c6f2da1..dbed4ca7fad4 100644
@@ -13,6 +13,7 @@
 #include <libudev.h>
 #include "mpath_pr_ioctl.h"
 #include "mpath_persist.h"
+#include "unaligned.h"
 
 #include "debug.h"
 
@@ -243,10 +244,9 @@ void mpath_format_readfullstatus(struct prin_resp *pr_buff, int len, int noisy)
 		memcpy(&fdesc.key, p, 8 );
 		fdesc.flag = p[12];
 		fdesc.scope_type =  p[13];
-		fdesc.rtpi = ((p[18] << 8) | p[19]);
+		fdesc.rtpi = get_unaligned_be16(&p[18]);
 
-		tid_len_len = ((p[20] << 24) | (p[21] << 16) |
-				(p[22] << 8) | p[23]);
+		tid_len_len = get_unaligned_be32(&p[20]);
 
 		if (tid_len_len > 0)
 			decode_transport_id( &fdesc, &p[24], tid_len_len);
@@ -277,7 +277,7 @@ decode_transport_id(struct prin_fulldescr *fdesc, unsigned char * p, int length)
 			jump = 24;
 			break;
 		case MPATH_PROTOCOL_ID_ISCSI:
-			num = ((p[2] << 8) | p[3]);
+			num = get_unaligned_be16(&p[2]);
 			memcpy(&fdesc->trnptid.iscsi_name, &p[4], num);
 			jump = (((num + 4) < 24) ? 24 : num + 4);
 			break;
libmultipath/checkers/hp_sw.c +2 -2
index 6019c9dbcd9d..cee9aab8d089 100644
@@ -14,6 +14,7 @@
 #include "checkers.h"
 
 #include "../libmultipath/sg_include.h"
+#include "../libmultipath/unaligned.h"
 
 #define TUR_CMD_LEN		6
 #define INQUIRY_CMDLEN		6
@@ -63,8 +64,7 @@ do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
 	if (evpd)
 		inqCmdBlk[1] |= 1;
 	inqCmdBlk[2] = (unsigned char) pg_op;
-	inqCmdBlk[3] = (unsigned char)((mx_resp_len >> 8) & 0xff);
-	inqCmdBlk[4] = (unsigned char) (mx_resp_len & 0xff);
+	put_unaligned_be16(mx_resp_len, &inqCmdBlk[3]);
 	memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
 	memset(sense_b, 0, SENSE_BUFF_LEN);
 	io_hdr.interface_id = 'S';
libmultipath/discovery.c +5 -4
index 780feb253797..1d027927bd98 100644
@@ -30,6 +30,7 @@
 #include "discovery.h"
 #include "prio.h"
 #include "defaults.h"
+#include "unaligned.h"
 #include "prioritizers/alua_rtpg.h"
 
 int
@@ -848,7 +849,7 @@ sgio_get_vpd (unsigned char * buff, int maxlen, int fd, int pg)
 	}
 retry:
 	if (0 == do_inq(fd, 0, 1, pg, buff, len)) {
-		len = buff[3] + (buff[2] << 8) + 4;
+		len = get_unaligned_be16(&buff[2]) + 4;
 		if (len >= maxlen)
 			return len;
 		if (len > DEFAULT_SGIO_LEN)
@@ -879,7 +880,7 @@ static int
 parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len)
 {
 	char *p = NULL;
-	int len = in[3] + (in[2] << 8);
+	int len = get_unaligned_be16(&in[2]);
 
 	if (len >= out_len) {
 		condlog(2, "vpd pg80 overflow, %d/%d bytes required",
@@ -1079,7 +1080,7 @@ get_vpd_sysfs (struct udev_device *parent, int pg, char * str, int maxlen)
 			pg, buff[1]);
 		return -ENODATA;
 	}
-	buff_len = (buff[2] << 8) + buff[3] + 4;
+	buff_len = get_unaligned_be16(&buff[2]) + 4;
 	if (buff_len > 4096)
 		condlog(3, "vpd pg%02x page truncated", pg);
 
@@ -1111,7 +1112,7 @@ get_vpd_sgio (int fd, int pg, char * str, int maxlen)
 			pg, buff[1]);
 		return -ENODATA;
 	}
-	buff_len = (buff[2] << 8) + buff[3] + 4;
+	buff_len = get_unaligned_be16(&buff[2]) + 4;
 	if (buff_len > 4096)
 		condlog(3, "vpd pg%02x page truncated", pg);
 
libmultipath/prioritizers/alua_rtpg.c +7 -6
index e9d83286ff16..e43150200ffc 100644
@@ -26,6 +26,7 @@
 #include "../structs.h"
 #include "../prio.h"
 #include "../discovery.h"
+#include "../unaligned.h"
 #include "alua_rtpg.h"
 
 #define SENSE_BUFF_LEN  32
@@ -128,7 +129,7 @@ do_inquiry(int fd, int evpd, unsigned int codepage,
 		inquiry_command_set_evpd(&cmd);
 		cmd.page = codepage;
 	}
-	set_uint16(cmd.length, resplen);
+	put_unaligned_be16(resplen, cmd.length);
 	PRINT_HEX((unsigned char *) &cmd, sizeof(cmd));
 
 	memset(&hdr, 0, sizeof(hdr));
@@ -220,7 +221,7 @@ get_target_port_group(struct path * pp, unsigned int timeout)
 		if (rc < 0)
 			goto out;
 
-		scsi_buflen = (buf[2] << 8 | buf[3]) + 4;
+		scsi_buflen = get_unaligned_be16(&buf[2]) + 4;
 		/* Paranoia */
 		if (scsi_buflen >= USHRT_MAX)
 			scsi_buflen = USHRT_MAX;
@@ -251,7 +252,7 @@ get_target_port_group(struct path * pp, unsigned int timeout)
 				continue;
 			}
 			p  = (struct vpd83_tpg_dscr *)dscr->data;
-			rc = get_uint16(p->tpg);
+			rc = get_unaligned_be16(p->tpg);
 		}
 	}
 
@@ -274,7 +275,7 @@ do_rtpg(int fd, void* resp, long resplen, unsigned int timeout)
 	memset(&cmd, 0, sizeof(cmd));
 	cmd.op			= OPERATION_CODE_RTPG;
 	rtpg_command_set_service_action(&cmd);
-	set_uint32(cmd.length, resplen);
+	put_unaligned_be32(resplen, cmd.length);
 	PRINT_HEX((unsigned char *) &cmd, sizeof(cmd));
 
 	memset(&hdr, 0, sizeof(hdr));
@@ -321,7 +322,7 @@ get_asymmetric_access_state(int fd, unsigned int tpg, unsigned int timeout)
 	rc = do_rtpg(fd, buf, buflen, timeout);
 	if (rc < 0)
 		goto out;
-	scsi_buflen = (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]) + 4;
+	scsi_buflen = get_unaligned_be32(&buf[0]) + 4;
 	if (scsi_buflen > UINT_MAX)
 		scsi_buflen = UINT_MAX;
 	if (buflen < scsi_buflen) {
@@ -342,7 +343,7 @@ get_asymmetric_access_state(int fd, unsigned int tpg, unsigned int timeout)
 	tpgd = (struct rtpg_data *) buf;
 	rc   = -RTPG_TPG_NOT_FOUND;
 	RTPG_FOR_EACH_PORT_GROUP(tpgd, dscr) {
-		if (get_uint16(dscr->tpg) == tpg) {
+		if (get_unaligned_be16(dscr->tpg) == tpg) {
 			if (rc != -RTPG_TPG_NOT_FOUND) {
 				PRINT_DEBUG("get_asymmetric_access_state: "
 					"more than one entry with same port "
libmultipath/prioritizers/alua_spc3.h +2 -33
index 13a0924719b4..58d507a5cbc9 100644
@@ -14,37 +14,6 @@
  */
 #ifndef __SPC3_H__
 #define __SPC3_H__
-/*=============================================================================
- * Some helper functions for getting and setting 16 and 32 bit values.
- *=============================================================================
- */
-static inline unsigned short
-get_uint16(unsigned char *p)
-{
-	return (p[0] << 8) + p[1];
-}
-
-static inline void
-set_uint16(unsigned char *p, unsigned short v)
-{
-	p[0] = (v >> 8) & 0xff;
-	p[1] = v & 0xff;
-}
-
-static inline unsigned int
-get_uint32(unsigned char *p)
-{
-	return (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3];
-}
-
-static inline void
-set_uint32(unsigned char *p, unsigned int v)
-{
-	p[0] = (v >> 24) & 0xff;
-	p[1] = (v >> 16) & 0xff;
-	p[2] = (v >>  8) & 0xff;
-	p[3] = v & 0xff;
-}
 
 /*=============================================================================
  * Definitions to support the standard inquiry command as defined in SPC-3.
@@ -232,7 +201,7 @@ struct vpd83_data {
 		for( \
 			d = p->data; \
 			(((char *) d) - ((char *) p)) < \
-			get_uint16(p->length); \
+			get_unaligned_be16(p->length); \
 			d = (struct vpd83_dscr *) \
 				((char *) d + d->length + 4) \
 		)
@@ -315,7 +284,7 @@ struct rtpg_data {
 #define RTPG_FOR_EACH_PORT_GROUP(p, g) \
 		for( \
 			g = &(p->data[0]); \
-			(((char *) g) - ((char *) p)) < get_uint32(p->length); \
+			(((char *) g) - ((char *) p)) < get_unaligned_be32(p->length); \
 			g = (struct rtpg_tpg_dscr *) ( \
 				((char *) g) + \
 				sizeof(struct rtpg_tpg_dscr) + \
libmultipath/prioritizers/ontap.c +2 -2
index ca06d6ce3a9f..6505033f44c9 100644
@@ -22,6 +22,7 @@
 #include "debug.h"
 #include "prio.h"
 #include "structs.h"
+#include "unaligned.h"
 
 #define INQUIRY_CMD	0x12
 #define INQUIRY_CMDLEN	6
@@ -197,8 +198,7 @@ static int ontap_prio(const char *dev, int fd, unsigned int timeout)
 	memset(&results, 0, sizeof (results));
 	rc = send_gva(dev, fd, 0x41, results, &results_size, timeout);
 	if (rc >= 0) {
-		tot_len = results[0] << 24 | results[1] << 16 |
-			  results[2] << 8 | results[3];
+		tot_len = get_unaligned_be32(&results[0]);
 		if (tot_len <= 8) {
 			goto try_fcp_proxy;
 		}
libmultipath/unaligned.h new file +38 -0
new file mode 100644
index 000000000000..14ec8b23e397
@@ -0,0 +1,38 @@
+#ifndef _UNALIGNED_H_
+#define _UNALIGNED_H_
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *ptr)
+{
+	const uint8_t *p = ptr;
+
+	return p[0] << 8 | p[1];
+}
+
+static inline uint32_t get_unaligned_be32(void *ptr)
+{
+	const uint8_t *p = ptr;
+
+	return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *ptr)
+{
+	uint8_t *p = ptr;
+
+	p[0] = val >> 8;
+	p[1] = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *ptr)
+{
+	uint8_t *p = ptr;
+
+	p[0] = val >> 24;
+	p[1] = val >> 16;
+	p[2] = val >> 8;
+	p[3] = val;
+}
+
+#endif /* _UNALIGNED_H_ */
Signature · 1 line
2.16.2
Reviewed-by on v1 6/6
#20 lore raw

Re: [PATCH 6/6] Introduce the ibmultipath/unaligned.h header file

Quoted 11 lines · Bart Van Assche

This patch avoids that Coverity reports the following for the code in libmultipath/prioritizers/alua_rtpg.c:

CID 173256: Integer handling issues (SIGN_EXTENSION)
Suspicious implicit sign extension: "buf[0]" with type "unsigned
char" (8 bits, unsigned) is promoted in "((buf[0] << 24) | (buf[1] <<
16) | (buf[2] << 8) | buf[3]) + 4" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned). If "((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 4" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.

Quoted 1 line
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on the v1 series
#21 lore raw
In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche

Hello Christophe,

This series contains the following patches:
- Four patches address Coverity complaints.
- One patch makes a function argument const.
- One patch addresses a bug that I discovered while inspecting the multipath command line tool output.

Please consider these patches for the multipath-tools project.

For the set. Buy I agree with Martin that we should fold some of these into his already posted patches.

-Ben

Quoted 34 lines

Thanks,

Bart.

Bart Van Assche (6):
multipathd/main.c: Fix indentation
libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is

    '\0'-terminated

libmultipath, alloc_path_with_pathinfo(): Declare third argument const
kpartx: Improve reliability of find_loop_by_file()
libmultipath: Fix sgio_get_vpd()
Introduce the ibmultipath/unaligned.h header file

 kpartx/lopart.c                       |  7 ++++---
 libmpathpersist/mpath_pr_ioctl.c      |  8 ++++----
 libmultipath/checkers/hp_sw.c         |  4 ++--
 libmultipath/discovery.c              | 22 +++++++++++---------
 libmultipath/discovery.h              |  2 +-
 libmultipath/prioritizers/alua_rtpg.c | 13 ++++++------
 libmultipath/prioritizers/alua_spc3.h | 35 ++------------------------------
 libmultipath/prioritizers/ontap.c     |  4 ++--
 libmultipath/unaligned.h              | 38 +++++++++++++++++++++++++++++++++++
 multipathd/main.c                     |  4 ++--
 10 files changed, 74 insertions(+), 63 deletions(-)
 create mode 100644 libmultipath/unaligned.h
Signature · 6 lines
2.16.2

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#22 lore raw

Hi Bart,

I've finally merged the queued patches, so you can rebase this patchset over the new head.

Thanks.

Quoted 56 lines · Benjamin Marzinski
Quoted 6 lines · Bart Van Assche

Hello Christophe,

This series contains the following patches:
- Four patches address Coverity complaints.
- One patch makes a function argument const.
- One patch addresses a bug that I discovered while inspecting the

multipath

Quoted 3 lines

command line tool output.

Please consider these patches for the multipath-tools project.

For the set. Buy I agree with Martin that we should fold some of these into his already posted patches.

-Ben

Quoted 14 lines

Thanks,

Bart.

Bart Van Assche (6):
multipathd/main.c: Fix indentation
libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is

    '\0'-terminated

libmultipath, alloc_path_with_pathinfo(): Declare third argument const
kpartx: Improve reliability of find_loop_by_file()
libmultipath: Fix sgio_get_vpd()
Introduce the ibmultipath/unaligned.h header file

Quoted 7 lines
 kpartx/lopart.c                       |  7 ++++---
 libmpathpersist/mpath_pr_ioctl.c      |  8 ++++----
 libmultipath/checkers/hp_sw.c         |  4 ++--
 libmultipath/discovery.c              | 22 +++++++++++---------
 libmultipath/discovery.h              |  2 +-
 libmultipath/prioritizers/alua_rtpg.c | 13 ++++++------
 libmultipath/prioritizers/alua_spc3.h | 35

++------------------------------

Quoted 2 lines
 libmultipath/prioritizers/ontap.c     |  4 ++--
 libmultipath/unaligned.h              | 38

+++++++++++++++++++++++++++++++++++

Quoted 11 lines
 multipathd/main.c                     |  4 ++--
 10 files changed, 74 insertions(+), 63 deletions(-)
 create mode 100644 libmultipath/unaligned.h

--
2.16.2

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#23 lore raw
Quoted 1 line · Christophe Varoqui

I've finally merged the queued patches, so you can rebase this patchset over the new head.

Hello Christophe,

I will rebase my patch series, retest and repost it.

Bart.