[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEWA0a4s+Uhm405CnvNsE61ed5_xJ8PUZqL74zfeZnivw1BChA@mail.gmail.com>
Date: Mon, 12 Jan 2026 14:18:18 -0800
From: Andrei Vagin <avagin@...gle.com>
To: Michal Koutný <mkoutny@...e.com>
Cc: Kees Cook <kees@...nel.org>, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org, criu@...ts.linux.dev,
Andrew Morton <akpm@...ux-foundation.org>, Chen Ridong <chenridong@...wei.com>,
Christian Brauner <brauner@...nel.org>, David Hildenbrand <david@...nel.org>,
Eric Biederman <ebiederm@...ssion.com>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Subject: Re: [PATCH 2/3] exec: inherit HWCAPs from the parent process
On Mon, Jan 12, 2026 at 4:46 AM Michal Koutný <mkoutny@...e.com> wrote:
>
> On Thu, Jan 08, 2026 at 05:07:47AM +0000, Andrei Vagin <avagin@...gle.com> wrote:
> > @@ -1780,6 +1791,50 @@ static int bprm_execve(struct linux_binprm *bprm)
> > return retval;
> > }
> >
> > +static void inherit_hwcap(struct linux_binprm *bprm)
> > +{
> > + int i, n;
> > +
> > +#ifdef ELF_HWCAP4
> > + n = 4;
> > +#elif defined(ELF_HWCAP3)
> > + n = 3;
> > +#elif defined(ELF_HWCAP2)
> > + n = 2;
> > +#else
> > + n = 1;
> > +#endif
>
> Is it guaranteed that HWCAP n+1 exists only when n does?
> (To make this work.)
>
It is true for all existing arch-es. I can't imagine why we would want to
define ELF_HWCAP{n+1} without having ELF_HWCAP{n}. If you think we need
to handle this case, I can address it in the next version.
It is just a small optimization to stop iterating after handling all
entries. The code will work correctly even when HWCAP n+1 exists but n
doesn't.
>
> > +
> > + for (i = 0; n && i < AT_VECTOR_SIZE; i += 2) {
> > + long val = current->mm->saved_auxv[i + 1];
> > +
> > + switch (current->mm->saved_auxv[i]) {
> > + case AT_HWCAP:
> > + bprm->hwcap = val & ELF_HWCAP;
> > + break;
> > +#ifdef ELF_HWCAP2
> > + case AT_HWCAP2:
> > + bprm->hwcap2 = val & ELF_HWCAP2;
> > + break;
> > +#endif
> > +#ifdef ELF_HWCAP3
> > + case AT_HWCAP3:
> > + bprm->hwcap3 = val & ELF_HWCAP3;
> > + break;
> > +#endif
> > +#ifdef ELF_HWCAP4
> > + case AT_HWCAP4:
> > + bprm->hwcap4 = val & ELF_HWCAP4;
> > + break;
> > +#endif
> > + default:
> > + continue;
> > + }
> > + n--;
> > + }
> > + mm_flags_set(MMF_USER_HWCAP, bprm->mm);
>
> Will this work when mm->saved_auxv isn't set by the prctl (it is
> zeroes?)?
The inherit_hwcap function is only called if MMF_USER_HWCAP is set (auxv was
modified via prctl). However, even if mm->saved_auxv hasn't been
modified, it still
contains valid values.
Thanks,
Andrei
ps: Please ignore the html version I mistakenly sent.
Powered by blists - more mailing lists