public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <jejb@linux.ibm.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Kashyap Desai <kashyap.desai@broadcom.com>,
	Sumit Saxena <sumit.saxena@broadcom.com>,
	Shivasharan S <shivasharan.srikanteshwara@broadcom.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH] scsi: megaraid_sas: Use array_size() helper
Date: Mon, 15 Jun 2020 16:27:53 -0700	[thread overview]
Message-ID: <1592263673.7698.5.camel@linux.ibm.com> (raw)
In-Reply-To: <20200615214718.GA6970@embeddedor>

On Mon, 2020-06-15 at 16:47 -0500, Gustavo A. R. Silva wrote:
> The get_order() function has no 2-factor argument form, so
> multiplication
> factors need to be wrapped in array_size().
> 
> This issue was found with the help of Coccinelle and, audited and
> fixed
> manually.
> 
> Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index 319f241da4b6..6de44ed4cde7 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -5180,8 +5180,8 @@ megasas_alloc_fusion_context(struct
> megasas_instance *instance)
>  
>  	fusion = instance->ctrl_context;
>  
> -	fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT
> *
> -					      sizeof(LD_SPAN_INFO));
> +	fusion->log_to_span_pages =
> get_order(array_size(MAX_LOGICAL_DRIVES_EXT,
> +					      sizeof(LD_SPAN_INFO)))
> ;

What's the point of this?  You're replacing a constant multiplication
the compiler can compute with one it can't on the theory there might be
an overflow, which is pretty far fetched given MAX_LOGICAL_DRIVES_EXT
is 256 and sizeof(LD_SPAN_INFO) is around 82.

I thought the whole point of overflow detection was to use it for
instances where we could be tricked into triggering one by userspace
which may result in a buffer under or overflow ... this is two
constants, how could this ever be a source of an exploit?

James


      reply	other threads:[~2020-06-15 23:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 21:47 [PATCH] scsi: megaraid_sas: Use array_size() helper Gustavo A. R. Silva
2020-06-15 23:27 ` James Bottomley [this message]

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=1592263673.7698.5.camel@linux.ibm.com \
    --to=jejb@linux.ibm.com \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=kashyap.desai@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=megaraidlinux.pdl@broadcom.com \
    --cc=shivasharan.srikanteshwara@broadcom.com \
    --cc=sumit.saxena@broadcom.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox