libmpathpersist fixes and some more
v3 cover libmpathpersist fixes and some more
Hi Christophe,
this is v3 of my small set of libmpathpersist fixes. It's based on your latest push. Sorry again for missing that.
Changes wrt v2:
- rebased to latest upstream (39ad8dc8)
- added another gcc 8.1 fix, and another small patch I hadn't submitted yet
Changes wrt v1:
- introduce and use get_unaligned_be64 (Bart van Assche)
- add test for (get|put)_unaligned_bexx functions
Note: we have both the "unaligned" and the "beXY_to_cpu" APIs now, for essentially the same purpose. I wonder if we should settle on a single API instead. I am unsure if beXY_to_cpu() has alignment issues on some architectures (I don't think there are issues on our current main target platforms). If yes, I believe that we'd be on the safe side using the "unaligned" API. Anyway, that could be done in a follow-up patch.
Thanks,
Martin
Martin Wilck (10):
libmpathpersist: remove duplicate test in readfullstatus
libmpathpersist: fix typo in mpath_format_readfullstatus
libmpathpersist: fix stack overflow in mpath_format_readfullstatus()
libmultipath: add (get|put)_unaligned_be64 multipath-tools/tests: add tests for get_unaligned_beXX
libmpathpersist: fix byte swapping for big endian systems (lib)mpathpersist: use O_RDONLY file descriptors
libmultipath: fix gcc 8.1 "truncated output" warnings
multipathd: fix buffer size in cli_getprkey()
libmultipath: avoid error messages from RDAC check
libmpathpersist/mpath_persist.c | 8 +-- libmpathpersist/mpath_pr_ioctl.c | 75 +++++++++---------------- libmultipath/propsel.c | 2 + libmultipath/sysfs.c | 4 +- libmultipath/unaligned.h | 16 ++++++ libmultipath/util.c | 4 +- mpathpersist/main.c | 2 +- multipathd/cli_handlers.c | 4 +- tests/Makefile | 2 +- tests/unaligned.c | 96 ++++++++++++++++++++++++++++++++ 10 files changed, 150 insertions(+), 63 deletions(-) create mode 100644 tests/unaligned.c
Signature · 1 line
2.17.1
PATCH v3 1/10 libmpathpersist: remove duplicate test in readfullstatus
--- libmpathpersist/mpath_pr_ioctl.c | 6 ------ 1 file changed, 6 deletions(-)
libmpathpersist/mpath_pr_ioctl.c +0 -6
@@ -216,12 +216,6 @@ void mpath_format_readfullstatus(struct prin_resp *pr_buff, int len, int noisy)mpath_reverse_uint32_byteorder (&pr_buff->prin_descriptor.prin_readfd.prgeneration);mpath_reverse_uint32_byteorder (&pr_buff->prin_descriptor.prin_readfd.number_of_descriptor); -if (0 == pr_buff->prin_descriptor.prin_readfd.number_of_descriptor) - { -return ; - } - -if (pr_buff->prin_descriptor.prin_readfd.number_of_descriptor ==0 ) {condlog (3 ,"No registration or resrvation found." );
Signature · 1 line
2.17.1
PATCH v3 2/10 libmpathpersist: fix typo in mpath_format_readfullstatus
In reply to Martin Wilck--- libmpathpersist/mpath_pr_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmpathpersist/mpath_pr_ioctl.c +1 -1
@@ -218,7 +218,7 @@ void mpath_format_readfullstatus(struct prin_resp *pr_buff, int len, int noisy)if (pr_buff->prin_descriptor.prin_readfd.number_of_descriptor ==0 ) { -condlog (3 ,"No registration or resrvation found." ); +condlog (3 ,"No registration or reservation found." );return ; }
Signature · 1 line
2.17.1
PATCH v3 3/10 libmpathpersist: fix stack overflow in mpath_format_readfullstatus()
In reply to Martin WilckSome storage arrays return corrupt data in response to READ FULL STATUS PRIN commands. This may lead to stack overflow if the values aren't sanitized.
--- libmpathpersist/mpath_pr_ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+)
libmpathpersist/mpath_pr_ioctl.c +9 -0
@@ -241,6 +241,13 @@ void mpath_format_readfullstatus(struct prin_resp *pr_buff, int len, int noisy) fdesc.rtpi =get_unaligned_be16 (&p[18 ]); tid_len_len =get_unaligned_be32 (&p[20 ]); +if (tid_len_len +24 + k >= additional_length) { +condlog (0 , +"%s: corrupt PRIN response: status descriptor end %d exceeds length %d" , + __func__, tid_len_len + k +24 , + additional_length); + tid_len_len = additional_length - k -24 ; + }if (tid_len_len >0 )decode_transport_id ( &fdesc, &p[24 ], tid_len_len);
@@ -272,6 +279,8 @@ decode_transport_id(struct prin_fulldescr *fdesc, unsigned char * p, int length)break ;case MPATH_PROTOCOL_ID_ISCSI : num =get_unaligned_be16 (&p[2 ]); +if (num >=sizeof (fdesc->trnptid.iscsi_name)) + num =sizeof (fdesc->trnptid.iscsi_name);memcpy (&fdesc->trnptid.iscsi_name, &p[4 ], num); jump = (((num +4 ) <24 ) ?24 : num +4 );break ;
Signature · 1 line
2.17.1
PATCH v3 4/10 libmultipath: add (get|put)_unaligned_be64
In reply to Martin Wilck--- libmultipath/unaligned.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
libmultipath/unaligned.h +16 -0
@@ -17,6 +17,14 @@ static inline uint32_t get_unaligned_be32(void *ptr)return p[0 ] <<24 | p[1 ] <<16 | p[2 ] <<8 | p[3 ]; } +static inline uint64_t get_unaligned_be64 (void *ptr) +{ +uint32_t low =get_unaligned_be32 (ptr +4 ); +uint64_t high =get_unaligned_be32 (ptr); + +return high <<32 | low; +} +static inline void put_unaligned_be16 (uint16_t val,void *ptr) {uint8_t *p = ptr;
@@ -35,4 +43,12 @@ static inline void put_unaligned_be32(uint32_t val, void *ptr) p[3] = val; } +static inline void put_unaligned_be64 (uint64_t val,void *ptr) +{ +uint8_t *p = ptr; + +put_unaligned_be32 (val >>32 , p); +put_unaligned_be32 (val, p +4 ); +} +#endif /* _UNALIGNED_H_ */
Signature · 1 line
2.17.1
PATCH v3 5/10 multipath-tools/tests: add tests for get_unaligned_beXX
In reply to Martin Wilck--- tests/Makefile | 2 +- tests/unaligned.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/unaligned.c
tests/Makefile +1 -1
@@ -3,7 +3,7 @@ include ../Makefile.inc CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka -TESTS := uevent parser util dmevents hwtable +TESTS := uevent parser util dmevents hwtable unaligned .SILENT: $(TESTS:%=%.o) .PRECIOUS: $(TESTS:%=%-test)
tests/unaligned.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 6/10 libmpathpersist: fix byte swapping for big endian systems
In reply to Martin WilckThe functions "mpath_reverse_uintXY_byteorder" were apparently meant to convert BE integers to native. This leads to wrong results on big-endian systems. Make these functions use the get_unaligned_beXY API, and rename.
Also, remove the unused endianness test in mpath_pr_ioctl.c.
--- libmpathpersist/mpath_persist.c | 8 ++--- libmpathpersist/mpath_pr_ioctl.c | 54 +++++++++----------------------- 2 files changed, 16 insertions(+), 46 deletions(-)
libmpathpersist/mpath_persist.c +2 -6
@@ -20,6 +20,7 @@#include <ctype.h> #include "propsel.h" #include "util.h" +#include "unaligned.h" #include "mpath_persist.h" #include "mpathpr.h"
@@ -560,12 +561,7 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, }if (!rollback && (thread[i].param.status ==MPATH_PR_RESERV_CONFLICT )){ rollback =1 ; - sa_key =0 ; -for (i =0 ; i <8 ; ++i){ -if (i >0 ) - sa_key <<=8 ; - sa_key |= paramp->sa_key[i]; - } + sa_key =get_unaligned_be64 (¶mp->sa_key[0 ]); status =MPATH_PR_RESERV_CONFLICT ; }if (!rollback && (status ==MPATH_PR_SUCCESS )){
libmpathpersist/mpath_pr_ioctl.c +14 -40
93 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 7/10 (lib)mpathpersist: use O_RDONLY file descriptors
In reply to Martin Wilckudevd catches close-after-write inotify events and generates "change" uvents for such devices, which may cause extra unnecessary and unwanted udev activity.
Therefore use O_RDONLY file descriptors for PRIN and PROUT commands. This works just as well as O_WRONLY. sg_persist has supported the --readonly option for years.
--- libmpathpersist/mpath_pr_ioctl.c | 4 ++-- mpathpersist/main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
libmpathpersist/mpath_pr_ioctl.c +2 -2
@@ -52,7 +52,7 @@ int prout_do_scsi_ioctl(char * dev, int rq_servact, int rq_scope,int fd =-1 ;snprintf (devname,FILE_NAME_SIZE ,"/dev/%s" ,dev); - fd =open (devname,O_WRONLY ); + fd =open (devname,O_RDONLY );if (fd <0 ){condlog (1 ,"%s: unable to open device." , dev);return MPATH_PR_FILE_ERROR ;
@@ -308,7 +308,7 @@ int prin_do_scsi_ioctl(char * dev, int rq_servact, struct prin_resp * resp, int {MPATH_PRIN_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0};snprintf (devname,FILE_NAME_SIZE ,"/dev/%s" ,dev); - fd =open (devname,O_WRONLY ); + fd =open (devname,O_RDONLY );if (fd <0 ){condlog (0 ,"%s: Unable to open device " , dev);return MPATH_PR_FILE_ERROR ;
mpathpersist/main.c +1 -1
@@ -380,7 +380,7 @@ int main (int argc, char * argv[]) }/* open device */ -if ((fd =open (device_name,O_WRONLY )) <0 ) +if ((fd =open (device_name,O_RDONLY )) <0 ) {fprintf (stderr,"%s: error opening file (rw) fd=%d\n" , device_name, fd);
Signature · 1 line
2.17.1
PATCH v3 8/10 libmultipath: fix gcc 8.1 "truncated output" warnings
In reply to Martin Wilckgcc 8.1 was warning about a possibly truncated output in snprintf.
--- libmultipath/sysfs.c | 4 ++-- libmultipath/util.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
libmultipath/sysfs.c +2 -2
@@ -239,7 +239,7 @@ sysfs_get_size (struct path *pp, unsigned long long * size)int sysfs_check_holders (char * check_devt,char * new_devt) {unsigned int major, new_minor, table_minor; -char path[PATH_SIZE ], check_dev[PATH_SIZE ]; +char path[PATH_MAX ], check_dev[PATH_SIZE ];char * table_name;DIR *dirfd;struct dirent *holder;
@@ -256,7 +256,7 @@ int sysfs_check_holders(char * check_devt, char * new_devt)condlog (3 ,"%s: checking holder" , check_dev); -snprintf (path,PATH_SIZE ,"/sys/block/%s/holders" , check_dev); +snprintf (path,sizeof (path),"/sys/block/%s/holders" , check_dev); dirfd =opendir (path);if (dirfd ==NULL ) { condlog(3, "%s: failed to open directory %s (%d)",
libmultipath/util.c +2 -2
@@ -331,7 +331,7 @@ setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached)int systemd_service_enabled_in (const char *dev,const char *prefix) { -char path[PATH_SIZE ], file[PATH_SIZE ], service[PATH_SIZE ]; +char path[PATH_SIZE ], file[PATH_MAX ], service[PATH_SIZE ];DIR *dirfd;struct dirent *d;int found =0 ;
@@ -358,7 +358,7 @@ int systemd_service_enabled_in(const char *dev, const char *prefix) p = d->d_name +strlen (d->d_name) -6 ;if (strcmp (p,".wants" ))continue ; -snprintf (file,PATH_SIZE ,"%s/%s/%s" , +snprintf (file,sizeof (file),"%s/%s/%s" , path, d->d_name, service);if (stat (file, &stbuf) ==0 ) {condlog (3 ,"%s: found %s" , dev, file);
Signature · 1 line
2.17.1
PATCH v3 9/10 multipathd: fix buffer size in cli_getprkey()
In reply to Martin Wilckgcc 8.1 warned about this.
--- multipathd/cli_handlers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
multipathd/cli_handlers.c +2 -2
@@ -1449,7 +1449,7 @@ cli_getprkey(void * v, char ** reply, int * len, void * data)if (!mpp)return 1 ; - *reply =malloc (20 ); + *reply =malloc (26 );if (!get_be64 (mpp->reservation_key)) {sprintf (*reply,"none\n" );
@@ -1458,7 +1458,7 @@ cli_getprkey(void * v, char ** reply, int * len, void * data) }if (mpp->sa_flags &MPATH_F_APTPL_MASK ) flagstr =":aptpl" ; -snprintf (*reply,20 ,"0x%" PRIx64"%s\n" , +snprintf (*reply,26 ,"0x%" PRIx64"%s\n" ,get_be64 (mpp->reservation_key), flagstr); (*reply)[19 ] ='\0' ; *len =strlen (*reply) +1 ;
Signature · 1 line
2.17.1
PATCH v3 10/10 libmultipath: avoid error messages from RDAC check
In reply to Martin WilckVPD pages are only valid for SCSI devices, so we should disable the RDAC detection for non-SCSI devices. Otherwise we'll get an error about VPD inquiry failed.
--- libmultipath/propsel.c | 2 ++ 1 file changed, 2 insertions(+)
libmultipath/propsel.c +2 -0
@@ -466,6 +466,8 @@ check_rdac(struct path * pp)int len;char buff[44 ]; +if (pp->bus !=SYSFS_BUS_SCSI ) +return 0 ; len =get_vpd_sgio (pp->fd,0xC9 , buff,44 );if (len <=0 )return 0 ;
Signature · 1 line
2.17.1
Benjamin Marzinski
maintainerQuoted 22 lines · Martin Wilck
Hi Christophe,
this is v3 of my small set of libmpathpersist fixes. It's based on your latest push. Sorry again for missing that.
Changes wrt v2:
- rebased to latest upstream (39ad8dc8)
- added another gcc 8.1 fix, and another small patch I hadn't submitted yetChanges wrt v1:
- introduce and useget_unaligned_be64(Bart van Assche)
- add test for (get|put)_unaligned_bexx functionsNote: we have both the "unaligned" and the "
beXY_to_cpu" APIs now, for essentially the same purpose. I wonder if we should settle on a single API instead. I am unsure ifbeXY_to_cpu()has alignment issues on some architectures (I don't think there are issues on our current main target platforms). If yes, I believe that we'd be on the safe side using the "unaligned" API. Anyway, that could be done in a follow-up patch.
Quoted 2 lines
Thanks,
Martin
ACK for the set.
-Ben
Quoted 28 lines
Martin Wilck (10):
libmpathpersist: remove duplicate test in readfullstatus
libmpathpersist: fix typo inmpath_format_readfullstatus
libmpathpersist: fix stack overflow inmpath_format_readfullstatus()
libmultipath: add (get|put)_unaligned_be64 multipath-tools/tests: add tests forget_unaligned_beXX
libmpathpersist: fix byte swapping for big endian systems (lib)mpathpersist: useO_RDONLYfile descriptors
libmultipath: fix gcc 8.1 "truncated output" warnings
multipathd: fix buffer size incli_getprkey()
libmultipath: avoid error messages from RDAC checklibmpathpersist/mpath_persist.c | 8 +-- libmpathpersist/mpath_pr_ioctl.c | 75 +++++++++---------------- libmultipath/propsel.c | 2 + libmultipath/sysfs.c | 4 +- libmultipath/unaligned.h | 16 ++++++ libmultipath/util.c | 4 +- mpathpersist/main.c | 2 +- multipathd/cli_handlers.c | 4 +- tests/Makefile | 2 +- tests/unaligned.c | 96 ++++++++++++++++++++++++++++++++ 10 files changed, 150 insertions(+), 63 deletions(-) create mode 100644 tests/unaligned.cSignature · 1 line
2.17.1