[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC 1/5] xen/arm64: livepatch: enable attaching callbacks


  • To: Ryo Takakura <takakura@xxxxxxxxxxxxx>
  • From: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
  • Date: Sat, 24 Oct 2026 14:48:05 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+6wJ5dhBAOBZQ2mx4yeO1L485WwM/LUvOP+swld0xVY=; b=wovNfzh+sjuVKQFyT4SYefoVAuEwmgqwGE5BL8VPPFmx3T/WVUqbYURm3yygsHu4tV39TD1Z8zp7PejGPiIkTI1w92i3J/hdVBrtLfmBjCTGx8gV/k2UcW9M2h0qgGZPrt8/6xlUArYGwO6yPjzXWMLm7WUbwUpI7CzvtFuAVIVFBCeVtOGSRzDRZ3qvLuUWThd7pzqKftkdVktfeVjW21neMBmIg8dJq+ZMd9VCR/rFT9A0DfoKl8RTSsfsPdAqSuX2xDd/ZktWNisFGXIvZZqHXj2R0Dn9zF8FGE8fjzHEUNi7MOQwLfoV/boiScorS2lmG9q/ckGAheYXMrqVZg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wqhawciZI3ZsvoDJBmqQ6Eec2uSI6x/1q0rPivZWkyCNXIJlcAPf9+LZ8xwI5dWJ/71E85QQdtZT+tiUGcN/8T1FGeQhN5kAsp5tV3+amE880K34hDjMN5+Y2ONWxqctTdOzt5notmquXVagfzfnSeHyQtHupTqkJs/iAMGrlf8WXCmWQKaOeVExOh0/uR64p3PT7VbNREMBtRfyznAgadoN/xWQdLHZ2vNw5tR6vXSHNHAWQAJOPpyTufAtSCEQ4k2NC9vJWoIc+OJm3k1ZiZ48Zp2+Ix3xYzTScynCsNqxzwkFgOdCNqtanyuq5zDEnxo9QDm1VFkq6HigzlQLkQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, sstabellini@xxxxxxxxxx, julien@xxxxxxx, bertrand.marquis@xxxxxxx, michal.orzel@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, roger@xxxxxxxxxxxxxx, ross.lagerwall@xxxxxxxxxx
  • Delivery-date: Sat, 24 Oct 2026 12:48:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Ryo,

Thanks for posting this RFC. Having dynamic function tracing in Xen
looks useful, and I'd like to help with reviews. I'm not yet deeply
familiar with this part of the code, so I've used LLM assistance to
help investigate it. I may have missed a check elsewhere;
could you help me confirm whether the following concerns apply?

--- a/xen/arch/arm/arm64/livepatch.c
+++ b/xen/arch/arm/arm64/livepatch.c
@@ -492,6 +496,36 @@
> +#ifdef CONFIG_ARM64_PATCHABLE_FUNCTION_ENTRY
> +void arch_livepatch_apply_trace(const struct livepatch_func *trace)
> +{
> +    uint32_t *new_ptr;
> +    uint32_t insns[2];
> +
> +    new_ptr = trace->old_addr - (void *)_start + vmap_of_xen_text;
> [...]
> +    memcpy(new_ptr, insns, sizeof(insns));

This copies eight bytes from the two-element instruction array, while
uploaded trace descriptors still use the ordinary Arm livepatch verifier?

For reference, the existing arch_livepatch_verify_func() in
xen/arch/arm/livepatch.c contains this size check (not added by this patch):

>     if ( func->old_size < ARCH_PATCH_INSN_SIZE )
>         return -EINVAL;
>
>     return 0;

With ARCH_PATCH_INSN_SIZE equal to four bytes, doesn't this accept a
four-byte function without establishing that two reserved tracing NOPs
are present? Is there another check on this path that I have overlooked?

Could an assembly entry or another uninstrumented function consequently
have executable instructions overwritten? If reverting then installs
two NOPs, could that lose the original instructions rather than restore
them?

Would it make sense to validate the complete reserved tracing entry,
including the actual branch destination and any conflicting livepatch,
before allowing the write? Could the expected entry also be checked at
application time, so that a modification after upload is not missed?

Separately, could a callback or one of its helpers call the traced
function again before the first callback returns?

> +  ASSERT(f->new_addr);
> +  ((livepatch_trace_func_t)f->new_addr)((unsigned long)f->old_addr, 
> parent_ip);

What would contain a recursion before Xen runs out of stack? Would a
guard covering the pre-callback dispatcher work as well as the callback
itself help, or is there an existing restriction on callback targets
that would rule this out?

I think marking the dispatcher itself non-patchable does not protect
its callees or the callback's callees, so they should be protected too?

Thanks for taking a look, and apologies if I have missed an existing
safeguard.

cu, Bernhard

-- 
Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.