* [PATCH 1/4] libmpathpersist: limit PRIN allocation length to 8192 bytes
2020-03-06 23:06 [PATCH 0/4] libmpathpersist allocation size fixes mwilck
@ 2020-03-06 23:06 ` mwilck
2020-03-14 23:14 ` Benjamin Marzinski
2020-03-06 23:06 ` [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow mwilck
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: mwilck @ 2020-03-06 23:06 UTC (permalink / raw)
To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck, David Bond
From: Martin Wilck <mwilck@suse.com>
Some targets (notably the qemu-pr-helper) don't support PERSISTENT
RESERVE IN commands with more than 8192 bytes allocation length.
While I have found no explicit requirement in the SCSI specs that
the allocation lengh may not exceed 8k, an 8k limit is also enforced
by sg_persist(8), and actually by mpathpersist itself for the
--allocation-length option, but not for the auto-determined length.
Fix that.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
libmpathpersist/mpath_pr_ioctl.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
index 74b26b0c..1a28cba7 100644
--- a/libmpathpersist/mpath_pr_ioctl.c
+++ b/libmpathpersist/mpath_pr_ioctl.c
@@ -543,5 +543,7 @@ int get_prin_length(int rq_servact)
mx_resp_len = 0;
break;
}
+ if (mx_resp_len > MPATH_MAX_PARAM_LEN)
+ mx_resp_len = MPATH_MAX_PARAM_LEN;
return mx_resp_len;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 1/4] libmpathpersist: limit PRIN allocation length to 8192 bytes
2020-03-06 23:06 ` [PATCH 1/4] libmpathpersist: limit PRIN allocation length to 8192 bytes mwilck
@ 2020-03-14 23:14 ` Benjamin Marzinski
0 siblings, 0 replies; 12+ messages in thread
From: Benjamin Marzinski @ 2020-03-14 23:14 UTC (permalink / raw)
To: mwilck; +Cc: dm-devel, David Bond
On Sat, Mar 07, 2020 at 12:06:02AM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
>
> Some targets (notably the qemu-pr-helper) don't support PERSISTENT
> RESERVE IN commands with more than 8192 bytes allocation length.
> While I have found no explicit requirement in the SCSI specs that
> the allocation lengh may not exceed 8k, an 8k limit is also enforced
> by sg_persist(8), and actually by mpathpersist itself for the
> --allocation-length option, but not for the auto-determined length.
>
> Fix that.
>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
> libmpathpersist/mpath_pr_ioctl.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
> index 74b26b0c..1a28cba7 100644
> --- a/libmpathpersist/mpath_pr_ioctl.c
> +++ b/libmpathpersist/mpath_pr_ioctl.c
> @@ -543,5 +543,7 @@ int get_prin_length(int rq_servact)
> mx_resp_len = 0;
> break;
> }
> + if (mx_resp_len > MPATH_MAX_PARAM_LEN)
> + mx_resp_len = MPATH_MAX_PARAM_LEN;
> return mx_resp_len;
> }
> --
> 2.25.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow
2020-03-06 23:06 [PATCH 0/4] libmpathpersist allocation size fixes mwilck
2020-03-06 23:06 ` [PATCH 1/4] libmpathpersist: limit PRIN allocation length to 8192 bytes mwilck
@ 2020-03-06 23:06 ` mwilck
2020-03-14 23:15 ` Benjamin Marzinski
2020-03-06 23:06 ` [PATCH 3/4] libmpathpersist: mpath_format_readfullstatus(): use real buffer size mwilck
2020-03-06 23:06 ` [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes mwilck
3 siblings, 1 reply; 12+ messages in thread
From: mwilck @ 2020-03-06 23:06 UTC (permalink / raw)
To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck, David Bond
From: Martin Wilck <mwilck@suse.com>
This limits the PERSISTENT RESERVE OUT data size to max. 8192 bytes.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
libmpathpersist/mpath_pr_ioctl.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
index 1a28cba7..8bf16c0d 100644
--- a/libmpathpersist/mpath_pr_ioctl.c
+++ b/libmpathpersist/mpath_pr_ioctl.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -138,38 +139,59 @@ retry :
return status;
}
+#define check_overflow(ofs, n, start, label) \
+ do { \
+ if ((ofs) + 4 + (n) + \
+ offsetof(struct prout_param_descriptor, private_buffer) \
+ > MPATH_MAX_PARAM_LEN) \
+ { \
+ (ofs) = (start); \
+ goto label; \
+ } \
+ } while(0)
+
uint32_t format_transportids(struct prout_param_descriptor *paramp)
{
unsigned int i = 0, len;
uint32_t buff_offset = 4;
- memset(paramp->private_buffer, 0, MPATH_MAX_PARAM_LEN);
+ memset(paramp->private_buffer, 0, sizeof(paramp->private_buffer));
for (i=0; i < paramp->num_transportid; i++ )
{
+ uint32_t start_offset = buff_offset;
+
+ check_overflow(buff_offset, 1, start_offset, end_loop);
paramp->private_buffer[buff_offset] = (uint8_t)((paramp->trnptid_list[i]->format_code & 0xff)|
(paramp->trnptid_list[i]->protocol_id & 0xff));
buff_offset += 1;
switch(paramp->trnptid_list[i]->protocol_id)
{
case MPATH_PROTOCOL_ID_FC:
+ check_overflow(buff_offset, 7 + 8 + 8,
+ start_offset, end_loop);
buff_offset += 7;
memcpy(¶mp->private_buffer[buff_offset], ¶mp->trnptid_list[i]->n_port_name, 8);
buff_offset +=8 ;
buff_offset +=8 ;
break;
case MPATH_PROTOCOL_ID_SAS:
+ check_overflow(buff_offset, 3 + 12,
+ start_offset, end_loop);
buff_offset += 3;
memcpy(¶mp->private_buffer[buff_offset], ¶mp->trnptid_list[i]->sas_address, 8);
buff_offset += 12;
break;
case MPATH_PROTOCOL_ID_ISCSI:
- buff_offset += 1;
len = (paramp->trnptid_list[i]->iscsi_name[1] & 0xff)+2;
+ check_overflow(buff_offset, 1 + len,
+ start_offset, end_loop);
+ buff_offset += 1;
memcpy(¶mp->private_buffer[buff_offset], ¶mp->trnptid_list[i]->iscsi_name,len);
buff_offset += len ;
break;
}
}
+end_loop:
buff_offset -= 4;
paramp->private_buffer[0] = (unsigned char)((buff_offset >> 24) & 0xff);
paramp->private_buffer[1] = (unsigned char)((buff_offset >> 16) & 0xff);
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow
2020-03-06 23:06 ` [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow mwilck
@ 2020-03-14 23:15 ` Benjamin Marzinski
2020-03-15 0:14 ` Martin Wilck
0 siblings, 1 reply; 12+ messages in thread
From: Benjamin Marzinski @ 2020-03-14 23:15 UTC (permalink / raw)
To: mwilck; +Cc: dm-devel, David Bond
On Sat, Mar 07, 2020 at 12:06:03AM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
>
> This limits the PERSISTENT RESERVE OUT data size to max. 8192 bytes.
>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
> libmpathpersist/mpath_pr_ioctl.c | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
> index 1a28cba7..8bf16c0d 100644
> --- a/libmpathpersist/mpath_pr_ioctl.c
> +++ b/libmpathpersist/mpath_pr_ioctl.c
> @@ -1,5 +1,6 @@
> #include <stdio.h>
> #include <stdlib.h>
> +#include <stddef.h>
>
> #include <sys/types.h>
> #include <sys/stat.h>
> @@ -138,38 +139,59 @@ retry :
> return status;
> }
>
> +#define check_overflow(ofs, n, start, label) \
> + do { \
> + if ((ofs) + 4 + (n) + \
I don't get where the 4 comes from here, since buff_offset starts
at 4. Maybe I'm just missing something.
-Ben
> + offsetof(struct prout_param_descriptor, private_buffer) \
> + > MPATH_MAX_PARAM_LEN) \
> + { \
> + (ofs) = (start); \
> + goto label; \
> + } \
> + } while(0)
> +
> uint32_t format_transportids(struct prout_param_descriptor *paramp)
> {
> unsigned int i = 0, len;
> uint32_t buff_offset = 4;
> - memset(paramp->private_buffer, 0, MPATH_MAX_PARAM_LEN);
> + memset(paramp->private_buffer, 0, sizeof(paramp->private_buffer));
> for (i=0; i < paramp->num_transportid; i++ )
> {
> + uint32_t start_offset = buff_offset;
> +
> + check_overflow(buff_offset, 1, start_offset, end_loop);
> paramp->private_buffer[buff_offset] = (uint8_t)((paramp->trnptid_list[i]->format_code & 0xff)|
> (paramp->trnptid_list[i]->protocol_id & 0xff));
> buff_offset += 1;
> switch(paramp->trnptid_list[i]->protocol_id)
> {
> case MPATH_PROTOCOL_ID_FC:
> + check_overflow(buff_offset, 7 + 8 + 8,
> + start_offset, end_loop);
> buff_offset += 7;
> memcpy(¶mp->private_buffer[buff_offset], ¶mp->trnptid_list[i]->n_port_name, 8);
> buff_offset +=8 ;
> buff_offset +=8 ;
> break;
> case MPATH_PROTOCOL_ID_SAS:
> + check_overflow(buff_offset, 3 + 12,
> + start_offset, end_loop);
> buff_offset += 3;
> memcpy(¶mp->private_buffer[buff_offset], ¶mp->trnptid_list[i]->sas_address, 8);
> buff_offset += 12;
> break;
> case MPATH_PROTOCOL_ID_ISCSI:
> - buff_offset += 1;
> len = (paramp->trnptid_list[i]->iscsi_name[1] & 0xff)+2;
> + check_overflow(buff_offset, 1 + len,
> + start_offset, end_loop);
> + buff_offset += 1;
> memcpy(¶mp->private_buffer[buff_offset], ¶mp->trnptid_list[i]->iscsi_name,len);
> buff_offset += len ;
> break;
> }
>
> }
> +end_loop:
> buff_offset -= 4;
> paramp->private_buffer[0] = (unsigned char)((buff_offset >> 24) & 0xff);
> paramp->private_buffer[1] = (unsigned char)((buff_offset >> 16) & 0xff);
> --
> 2.25.1
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow
2020-03-14 23:15 ` Benjamin Marzinski
@ 2020-03-15 0:14 ` Martin Wilck
0 siblings, 0 replies; 12+ messages in thread
From: Martin Wilck @ 2020-03-15 0:14 UTC (permalink / raw)
To: Benjamin Marzinski; +Cc: dm-devel, David Bond
On Sat, 2020-03-14 at 18:15 -0500, Benjamin Marzinski wrote:
> On Sat, Mar 07, 2020 at 12:06:03AM +0100, mwilck@suse.com wrote:
> > From: Martin Wilck <mwilck@suse.com>
> >
> > This limits the PERSISTENT RESERVE OUT data size to max. 8192
> > bytes.
> >
> > Signed-off-by: Martin Wilck <mwilck@suse.com>
> > ---
> > libmpathpersist/mpath_pr_ioctl.c | 26 ++++++++++++++++++++++++--
> > 1 file changed, 24 insertions(+), 2 deletions(-)
> >
> > diff --git a/libmpathpersist/mpath_pr_ioctl.c
> > b/libmpathpersist/mpath_pr_ioctl.c
> > index 1a28cba7..8bf16c0d 100644
> > --- a/libmpathpersist/mpath_pr_ioctl.c
> > +++ b/libmpathpersist/mpath_pr_ioctl.c
> > @@ -1,5 +1,6 @@
> > #include <stdio.h>
> > #include <stdlib.h>
> > +#include <stddef.h>
> >
> > #include <sys/types.h>
> > #include <sys/stat.h>
> > @@ -138,38 +139,59 @@ retry :
> > return status;
> > }
> >
> > +#define check_overflow(ofs, n, start, label)
> > \
> > + do {
> > \
> > + if ((ofs) + 4 + (n) +
> > \
>
> I don't get where the 4 comes from here, since buff_offset starts
> at 4. Maybe I'm just missing something.
>
No. It's wrong, buff_offset includes these 4 bytes inded. Thanks for
spotting it. I'll resubmit the series.
Regards,
Martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/4] libmpathpersist: mpath_format_readfullstatus(): use real buffer size
2020-03-06 23:06 [PATCH 0/4] libmpathpersist allocation size fixes mwilck
2020-03-06 23:06 ` [PATCH 1/4] libmpathpersist: limit PRIN allocation length to 8192 bytes mwilck
2020-03-06 23:06 ` [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow mwilck
@ 2020-03-06 23:06 ` mwilck
2020-03-14 23:16 ` Benjamin Marzinski
2020-03-06 23:06 ` [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes mwilck
3 siblings, 1 reply; 12+ messages in thread
From: mwilck @ 2020-03-06 23:06 UTC (permalink / raw)
To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck, David Bond
From: Martin Wilck <mwilck@suse.com>
This changes no semantics, but it will allow changing the size of
prin_readfd.private_buffer in a follow-up patch.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
libmpathpersist/mpath_pr_ioctl.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
index 8bf16c0d..8d8ca76f 100644
--- a/libmpathpersist/mpath_pr_ioctl.c
+++ b/libmpathpersist/mpath_pr_ioctl.c
@@ -233,6 +233,8 @@ static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
uint32_t additional_length, k, tid_len_len = 0;
char tempbuff[MPATH_MAX_PARAM_LEN];
struct prin_fulldescr fdesc;
+ static const int pbuf_size =
+ sizeof(pr_buff->prin_descriptor.prin_readfd.private_buffer);
convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readfd.prgeneration);
convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readfd.number_of_descriptor);
@@ -244,16 +246,18 @@ static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
}
additional_length = pr_buff->prin_descriptor.prin_readfd.number_of_descriptor;
- if (additional_length > MPATH_MAX_PARAM_LEN) {
+ if (additional_length > pbuf_size) {
condlog(3, "PRIN length %u exceeds max length %d", additional_length,
- MPATH_MAX_PARAM_LEN);
+ pbuf_size);
return;
}
memset(&fdesc, 0, sizeof(struct prin_fulldescr));
- memcpy( tempbuff, pr_buff->prin_descriptor.prin_readfd.private_buffer,MPATH_MAX_PARAM_LEN );
- memset(&pr_buff->prin_descriptor.prin_readfd.private_buffer, 0, MPATH_MAX_PARAM_LEN);
+ memcpy( tempbuff, pr_buff->prin_descriptor.prin_readfd.private_buffer,
+ pbuf_size);
+ memset(&pr_buff->prin_descriptor.prin_readfd.private_buffer, 0,
+ pbuf_size);
p =(unsigned char *)tempbuff;
ppbuff = (char *)pr_buff->prin_descriptor.prin_readfd.private_buffer;
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 3/4] libmpathpersist: mpath_format_readfullstatus(): use real buffer size
2020-03-06 23:06 ` [PATCH 3/4] libmpathpersist: mpath_format_readfullstatus(): use real buffer size mwilck
@ 2020-03-14 23:16 ` Benjamin Marzinski
0 siblings, 0 replies; 12+ messages in thread
From: Benjamin Marzinski @ 2020-03-14 23:16 UTC (permalink / raw)
To: mwilck; +Cc: dm-devel, David Bond
On Sat, Mar 07, 2020 at 12:06:04AM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
>
> This changes no semantics, but it will allow changing the size of
> prin_readfd.private_buffer in a follow-up patch.
>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
> libmpathpersist/mpath_pr_ioctl.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
> index 8bf16c0d..8d8ca76f 100644
> --- a/libmpathpersist/mpath_pr_ioctl.c
> +++ b/libmpathpersist/mpath_pr_ioctl.c
> @@ -233,6 +233,8 @@ static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
> uint32_t additional_length, k, tid_len_len = 0;
> char tempbuff[MPATH_MAX_PARAM_LEN];
> struct prin_fulldescr fdesc;
> + static const int pbuf_size =
> + sizeof(pr_buff->prin_descriptor.prin_readfd.private_buffer);
>
> convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readfd.prgeneration);
> convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readfd.number_of_descriptor);
> @@ -244,16 +246,18 @@ static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
> }
>
> additional_length = pr_buff->prin_descriptor.prin_readfd.number_of_descriptor;
> - if (additional_length > MPATH_MAX_PARAM_LEN) {
> + if (additional_length > pbuf_size) {
> condlog(3, "PRIN length %u exceeds max length %d", additional_length,
> - MPATH_MAX_PARAM_LEN);
> + pbuf_size);
> return;
> }
>
> memset(&fdesc, 0, sizeof(struct prin_fulldescr));
>
> - memcpy( tempbuff, pr_buff->prin_descriptor.prin_readfd.private_buffer,MPATH_MAX_PARAM_LEN );
> - memset(&pr_buff->prin_descriptor.prin_readfd.private_buffer, 0, MPATH_MAX_PARAM_LEN);
> + memcpy( tempbuff, pr_buff->prin_descriptor.prin_readfd.private_buffer,
> + pbuf_size);
> + memset(&pr_buff->prin_descriptor.prin_readfd.private_buffer, 0,
> + pbuf_size);
>
> p =(unsigned char *)tempbuff;
> ppbuff = (char *)pr_buff->prin_descriptor.prin_readfd.private_buffer;
> --
> 2.25.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes
2020-03-06 23:06 [PATCH 0/4] libmpathpersist allocation size fixes mwilck
` (2 preceding siblings ...)
2020-03-06 23:06 ` [PATCH 3/4] libmpathpersist: mpath_format_readfullstatus(): use real buffer size mwilck
@ 2020-03-06 23:06 ` mwilck
2020-03-15 0:19 ` Benjamin Marzinski
3 siblings, 1 reply; 12+ messages in thread
From: mwilck @ 2020-03-06 23:06 UTC (permalink / raw)
To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck, David Bond
From: Martin Wilck <mwilck@suse.com>
Make sure that data structures used for PERSISTENT RESERVE IN/OUT
fit into 8k buffers.
This patch breaks the libmpathpersist ABI.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
libmpathpersist/mpath_persist.h | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/libmpathpersist/mpath_persist.h b/libmpathpersist/mpath_persist.h
index 7cf4faf9..bdf4069d 100644
--- a/libmpathpersist/mpath_persist.h
+++ b/libmpathpersist/mpath_persist.h
@@ -92,7 +92,7 @@ struct prin_readdescr
uint32_t prgeneration;
uint32_t additional_length; /* The value should be either 0 or divisible by 8.
0 indicates no registered reservation key. */
- uint8_t key_list[MPATH_MAX_PARAM_LEN];
+ uint8_t key_list[MPATH_MAX_PARAM_LEN - 2 * sizeof(uint32_t)];
};
struct prin_resvdescr
@@ -141,7 +141,9 @@ struct print_fulldescr_list
{
uint32_t prgeneration;
uint32_t number_of_descriptor;
- uint8_t private_buffer[MPATH_MAX_PARAM_LEN]; /*Private buffer for list storage*/
+ /* Data-in; Private buffer for list storage */
+ uint8_t private_buffer[MPATH_MAX_PARAM_LEN - 2 * sizeof(uint32_t)];
+ /* array of pointers into private_buffer */
struct prin_fulldescr *descriptors[];
};
@@ -163,8 +165,13 @@ struct prout_param_descriptor { /* PROUT parameter descriptor */
uint8_t sa_flags;
uint8_t _reserved;
uint16_t _obsolete1;
- uint8_t private_buffer[MPATH_MAX_PARAM_LEN]; /*private buffer for list storage*/
- uint32_t num_transportid; /* Number of Transport ID listed in trnptid_list[]*/
+ /*private buffer for list storage; data-out */
+ /* 24: offsetof (struct prout_param_descriptor, private_buffer) */
+ uint8_t private_buffer[MPATH_MAX_PARAM_LEN - 24];
+ /* Internal use below here */
+ /* Number of Transport ID listed in trnptid_list[] */
+ uint32_t num_transportid;
+ /* pointers into private_buffer */
struct transportid *trnptid_list[];
};
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes
2020-03-06 23:06 ` [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes mwilck
@ 2020-03-15 0:19 ` Benjamin Marzinski
2020-03-15 0:27 ` Martin Wilck
0 siblings, 1 reply; 12+ messages in thread
From: Benjamin Marzinski @ 2020-03-15 0:19 UTC (permalink / raw)
To: mwilck; +Cc: dm-devel, David Bond
On Sat, Mar 07, 2020 at 12:06:05AM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
>
> Make sure that data structures used for PERSISTENT RESERVE IN/OUT
> fit into 8k buffers.
>
> This patch breaks the libmpathpersist ABI.
>
I'm not super worried about this. I don't really see a way for users to
hurt themselves because of this change, without making some pretty odd
assumptions. Am I missing something?
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
> libmpathpersist/mpath_persist.h | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/libmpathpersist/mpath_persist.h b/libmpathpersist/mpath_persist.h
> index 7cf4faf9..bdf4069d 100644
> --- a/libmpathpersist/mpath_persist.h
> +++ b/libmpathpersist/mpath_persist.h
> @@ -92,7 +92,7 @@ struct prin_readdescr
> uint32_t prgeneration;
> uint32_t additional_length; /* The value should be either 0 or divisible by 8.
> 0 indicates no registered reservation key. */
> - uint8_t key_list[MPATH_MAX_PARAM_LEN];
> + uint8_t key_list[MPATH_MAX_PARAM_LEN - 2 * sizeof(uint32_t)];
> };
>
> struct prin_resvdescr
> @@ -141,7 +141,9 @@ struct print_fulldescr_list
> {
> uint32_t prgeneration;
> uint32_t number_of_descriptor;
> - uint8_t private_buffer[MPATH_MAX_PARAM_LEN]; /*Private buffer for list storage*/
> + /* Data-in; Private buffer for list storage */
> + uint8_t private_buffer[MPATH_MAX_PARAM_LEN - 2 * sizeof(uint32_t)];
> + /* array of pointers into private_buffer */
> struct prin_fulldescr *descriptors[];
> };
>
> @@ -163,8 +165,13 @@ struct prout_param_descriptor { /* PROUT parameter descriptor */
> uint8_t sa_flags;
> uint8_t _reserved;
> uint16_t _obsolete1;
> - uint8_t private_buffer[MPATH_MAX_PARAM_LEN]; /*private buffer for list storage*/
> - uint32_t num_transportid; /* Number of Transport ID listed in trnptid_list[]*/
> + /*private buffer for list storage; data-out */
> + /* 24: offsetof (struct prout_param_descriptor, private_buffer) */
> + uint8_t private_buffer[MPATH_MAX_PARAM_LEN - 24];
> + /* Internal use below here */
> + /* Number of Transport ID listed in trnptid_list[] */
> + uint32_t num_transportid;
> + /* pointers into private_buffer */
> struct transportid *trnptid_list[];
> };
>
> --
> 2.25.1
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes
2020-03-15 0:19 ` Benjamin Marzinski
@ 2020-03-15 0:27 ` Martin Wilck
2020-03-15 20:45 ` Martin Wilck
0 siblings, 1 reply; 12+ messages in thread
From: Martin Wilck @ 2020-03-15 0:27 UTC (permalink / raw)
To: Benjamin Marzinski; +Cc: dm-devel, David Bond
On Sat, 2020-03-14 at 19:19 -0500, Benjamin Marzinski wrote:
> On Sat, Mar 07, 2020 at 12:06:05AM +0100, mwilck@suse.com wrote:
> > From: Martin Wilck <mwilck@suse.com>
> >
> > Make sure that data structures used for PERSISTENT RESERVE IN/OUT
> > fit into 8k buffers.
> >
> > This patch breaks the libmpathpersist ABI.
> >
>
> I'm not super worried about this. I don't really see a way for users
> to
> hurt themselves because of this change, without making some pretty
> odd
> assumptions. Am I missing something?
I found this:
struct prout_param_descriptor {
uint8_t key[8];
uint8_t sa_key[8];
[...]
uint8_t private_buffer[MPATH_MAX_PARAM_LEN - 24];
uint32_t num_transportid;
struct transportid *trnptid_list[];
};
A program written against the old API might assume that the length of
private_buffer was MPATH_MAX_PARAM_LEN, and call e.g.
memset(private_buffer, 0, MPATH_MAX_PARAM_LEN), overwriting
num_transportid.
The same could happen if a program compiled against the new API was
linked against the old. In that case, the overwrite would happen in
format_transportids().
Martin
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 4/4] libmpathpersist: ABI change: limit data-in/out size to 8192 bytes
2020-03-15 0:27 ` Martin Wilck
@ 2020-03-15 20:45 ` Martin Wilck
0 siblings, 0 replies; 12+ messages in thread
From: Martin Wilck @ 2020-03-15 20:45 UTC (permalink / raw)
To: Benjamin Marzinski; +Cc: dm-devel, David Bond
On Sun, 2020-03-15 at 01:27 +0100, Martin Wilck wrote:
>
> A program written against the old API might assume that the length of
> private_buffer was MPATH_MAX_PARAM_LEN, and call e.g.
> memset(private_buffer, 0, MPATH_MAX_PARAM_LEN), overwriting
> num_transportid.
And programs compiled against old headers would obviously use the
wrong offsets for num_transportids and trnptid_list.
Similar for struct print_fulldescr_list.descriptors.
So I this does indeed break the ABI. Perhaps we shouldn't apply this
without implementing clean so numbering.
Regards
Martin
^ permalink raw reply [flat|nested] 12+ messages in thread