Re: [PATCH v2 1/2] scs: switch to vmapped shadow stacks

From: Sami Tolvanen
Date: Mon Nov 30 2020 - 15:04:17 EST


On Mon, Nov 30, 2020 at 3:44 AM Will Deacon <will@xxxxxxxxxx> wrote:
>
> On Tue, Nov 24, 2020 at 11:59:39AM -0800, Sami Tolvanen wrote:
> > +void *scs_alloc(int node)
> > {
> > - void *s = kmem_cache_alloc_node(scs_cache, GFP_SCS, node);
> > + int i;
> > + void *s;
> > +
> > + for (i = 0; i < NR_CACHED_SCS; i++) {
> > + s = this_cpu_xchg(scs_cache[i], NULL);
> > + if (s) {
> > + kasan_unpoison_vmalloc(s, SCS_SIZE);
> > + memset(s, 0, SCS_SIZE);
> > + goto out;
> > + }
> > + }
> > +
> > + s = __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END,
> > + GFP_SCS, PAGE_KERNEL, 0, node,
> > + __builtin_return_address(0));
> >
> > if (!s)
> > return NULL;
>
> Sorry I didn't spot this before, but if you put the xchg/vmalloc code
> into a new __scs_alloc() function then you can drop the label and this
> becomes:
>
> s = __scs_alloc(...);
> if (!s)
> return NULL;
>
> *__scs_maghic(s) = SCS_ENG_MAGIC;
> ...

Good point, I'll change this in v3.

Sami