[PATCH 12/12] riscv/cfi: Support ucontext under CFI

Jesse Huang jesse.huang@sifive.com
Thu Jun 19 06:59:40 GMT 2025


On Thu, Jun 19, 2025 at 5:34 AM Deepak Gupta <debug@rivosinc.com> wrote:

> On Wed, Jun 18, 2025 at 01:42:58AM -0700, Jesse Huang wrote:
> >This patches only make the ucontext library work while CFI is enabled.
> >enabled. All security checks are skipped and should be implemented if
> >correspoding interface are landed into the kernel.
> >SSP is stored in the unused t3 slot in the sigcontext structure to avoid
>
> Question:
>
> Why can't we steal a 8 byte slot from `__glibc_reserved` under ucontext_t?


The __glibc_reserved field actually does not take any space

#define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))

typedef struct
{
  unsigned long int __val[_SIGSET_NWORDS];
} __sigset_t;

typedef struct ucontext_t
  {
    unsigned long int  __uc_flags;
    struct ucontext_t *uc_link;
    stack_t            uc_stack;
    sigset_t           uc_sigmask;
    /* There's some padding here to allow sigset_t to be expanded in the
       future.  Though this is unlikely, other architectures put uc_sigmask
       at the end of this structure and explicitly state it can be
       expanded, so we didn't want to box ourselves in here.  */
    char               __glibc_reserved[1024 / 8 - sizeof (sigset_t)];
    /* We can't put uc_sigmask at the end of this structure because we need
       to be able to expand sigcontext in the future.  For example, the
       vector ISA extension will almost certainly add ISA state.  We want
       to ensure all user-visible ISA state can be saved and restored via a
       ucontext, so we're putting this at the end in order to allow for
       infinite extensibility.  Since we know this will be extended and we
       assume sigset_t won't be extended an extreme amount, we're
       prioritizing this.  */
    mcontext_t uc_mcontext;
  } ucontext_t;

Where  `1024 / 8 - sizeof(sigset_t)` evaluates to 0, unless we shrink the
`_SIGSET_NWORDS`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250619/6f95f38e/attachment-0001.htm>


More information about the Libc-alpha mailing list