All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: HyeongJun An <sammiee5311@gmail.com>
Cc: andersson@kernel.org, linux-remoteproc@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] remoteproc: elf_loader: bound the section header table
Date: Wed, 19 Aug 2026 10:44:28 -0600	[thread overview]
Message-ID: <aoXdbENOmRRx2o6l@p14s> (raw)
In-Reply-To: <CAJciObG2OahhKz+t9pbA1yCHz4pFQLK6EKmZMwY2zxqD33SgQg@mail.gmail.com>

On Wed, Aug 19, 2026 at 09:15:27PM +0900, HyeongJun An wrote:
> Thanks for taking a look!
> 
> On Wed, Aug 19, 2026 at 1:42 AM Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> > On Thu, 23 Jul 2026 at 20:53, HyeongJun An <sammiee5311@gmail.com> wrote:
> > > +       /* find_table() reads the header at shstrndx even with no sections */
> >
> > Right, but if there is no sections, @shnum in find_tables is 0 and not
> > arm is done.
> 
> The loop is skipped, but there is one load before it:
> 
>   :266  name_table_shdr = shdr + (shstrndx * elf_shdr_get_size);
>   :268  name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr);
>   :270  for (i = 0; i < shnum; i++, shdr += elf_shdr_get_size) {
> 
> :268 reads sh_offset out of the header at index shstrndx, before shnum is
> tested at :270.  Both callers, :336 and :380, reach find_table() without
> checking shnum.  The value is unused when shnum is 0, so it is a 4 or 8
> byte read past the buffer and nothing worse.
> 
> > > +       shend = size_add(size_mul(elf_shdr_get_size, (size_t)shstrndx + 1), shoff);
> >
> > Why the shstrndx + 1?
> 
> To hold the header at index shstrndx the table needs shstrndx + 1 entries.

You are correct.

I would assume that if e_shnum is 0, then e_shstrndx would also be 0.  If it
isn't the case then your patch is valid.  I will queue it when rc1 comes out.

Thanks,
Mathieu

> It is keyed on shstrndx and not shnum because nothing here requires
> e_shstrndx < e_shnum.
> 
> > Also, there is no point in doing this check if @shnum is 0.  Please
> > move this block in the "if (shnum)".
> 
> The check it replaces, :95, sits outside any shnum test today, so moving
> it in loses what master already has.
> 
> If you want it inside, the way there is to drop the read:
> 
> if (!shnum)
> return NULL;
> 
> at the top of find_table().  The loop already falls through to return NULL
> at :313, so it changes nothing today, and the bound can then go inside
> "if (shnum)".
> 
> I am happy to do either.  Let me know which you would prefer for v2.
> 
> Thanks a lot!

  reply	other threads:[~2026-08-19 16:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  2:53 [PATCH] remoteproc: elf_loader: bound the section header table HyeongJun An
2026-08-18 16:42 ` Mathieu Poirier
2026-08-19 12:15   ` HyeongJun An
2026-08-19 16:44     ` Mathieu Poirier [this message]
2026-08-20  2:49       ` HyeongJun An

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=aoXdbENOmRRx2o6l@p14s \
    --to=mathieu.poirier@linaro.org \
    --cc=andersson@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=sammiee5311@gmail.com \
    --cc=stable@vger.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 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.