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

[PATCH] x86/extable: hide use of negative offset from array start


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 22 Feb 2023 11:22:54 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=OABGfhw/XniI7F6M7hCIrlgr1VnzTirO+SOQl/uiVm4=; b=MJJ+EQsDuWzTboHavD2Eekfz7wiOH2bjBMoQX5lxgLUuFlXTSigXWaDku6iZy9z12M4TPD9z1waPvm/lmTEqyZUyUvR3kM0Xox8/5SAuxcpTIADi9jD5yxYsm6CuoNhr09MrfvpTywl/Iv/TxBfK56/Sqz0Ygg6CybfnW7rx0yiyjDqo/23tZjtw2BRv0GiC3VRa9jTjGJNUYEkF7LTQvFscrFxquj1kkdaGJ6zlVr3Uz5piWS3Av/yCAn7Q1CS5v/GQK0uKLSgpLVreg/OYXAYmYtnwe0q86eczMHUOsjHzHOlz3kBVV0mFEzvqYDwrVODu8LgVsR/PiGuV6q6REw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jlq0qxK9Ds/6pID+/wPqHgn25q9JRlb4D1l8aIlzAUtFIi6EaZIhoBWT+kXdAA69JWQIuHV7ZXGwSFKBnja80x5/ZQtjK8WyTVJFQKOXtNHsZv3AEZ1tn+JY7tSZuLYmhG77cnqGKZMq0bTQ7CBoiGnnP5Pf+wPKecSF8xeaXupX4sgSQA0dhlaWePCCGizmBsh909BhUG/SUPWdMFjLY/OHQAgziiX8H3cZQwyizjRIj+zx+Y0uu14nD6X+40CDQoO63icfFOuyH23ToE1vn7OXrySg8T8jSv5q9tgm7v+aK4ZR5hbIyeXXf2XJ360fNe134pFdoNCc7YpVfBkYdw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 22 Feb 2023 10:23:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

In COVERAGE=y but DEBUG=n builds (observed by randconfig testing) gcc12
takes issue with the subtraction of 1 from __stop___pre_ex_table[],
considering this an out of bounds access. Not being able to know that
the symbol actually marks the end of an array, the compiler is kind of
right with this diagnosis. Move the subtraction into the function.

Reported-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
To keep things simple, I'm merely calculating "last" as a local variable
now, rather than replacing its uses by suitable ones of "end". In the
longer run it may become necessary to actually go this 2nd step, as in
principle the compiler could inline the function and then still spot the
same issue. However, while the subtraction of 1 can likely be avoided by
suitable other adjustments, "last - first" cannot easily be. Yet that's
also an offense, in that it's calculating the difference between pointers
into distinct objects.

--- a/xen/arch/x86/extable.c
+++ b/xen/arch/x86/extable.c
@@ -64,9 +64,10 @@ void __init sort_exception_tables(void)
 
 static unsigned long
 search_one_extable(const struct exception_table_entry *first,
-                   const struct exception_table_entry *last,
+                   const struct exception_table_entry *end,
                    unsigned long value)
 {
+    const struct exception_table_entry *last = end - 1;
     const struct exception_table_entry *mid;
     long diff;
 
@@ -91,7 +92,7 @@ search_exception_table(const struct cpu_
     unsigned long stub = this_cpu(stubs.addr);
 
     if ( region && region->ex )
-        return search_one_extable(region->ex, region->ex_end - 1, regs->rip);
+        return search_one_extable(region->ex, region->ex_end, regs->rip);
 
     if ( regs->rip >= stub + STUB_BUF_SIZE / 2 &&
          regs->rip < stub + STUB_BUF_SIZE &&
@@ -102,7 +103,7 @@ search_exception_table(const struct cpu_
 
         region = find_text_region(retptr);
         retptr = region && region->ex
-                 ? search_one_extable(region->ex, region->ex_end - 1, retptr)
+                 ? search_one_extable(region->ex, region->ex_end, retptr)
                  : 0;
         if ( retptr )
         {
@@ -198,7 +199,7 @@ search_pre_exception_table(struct cpu_us
 {
     unsigned long addr = regs->rip;
     unsigned long fixup = search_one_extable(
-        __start___pre_ex_table, __stop___pre_ex_table-1, addr);
+        __start___pre_ex_table, __stop___pre_ex_table, addr);
     if ( fixup )
     {
         dprintk(XENLOG_INFO, "Pre-exception: %p -> %p\n", _p(addr), _p(fixup));



 


Rackspace

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