libmpathpersist: remove duplicate test in readfullstatus
PATCH 1/6 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 2/6 libmpathpersist: fix typo in mpath_format_readfullstatus
--- 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 3/6 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 4/6 libmpathpersist: fix byte swapping for big endian systems
In reply to Martin WilckThis code was obviously intended to convert big-endian data from PRIN to CPU endianness. It doesn't work on big endian systems.
--- libmpathpersist/mpath_persist.c | 7 +------ libmpathpersist/mpath_pr_ioctl.c | 16 ++-------------- 2 files changed, 3 insertions(+), 20 deletions(-)
libmpathpersist/mpath_persist.c +1 -6
@@ -543,12 +543,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 =be64_to_cpu (*(uint64_t *)¶mp->sa_key[0 ]); status =MPATH_PR_RESERV_CONFLICT ; }if (!rollback && (status ==MPATH_PR_SUCCESS )){
libmpathpersist/mpath_pr_ioctl.c +2 -14
@@ -485,24 +485,12 @@ int mpath_isLittleEndian(void)void mpath_reverse_uint16_byteorder (uint16_t *num) { -uint16_t byte0, byte1; - - byte0 = (*num &0x000000FF ) >>0 ; - byte1 = (*num &0x0000FF00 ) >>8 ; - - *num = ((byte0 <<8 ) | (byte1 <<0 )); + *num =get_unaligned_be16 (num); }void mpath_reverse_uint32_byteorder (uint32_t *num) { -uint32_t byte0, byte1, byte2, byte3; - - byte0 = (*num &0x000000FF ) >>0 ; - byte1 = (*num &0x0000FF00 ) >>8 ; - byte2 = (*num &0x00FF0000 ) >>16 ; - byte3 = (*num &0xFF000000 ) >>24 ; - - *num = ((byte0 <<24 ) | (byte1 <<16 ) | (byte2 <<8 ) | (byte3 <<0 )); + *num =get_unaligned_be32 (num); }void
Signature · 1 line
2.17.1
Re: [PATCH 4/6] libmpathpersist: fix byte swapping for big endian systems
libmpathpersist/mpath_persist.c int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, · line 546
Quoted 7 lines · Martin Wilck
libmpathpersist/mpath_persist.c +1
-6- sa_key =0 ; -for (i =0 ; i <8 ; ++i){ -if (i >0 ) - sa_key <<=8 ; - sa_key |= paramp->sa_key[i]; - } + sa_key =be64_to_cpu (*(uint64_t *)¶mp->sa_key[0 ]);
Have you considered to use get_unaligned_be64() instead of the above construct with casts?
Thanks,
Bart.
Re: [PATCH 4/6] libmpathpersist: fix byte swapping for big endian systems
Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Martin Wilck
libmpathpersist/mpath_persist.c +1
-6- sa_key =0 ; -for (i =0 ; i <8 ; ++i){ -if (i >0 ) - sa_key <<=8 ; - sa_key |= paramp->sa_key[i]; - } + sa_key = be64_to_cpu(*(uint64_t *)¶mp-
Quoted 4 lines
Quoted 1 line
Quoted 1 line
sa_key[0]);
Have you considered to use
get_unaligned_be64()instead of the above construct with casts?
Yes, I did. I opted for this construct for patch brevity (and admittedly, lazyness), because get_unaligned_be64() doesn't exist yet. I can change that of course if you insist.
Thanks,
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
Re: [PATCH 4/6] libmpathpersist: fix byte swapping for big endian systems
Quoted 9 lines · Martin Wilck
Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Martin Wilck
libmpathpersist/mpath_persist.c +1
-6- sa_key =0 ; -for (i =0 ; i <8 ; ++i){ -if (i >0 ) - sa_key <<=8 ; - sa_key |= paramp->sa_key[i]; - } + sa_key = be64_to_cpu(*(uint64_t *)¶mp-
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
sa_key[0]);
Have you considered to use
get_unaligned_be64()instead of the above construct with casts?Yes, I did. I opted for this construct for patch brevity (and admittedly, lazyness), because
get_unaligned_be64()doesn't exist yet. I can change that of course if you insist.
Adding an implementation of get_unaligned_be64() and introducing it in the above code would be highly appreciated. I think that will improve readability.
Thanks,
Bart.
Re: [PATCH 4/6] libmpathpersist: fix byte swapping for big endian systems
Quoted 6 lines · Bart Van Assche
Adding an implementation of
get_unaligned_be64()and introducing it in
the above code would be highly appreciated. I think that will improve
readability.
ok, will do.
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
PATCH 5/6 (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 6/6 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
@@ -329,7 +329,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 ;
@@ -356,7 +356,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
Quoted 1 line · Martin Wilck
Signed-off-by Martin Wilck <[email protected]>
in replies, please remove Eli from cc, his email bounces.
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