libmultipath: Fixes for NVME / NVMEoF
Subsystems (2)
cover libmultipath: Fixes for NVME / NVMEoF
Current code fails to set up multipath maps for NVME devices in a Linux target/Linux host combination. This series enables at least basic operation.
Patch 1/4 fixes a crash that happens if over-long WWIDs are encountered, and is not specific to NVME as such. Patch 2/4 drops
the broken test uevent_can_discard_by_devpath(). Patch 3/4 compensates for the additional event processing required by 2/4. Patch 4/4 mangles overlong "nvme.*" WWIDs to make them usable for multipath (related discussion in [1]; WWID_SIZE can't be simply increased because it has to match device mapper's DM_NAME_LEN).
[1] http://lists.infradead.org/pipermail/linux-nvme/2017-July/011960.html
Martin Wilck (4):
libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
libmultipath: drop uevent_can_discard_by_devpath
libmultipath: only listen for uevents with DEVTYPE=disk
libmultipath: fix over-long NVME WWIDs
libmultipath/discovery.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ libmultipath/uevent.c | 27 +--------------- 2 files changed, 81 insertions(+), 26 deletions(-)
Signature · 1 line
2.13.2
PATCH 1/4 libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
If the first WWID_LEN bytes of the uuid_attribute do not contain a 0 byte, pp->wwid may end up not properly terminated. Fix it.
--- libmultipath/discovery.c | 1 + 1 file changed, 1 insertion(+)
libmultipath/discovery.c +1 -0
@@ -1615,6 +1615,7 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) len =strlen (value); }strncpy (pp->wwid, value, len); + pp->wwid[WWID_SIZE -1 ] ='\0' ; }else {condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);
Signature · 1 line
2.13.2
Re: [PATCH 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
Quoted 13 lines · Martin Wilck
If the first
WWID_LENbytes of theuuid_attributedo not contain a 0 byte,pp->wwidmay end up not properly terminated. Fix it.Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 1 + 1 file changed, 1 insertion(+)libmultipath/discovery.c +0
-0
libmultipath/discovery.c get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) · line 1621
Quoted 7 lines
libmultipath/discovery.c +1
-0@@ -1615,6 +1615,7 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) len =strlen (value); }strncpy (pp->wwid, value, len); + pp->wwid[WWID_SIZE -1 ] ='\0' ; }else {condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);
Hi Martin,
Your patch does not cause all overflows to be reported. How about using the following (untested) alternative?
libmultipath/discovery.c +1 -6
@@ -1607,13 +1607,8 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)if (!value ||strlen (value) ==0 ) value =getenv (uid_attribute);if (value &&strlen (value)) { -if (strlen (value) +1 >WWID_SIZE ) { +if (strlcpy (pp->wwid, value,sizeof (pp->wwid)) >=WWID_SIZE )condlog (0 ,"%s: wwid overflow" , pp->dev); - len =WWID_SIZE ; - }else { - len =strlen (value); - } -strncpy (pp->wwid, value, len); }else {condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);
Bart.
Re: [PATCH 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
Hi Bart,
Quoted 25 lines · Bart Van Assche
Quoted 20 lines · Martin Wilck
If the first
WWID_LENbytes of theuuid_attributedo not contain a 0 byte,pp->wwidmay end up not properly terminated. Fix it.Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 1 + 1 file changed, 1 insertion(+)libmultipath/discovery.c +1
-0@@ -1615,6 +1615,7 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) len =strlen (value); }strncpy (pp->wwid, value, len); + pp->wwid[WWID_SIZE -1 ] ='\0' ; }else { condlog(3, "%s: no %s attribute", pp->dev,Quoted 1 line
uid_attribute);Hi Martin,
Quoted 1 line
Your patch does not cause all overflows to be reported.
I'm not sure what you mean. The overflow message is printed if and only if (strlen(value) + 1 > WWID_SIZE), which is correct, AFAICS. The point of my patch is just to avoid that multipath crashes later due to an unterminated string caused by this overflow.
Quoted 24 lines
How about using the
following (untested) alternative?libmultipath/discovery.c +1
-6@@ -1607,13 +1607,8 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)if (!value ||strlen (value) ==0 ) value =getenv (uid_attribute);if (value &&strlen (value)) { -if (strlen (value) +1 >WWID_SIZE ) { +if (strlcpy (pp->wwid, value,sizeof (pp->wwid)) >=WWID_SIZE )condlog (0 ,"%s: wwid overflow" , pp->dev); - len =WWID_SIZE ; - }else { - len =strlen (value); - } -strncpy (pp->wwid, value, len); }else {libmultipath/discovery.c +0
-0condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);
Quoted 1 line
Bart.
Let's have a strncpy vs. strlcpy discussion :D !
I can do this if you insist, but I don't see a big benefit. We've tested with the patch I submitted.
Thanks,
Martin
Re: [PATCH 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
Quoted 27 lines · Martin Wilck
Quoted 21 lines · Bart Van Assche
How about using the following (untested) alternative?
libmultipath/discovery.c +1
-6@@ -1607,13 +1607,8 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)if (!value ||strlen (value) ==0 ) value =getenv (uid_attribute);if (value &&strlen (value)) { -if (strlen (value) +1 >WWID_SIZE ) { +if (strlcpy (pp->wwid, value,sizeof (pp->wwid)) >=WWID_SIZE )condlog (0 ,"%s: wwid overflow" , pp->dev); - len =WWID_SIZE ; - }else { - len =strlen (value); - } -strncpy (pp->wwid, value, len); }else {libmultipath/discovery.c get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) · line 1614
Quoted 2 lines
libmultipath/discovery.c +0
-0condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);Let's have a strncpy vs. strlcpy discussion :D !
Quoted 2 lines
I can do this if you insist, but I don't see a big benefit. We've tested with the patch I submitted.
My comments were not intended as an invitation to open a strncpy() vs. strlcpy() discussion. What I wanted to illustrate with the above patch is that when using strlcpy() it is not necessary to explicitly zero-terminate a string because strlcpy() guarantees zero-termination. Compact code that is as readable as more verbose code is always better because compact code is easier to verify.
Bart.
Re: [PATCH 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
Quoted 7 lines · Bart Van Assche
Quoted 5 lines · Martin Wilck
Let's have a strncpy vs. strlcpy discussion :D !
I can do this if you insist, but I don't see a big benefit. We've tested with the patch I submitted.
Quoted 10 lines
My comments were not intended as an invitation to open a
strncpy()vs.strlcpy()
discussion. What I wanted to illustrate with the above patch is that when usingstrlcpy()it is not necessary to explicitly zero-terminate a string becausestrlcpy()guarantees zero-termination. Compact code that is as readable as more
verbose code is always better because compact code is easier to verify.
OK. I'll wait for comments on the other patches, and change v2 of this patch to your version.
Martin
Re: [PATCH 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
Quoted 2 lines · Martin Wilck
OK. I'll wait for comments on the other patches, and change v2 of this patch to your version.
Hello Martin,
Patch 1/4 of this series is the only patch I wanted to comment on. The other patches touch code that I'm not familiar enough with to review them.
Bart.
Benjamin Marzinski
maintainerRe: [PATCH 1/4] libmultipath: get_udev_uid: make sure pp->wwid is 0-terminated
In reply to Martin WilckACK, but I'm fine with Bart's patch as well.
-Ben
Quoted 22 lines · Martin Wilck
If the first
WWID_LENbytes of theuuid_attributedo not contain a 0 byte,pp->wwidmay end up not properly terminated. Fix it.Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 1 + 1 file changed, 1 insertion(+)libmultipath/discovery.c +1
-0@@ -1615,6 +1615,7 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) len =strlen (value); }strncpy (pp->wwid, value, len); + pp->wwid[WWID_SIZE -1 ] ='\0' ; }else {condlog (3 ,"%s: no %s attribute" , pp->dev, uid_attribute);Signature · 1 line
2.13.2
PATCH 2/4 libmultipath: drop uevent_can_discard_by_devpath
In reply to Martin WilckThis function is broken. Not all devices that matter for multipathd follow the block/$DEVICE/$PARTITION convention (example: NVME)
--- libmultipath/uevent.c | 25 ------------------------- 1 file changed, 25 deletions(-)
libmultipath/uevent.c +0 -25
@@ -143,36 +143,11 @@ uevent_need_merge(void)return need_merge; } -static bool -uevent_can_discard_by_devpath (const char *devpath) -{ -static const char BLOCK [] ="/block/" ; -const char *tmp =strstr (devpath,BLOCK ); - -if (tmp ==NULL ) { -condlog (4 ,"no /block/ in '%s'" , devpath); -return true; - } - tmp +=sizeof (BLOCK ) -1 ; -if (*tmp =='\0' ) -/* just ".../block/" - discard */ -return true; -/* -* If there are more path elements after ".../block/xyz", -* it's a partition - discard it; but don't discard ".../block/sda/". -*/ - tmp =strchr (tmp,'/' ); -return tmp !=NULL && *(tmp +1 ) !='\0' ; -} -bool uevent_can_discard (struct uevent *uev) {struct config * conf; -if (uevent_can_discard_by_devpath (uev->devpath)) -return true; -/* * do not filter dm devices by devnode */
Signature · 1 line
2.13.2
Re: [PATCH 2/4] libmultipath: drop uevent_can_discard_by_devpath
Quoted 8 lines
From: [email protected] [mailto:[email protected]] On Behalf Of Martin Wilck
Sent: Friday, July 14, 2017 6:32 AM
To: Christophe Varoqui <[email protected]>; [email protected]; Benjamin Marzinski <[email protected]>; Hannes Reinecke <[email protected]>; Guan Junxiong <[email protected]>
Cc: Martin Wilck <[email protected]>; [email protected]; Xose Vazquez Perez <[email protected]>; linux- [email protected]
Subject: [dm-devel] [PATCH 2/4] libmultipath: dropuevent_can_discard_by_devpath
Quoted 6 lines
This function is broken. Not all devices that matter for multipathd follow the
block/$DEVICE/$PARTITIONconvention (example: NVME)Signed-off-by Martin Wilck <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>---
Benjamin Marzinski
maintainerRe: [PATCH 2/4] libmultipath: drop uevent_can_discard_by_devpath
In reply to Martin WilckACK
-Ben
Quoted 52 lines · Martin Wilck
This function is broken. Not all devices that matter for multipathd follow the
block/$DEVICE/$PARTITIONconvention (example: NVME)Signed-off-by Martin Wilck <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- libmultipath/uevent.c | 25 ------------------------- 1 file changed, 25 deletions(-)libmultipath/uevent.c +0
-25@@ -143,36 +143,11 @@ uevent_need_merge(void)return need_merge; } -static bool -uevent_can_discard_by_devpath (const char *devpath) -{ -static const char BLOCK [] ="/block/" ; -const char *tmp =strstr (devpath,BLOCK ); - -if (tmp ==NULL ) { -condlog (4 ,"no /block/ in '%s'" , devpath); -return true; - } - tmp +=sizeof (BLOCK ) -1 ; -if (*tmp =='\0' ) -/* just ".../block/" - discard */ -return true; -/* -* If there are more path elements after ".../block/xyz", -* it's a partition - discard it; but don't discard ".../block/sda/". -*/ - tmp =strchr (tmp,'/' ); -return tmp !=NULL && *(tmp +1 ) !='\0' ; -} -bool uevent_can_discard (struct uevent *uev) {struct config * conf; -if (uevent_can_discard_by_devpath (uev->devpath)) -return true; -/* * do not filter dm devices by devnode */ Signature · 1 line
2.13.2
Re: [PATCH 2/4] libmultipath: drop uevent_can_discard_by_devpath
In reply to Martin WilckThis patch combined with PATCH 3/4 looks more elegant than my previous patch and it works to fix the multipathd hotplug problem for NoF. Thanks.
Quoted 51 lines · Martin Wilck
This function is broken. Not all devices that matter for multipathd follow the
block/$DEVICE/$PARTITIONconvention (example: NVME)Signed-off-by Martin Wilck <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- libmultipath/uevent.c | 25 ------------------------- 1 file changed, 25 deletions(-)libmultipath/uevent.c +0
-25@@ -143,36 +143,11 @@ uevent_need_merge(void)return need_merge; } -static bool -uevent_can_discard_by_devpath (const char *devpath) -{ -static const char BLOCK [] ="/block/" ; -const char *tmp =strstr (devpath,BLOCK ); - -if (tmp ==NULL ) { -condlog (4 ,"no /block/ in '%s'" , devpath); -return true; - } - tmp +=sizeof (BLOCK ) -1 ; -if (*tmp =='\0' ) -/* just ".../block/" - discard */ -return true; -/* -* If there are more path elements after ".../block/xyz", -* it's a partition - discard it; but don't discard ".../block/sda/". -*/ - tmp =strchr (tmp,'/' ); -return tmp !=NULL && *(tmp +1 ) !='\0' ; -} -bool uevent_can_discard (struct uevent *uev) {struct config * conf; -if (uevent_can_discard_by_devpath (uev->devpath)) -return true; -/* * do not filter dm devices by devnode */
PATCH 3/4 libmultipath: only listen for uevents with DEVTYPE=disk
In reply to Martin WilckWe are only interested in disks anyway. This saves us checking for devtype in the uevent processing queue, and is more powerful than the previous test in the dropped function uevent_can_discard_by_devpath().
--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/uevent.c +1 -1
@@ -770,7 +770,7 @@ int uevent_listen(struct udev *udev) goto out; } err =udev_monitor_filter_add_match_subsystem_devtype (monitor,"block" , -NULL ); +"disk" );if (err)condlog (2 ,"failed to create filter : %s" ,strerror (-err)); err =udev_monitor_enable_receiving (monitor);
Signature · 1 line
2.13.2
Re: [PATCH 3/4] libmultipath: only listen for uevents with DEVTYPE=disk
Quoted 9 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Martin Wilck
Sent: Friday, July 14, 2017 6:32 AM
To: Christophe Varoqui <[email protected]>; [email protected]; Benjamin Marzinski <[email protected]>; Hannes Reinecke <[email protected]>; Guan Junxiong <[email protected]>
Cc: Martin Wilck <[email protected]>; [email protected]; Xose Vazquez Perez <[email protected]>; linux- [email protected]
Subject: [dm-devel] [PATCH 3/4] libmultipath: only listen for uevents with DEVTYPE=disk
Quoted 8 lines
We are only interested in disks anyway. This saves us checking for devtype in the uevent processing queue, and is more powerful than the previous test in the dropped function
uevent_can_discard_by_devpath().Signed-off-by Martin Wilck <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>---
Benjamin Marzinski
maintainerRe: [PATCH 3/4] libmultipath: only listen for uevents with DEVTYPE=disk
In reply to Martin WilckACK
-Ben
Quoted 26 lines · Martin Wilck
We are only interested in disks anyway. This saves us checking for devtype in the uevent processing queue, and is more powerful than the previous test in the dropped function
uevent_can_discard_by_devpath().Signed-off-by Martin Wilck <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libmultipath/uevent.c +1
-1@@ -770,7 +770,7 @@ int uevent_listen(struct udev *udev) goto out; } err =udev_monitor_filter_add_match_subsystem_devtype (monitor,"block" , -NULL ); +"disk" );if (err)condlog (2 ,"failed to create filter : %s" ,strerror (-err)); err =udev_monitor_enable_receiving (monitor);Signature · 1 line
2.13.2
Re: [PATCH 3/4] libmultipath: only listen for uevents with DEVTYPE=disk
In reply to Martin WilckLooks fine.
Quoted 25 lines · Martin Wilck
We are only interested in disks anyway. This saves us checking for devtype in the uevent processing queue, and is more powerful than the previous test in the dropped function
uevent_can_discard_by_devpath().Signed-off-by Martin Wilck <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libmultipath/uevent.c +1
-1@@ -770,7 +770,7 @@ int uevent_listen(struct udev *udev) goto out; } err =udev_monitor_filter_add_match_subsystem_devtype (monitor,"block" , -NULL ); +"disk" );if (err)condlog (2 ,"failed to create filter : %s" ,strerror (-err)); err =udev_monitor_enable_receiving (monitor);
PATCH 4/4 libmultipath: fix over-long NVME WWIDs
In reply to Martin WilckFix for NVME wwids looking like this:
nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002 which are encountered in some combinations of Linux NVME host and target,
where the 2nd field represents the serial number (SN) and the 3rd the
model number (MN).
The device mapper allows map names only up to 128 characters. Strip the "00" sequences at the end of the serial and model field, they are hex-encoded 0-bytes which are forbidden by the NVME spec anyway.
--- libmultipath/discovery.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
libmultipath/discovery.c +79 -0
@@ -1598,6 +1598,82 @@ get_prio (struct path * pp)return 0 ; } +/* +* Mangle string of length *len starting at start +* by removing character sequence "00" (hex for a 0 byte), +* starting at end, backwards. +* Changes the value of *len if characters were removed. +* Returns a pointer to the position where "end" was moved to. +*/ +static char +*skip_zeroes_backward (char * start,int *len,char *end) +{ +char *p = end; + +while (p >= start +2 && *(p -1 ) =='0' && *(p -2 ) =='0' ) + p -=2 ; + +if (p == end) +return p; + +memmove (p, end, start + *len +1 - end); + *len -= end - p; + +return p; +} + +/* +* Fix for NVME wwids looking like this: +* nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002 +* which are encountered in some combinations of Linux NVME host and target. +* The '00' are hex-encoded 0-bytes which are forbidden in the serial (SN) +* and model (MN) fields. Discard them. +* If a WWID of the above type is found, sets pp->wwid and returns a value > 0. +* Otherwise, returns 0. +*/ +static int +fix_broken_nvme_wwid (struct path *pp,const char *value,int size) +{ +static const char _nvme[] ="nvme." ; +int len, i; +char mangled[256 ]; +char *p; + + len =strlen (value); +if (len >=sizeof (mangled) || len +1 < size) +return 0 ; + +/* Check that value starts with "nvme.%04x-" */ +if (memcmp (value, _nvme,sizeof (_nvme) -1 ) || value[9 ] !='-' ) +return 0 ; +for (i =5 ; i <9 ; i++) +if (!isxdigit (value[i])) +return 0 ; + +memcpy (mangled, value, len +1 ); + +/* search end of "model" part and strip trailing '00' */ + p =memrchr (mangled,'-' , len); +if (p ==NULL ) +return 0 ; + + p =skip_zeroes_backward (mangled, &len, p); + +/* search end of "serial" part */ + p =memrchr (mangled,'-' , p - mangled); +if (p ==NULL ||memrchr (mangled,'-' , p - mangled) != mangled +9 ) +/* We expect exactly 3 '-' in the value */ +return 0 ; + + p =skip_zeroes_backward (mangled, &len, p); +if (len >= size) +return 0 ; + +memcpy (pp->wwid, mangled, len +1 ); +condlog (2 ,"%s: over-long WWID shortened to %s" , pp->dev, pp->wwid); +return len; +} +static int get_udev_uid (struct path * pp,char *uid_attribute,struct udev_device *udev) {
@@ -1609,6 +1685,9 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) value =getenv (uid_attribute);if (value &&strlen (value)) {if (strlen (value) +1 >WWID_SIZE ) { + len =fix_broken_nvme_wwid (pp, value,WWID_SIZE ); +if (len >0 ) +return len;condlog (0 ,"%s: wwid overflow" , pp->dev); len =WWID_SIZE ; }else {
Signature · 1 line
2.13.2
Benjamin Marzinski
maintainerRe: [PATCH 4/4] libmultipath: fix over-long NVME WWIDs
ACK, with one small nit below.
-Ben
Quoted 58 lines · Martin Wilck
Fix for NVME wwids looking like this:
nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002 which are encountered in some combinations of Linux NVME host and target,
where the 2nd field represents the serial number (SN) and the 3rd the
model number (MN).The device mapper allows map names only up to 128 characters. Strip the "00" sequences at the end of the serial and model field, they are hex-encoded 0-bytes which are forbidden by the NVME spec anyway.
Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)libmultipath/discovery.c +34
-0@@ -1598,6 +1598,82 @@ get_prio (struct path * pp)return 0 ; } +/* +* Mangle string of length *len starting at start +* by removing character sequence "00" (hex for a 0 byte), +* starting at end, backwards. +* Changes the value of *len if characters were removed. +* Returns a pointer to the position where "end" was moved to. +*/ +static char +*skip_zeroes_backward (char * start,int *len,char *end) +{ +char *p = end; + +while (p >= start +2 && *(p -1 ) =='0' && *(p -2 ) =='0' ) + p -=2 ; + +if (p == end) +return p; + +memmove (p, end, start + *len +1 - end); + *len -= end - p; + +return p; +} + +/* +* Fix for NVME wwids looking like this: +* nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002 +* which are encountered in some combinations of Linux NVME host and target. +* The '00' are hex-encoded 0-bytes which are forbidden in the serial (SN) +* and model (MN) fields. Discard them. +* If a WWID of the above type is found, sets pp->wwid and returns a value > 0. +* Otherwise, returns 0. +*/ +static int
libmultipath/discovery.c get_prio (struct path * pp) · line 1644
Quoted 10 lines
libmultipath/discovery.c +10
-0+fix_broken_nvme_wwid(struct path *pp, const char *value, int size) +{ + static const char _nvme[] = "nvme."; +int len, i; +char mangled[256 ]; +char *p; + + len =strlen (value); +if (len >=sizeof (mangled) || len +1 < size) +return 0 ;
Don't we check (len + 1 < size) before calling this? It seems odd to return that we can't do anything when in reality, we simply don't need to do anything.
-Ben
Quoted 47 lines
libmultipath/discovery.c +35
-0+ +/* Check that value starts with "nvme.%04x-" */ +if (memcmp (value, _nvme,sizeof (_nvme) -1 ) || value[9 ] !='-' ) +return 0 ; +for (i =5 ; i <9 ; i++) +if (!isxdigit (value[i])) +return 0 ; + +memcpy (mangled, value, len +1 ); + +/* search end of "model" part and strip trailing '00' */ + p =memrchr (mangled,'-' , len); +if (p ==NULL ) +return 0 ; + + p =skip_zeroes_backward (mangled, &len, p); + +/* search end of "serial" part */ + p =memrchr (mangled,'-' , p - mangled); +if (p ==NULL ||memrchr (mangled,'-' , p - mangled) != mangled +9 ) +/* We expect exactly 3 '-' in the value */ +return 0 ; + + p =skip_zeroes_backward (mangled, &len, p); +if (len >= size) +return 0 ; + +memcpy (pp->wwid, mangled, len +1 ); +condlog (2 ,"%s: over-long WWID shortened to %s" , pp->dev, pp->wwid); +return len; +} +static int get_udev_uid (struct path * pp,char *uid_attribute,struct udev_device *udev) {@@ -1609,6 +1685,9 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev) value =getenv (uid_attribute);if (value &&strlen (value)) {if (strlen (value) +1 >WWID_SIZE ) { + len =fix_broken_nvme_wwid (pp, value,WWID_SIZE ); +if (len >0 ) +return len;condlog (0 ,"%s: wwid overflow" , pp->dev); len =WWID_SIZE ; }else {Signature · 1 line
2.13.2
Re: [PATCH 4/4] libmultipath: fix over-long NVME WWIDs
In reply to Martin WilckHi, Martin:
Quoted 2 lines · Martin Wilck
Fix for NVME wwids looking like this:
nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002
I think the above line is too long and it's better to split it into two lines. Otherwise , this patch looks good for me.
Quoted 3 lines
which are encountered in some combinations of Linux NVME host and target, where the 2nd field represents the serial number (SN) and the 3rd the model number (MN).