mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>,
	kernel-janitors@vger.kernel.org, keescook@chromium.org,
	christophe.jaillet@wanadoo.fr, kuba@kernel.org,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 21/24] x86/sgx: use vmalloc_array and vcalloc
Date: Tue, 27 Jun 2023 17:01:35 +0200 (CEST)	[thread overview]
Message-ID: <896979d6-7365-e75-52fe-ad929e3e8620@inria.fr> (raw)
In-Reply-To: <004bc553-4dca-070b-c203-adcb50d4112d@intel.com>



On Tue, 27 Jun 2023, Dave Hansen wrote:

> On 6/27/23 07:43, Julia Lawall wrote:
> > Use vmalloc_array and vcalloc to protect against
> > multiplication overflows.
> ...
> > diff -u -p a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> > --- a/arch/x86/kernel/cpu/sgx/main.c
> > +++ b/arch/x86/kernel/cpu/sgx/main.c
> > @@ -628,7 +628,7 @@ static bool __init sgx_setup_epc_section
> >  	if (!section->virt_addr)
> >  		return false;
> >
> > -	section->pages = vmalloc(nr_pages * sizeof(struct sgx_epc_page));
> > +	section->pages = vmalloc_array(nr_pages, sizeof(struct sgx_epc_page));
> >  	if (!section->pages) {
>
> I'm not sure that changelog matches the code.
>
> 'nr_pages' here is an 'unsigned long' and The sizeof()==32.  In
> practice, the multiplication can be done with a shift, and the ulong is
> a *LONG* way from overflowing.
>
> I'll accept that, as a general rule, vmalloc_array() is the preferred
> form.  It's totally possible that someone could copy and paste the
> nr_foo*sizeof(struct bar) code over to a place where nr_foo is a more
> troublesome type.
>
> But, if that's the true motivation, could we please say that in the
> changelog?  As it stands, it's a bit silly to be talking about
> multiplication overflows, unless I'm missing something totally obvious.

If it is certain that no overflow is possible, then perhaps it is fine to
drop the patch?  I didn't change cases where both arguments are constants
nor where the result of the sizeof is 1.  But I also didn't do a careful
analysis to see if an overflow is possible given the possible values
involved.

Or if it seems better to keep the change, I can also change the log
message.

julia

  reply	other threads:[~2023-06-27 15:01 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 14:43 [PATCH v2 00/24] " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 01/24] lib/test_vmalloc.c: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 02/24] octeon_ep: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 03/24] drm/gud: " Julia Lawall
2023-07-03 12:23   ` Thomas Zimmermann
2023-07-04 10:41   ` Noralf Trønnes
2023-06-27 14:43 ` [PATCH v2 04/24] gve: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 05/24] RDMA/erdma: " Julia Lawall
2023-07-21 18:56   ` Jason Gunthorpe
2023-06-27 14:43 ` [PATCH v2 06/24] dma-buf: system_heap: " Julia Lawall
2023-06-27 18:52   ` John Stultz
2023-06-27 14:43 ` [PATCH v2 07/24] scsi: fnic: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 08/24] virtio-mem: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 09/24] pds_core: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 10/24] bus: mhi: host: " Julia Lawall
2023-06-27 14:48   ` Jeffrey Hugo
2023-07-12 16:48   ` Manivannan Sadhasivam
2023-06-27 14:43 ` [PATCH v2 11/24] ionic: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 12/24] btrfs: zoned: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 13/24] iommu/tegra: gart: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 14/24] RDMA/siw: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 15/24] habanalabs: " Julia Lawall
2023-07-02  8:01   ` Oded Gabbay
2023-06-27 14:43 ` [PATCH v2 16/24] drm/i915/gvt: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 17/24] kcov: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 18/24] net: enetc: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 19/24] RDMA/bnxt_re: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 20/24] comedi: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 21/24] x86/sgx: " Julia Lawall
2023-06-27 14:54   ` Dave Hansen
2023-06-27 15:01     ` Julia Lawall [this message]
2023-06-27 15:06       ` Dave Hansen
2023-06-27 14:43 ` [PATCH v2 22/24] net: mana: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 23/24] vduse: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 24/24] scsi: qla2xxx: " Julia Lawall
2023-06-27 16:40 ` [PATCH v2 00/24] " patchwork-bot+netdevbpf
2023-07-06  1:35 ` Martin K. Petersen
2023-07-11 16:31 ` (subset) " Martin K. Petersen

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=896979d6-7365-e75-52fe-ad929e3e8620@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=bp@alien8.de \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jarkko@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®