From: Benjamin Marzinski <bmarzins@redhat.com>
To: mwilck@suse.com
Cc: dm-devel@redhat.com, David Bond <dbond@suse.com>
Subject: Re: [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow
Date: Sat, 14 Mar 2020 18:15:39 -0500 [thread overview]
Message-ID: <20200314231539.GS30153@octiron.msp.redhat.com> (raw)
In-Reply-To: <20200306230605.3473-3-mwilck@suse.com>
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
next prev parent reply other threads:[~2020-03-14 23:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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-14 23:14 ` Benjamin Marzinski
2020-03-06 23:06 ` [PATCH 2/4] libmpathpersist: format_transportids(): avoid PROUT overflow mwilck
2020-03-14 23:15 ` Benjamin Marzinski [this message]
2020-03-15 0:14 ` Martin Wilck
2020-03-06 23:06 ` [PATCH 3/4] libmpathpersist: mpath_format_readfullstatus(): use real buffer size 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
2020-03-15 0:19 ` Benjamin Marzinski
2020-03-15 0:27 ` Martin Wilck
2020-03-15 20:45 ` Martin Wilck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200314231539.GS30153@octiron.msp.redhat.com \
--to=bmarzins@redhat.com \
--cc=dbond@suse.com \
--cc=dm-devel@redhat.com \
--cc=mwilck@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.