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

Re: [PATCH v1 1/1] arm64: Fix strrchr() matching of null terminator


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: "Edgar E. Iglesias" <edgar.iglesias@xxxxxxx>
  • Date: Tue, 19 May 2026 18:27:23 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.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=Uh31kvedVf7+zuAc3TPNvVcej9QrdanV4BG58oldh2c=; b=eO8louH3RP1cYYvDv80DzcYdebAKlrBCCwB2oM1VTarvT41TYaZmIVMYP4tH6qD/NJLlqXgw/qgdhNIJSjp6OUwvogXSVs68EIFA3fTI3K2cpc/jTK/SXBsf3Gz6FHHKRc3Ci+o3E8owE8Wt7yVzWEZDsyxHHrlTrvBNGqoThq7wVOF0Kvzr11/Zuel551oobBqiyIAsuG17qJYtL26yTTr+HCEgq9uDMQuhybaCBlgY22mnnOT2wkeaT7VEbJGFPrgyJu0XLhHsOBJ2DgSyqCg0xuTPZ4jYFJ/Z1bhqdQsXKhZAvCw/W6UHx5+wyeyJxFJopMSpD50wzELrU5f0jQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ahsaF9qUZE1yBBYgpPmg8NvHbx5flWTnj/QgdnmPtTibhXokUyjG3hwv7JKGYbeUPJrkAlpGbiGoe494bw0Dzyv4j4sJyQh3gAslfz3/SBWrKM/XPzbhOyhGX5ik0k144DcOW2BO4/mQ2iC3UBdyKiG2o+FndzQC0Yn5XGZIOVSgaqUpMGLZ8nUcJLqE0l4S48qeofWVs4K1wXr4k6OdOwiTKsTItkgIGBrUhSNLGw4HUrVmP9U8x9hpep2okdAnb4ds/vWoBxlI9igFMnwlzxxL5vECtthOlZa2VOT8x8CccHOknwkWUQ+Dv8SOv01H1TfcNSon1lgJF3o3BGWTMw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=fail header.s=selector1 header.d=amd.com header.i="@amd.com"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, sstabellini@xxxxxxxxxx, julien@xxxxxxx, bertrand.marquis@xxxxxxx, michal.orzel@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx
  • Delivery-date: Tue, 19 May 2026 16:27:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, May 19, 2026 at 01:45:37PM +0100, Andrew Cooper wrote:
> On 19/05/2026 12:43 am, Edgar E. Iglesias wrote:
> > The generic Xen strrchr() implementation returns a pointer to the string
> > terminator when searching for '\0', matching the standard C semantics.
> >
> > The ARM64 assembly version stopped as soon as it loaded the terminator and
> > returned the previous match pointer instead.  This made strrchr("", '\0')
> > return NULL.
> >
> > Compare the loaded byte against the requested character before deciding
> > whether to stop at the terminator, so the terminator itself can be returned
> > when it is the requested character.
> >
> > Fixes: 42c4eb6a83 ("xen: arm64: assembly optimised mem* and str*")
> > Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xxxxxxx>
> > ---
> >  xen/arch/arm/arm64/lib/strrchr.S | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> A couple of tangential things.
> 
> This file was inherited from Linux.  Does the same bug need fixing
> there?  What about the arm32 side?

Yes, I'll have a look at Linux. Arm32 looks fine to me.

> 
> Looking at your example, it surely wasn't actually as simple as
> strrchr("", '\0') ?  I'd expect the optimiser to be able to turn that
> into a constant and not call out to the library implementation.
> 

We ran into this while exploring a new QEMU based test framework, we had
it do some fuzzing and it tripped over this.


> Elsewhere, I've created xen/common/bitops.c to be CONFIG_SELF_TESTS for
> the bit operations including the arch-optimised variations, because
> they're subtle and easy to get wrong.  This looks like it's worth doing
> the same for the bits of libc we implement.
>

Yes, that looks like a good fit, thanks.

Cheers,
Edgar



 


Rackspace

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