From nobody Sat Dec 21 13:48:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1727253811; cv=none; d=zohomail.com; s=zohoarc; b=Q4PmIQG+7IBgXTNidWkoH1wlTHhUl6PmTM2BPZGs7t2TUGhQUG2nDF+nqF9rf/J2CtuuQBZEosR30e5pBxLKFVc/4X3+ohiSEQ8LpdQlZFcgwAFpOnKSAdRMx4uAkR7zqK41YDz4/YBLnfSVITHSE5hNeouBmcTFs+Yxc5PDvRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727253811; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VmANCqOCNLuCE6WgFe5IkbUtz4Dl4MOkNZ8FdlMteZ4=; b=X3ndWyg2t2O/w9faM1anKyD/IFOvGGjnXDjvDoASwutRhZM8ja2lIt3LLmEiynfvMjNkMKgcZzSBh75qfgx69SEFChtMhzNnnpSuaj0uXdDvdJrJ0SZcwP084aO41LIiUVKvY9BohkQLnf6HjKMvPoqAIZ39IjqhRBr203wuQwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727253811969221.3064452946129; Wed, 25 Sep 2024 01:43:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803573.1214239 (Exim 4.92) (envelope-from ) id 1stNc4-0005cq-LZ; Wed, 25 Sep 2024 08:43:08 +0000 Received: by outflank-mailman (output) from mailman id 803573.1214239; Wed, 25 Sep 2024 08:43:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc4-0005ch-Fv; Wed, 25 Sep 2024 08:43:08 +0000 Received: by outflank-mailman (input) for mailman id 803573; Wed, 25 Sep 2024 08:43:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc2-0005NX-St for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 08:43:06 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2e87d1c4-7b1a-11ef-99a2-01e77a169b0f; Wed, 25 Sep 2024 10:43:05 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c5b9d2195eso5114209a12.1 for ; Wed, 25 Sep 2024 01:43:05 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4974a6sm1620662a12.39.2024.09.25.01.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 01:43:03 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2e87d1c4-7b1a-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1727253784; x=1727858584; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VmANCqOCNLuCE6WgFe5IkbUtz4Dl4MOkNZ8FdlMteZ4=; b=V+Pl2q8YhftYc7znEWOsw7Xd/KvnbmQRt5JLV77HKkG+ZnsOdh9kDr/J6nVOf+Xcyc msNW00PK6wTLTXfsYLo9kuDnC4YoJzOdY4iZ0psTTIgU8QpNgAcEfSyvnxxtkxksQNUs eqQI4HWvzt/nFsJFmVujUgw62etdBQ8rbvAmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727253784; x=1727858584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VmANCqOCNLuCE6WgFe5IkbUtz4Dl4MOkNZ8FdlMteZ4=; b=Oipwomul/FYBhcCj0A/fFS+rf6soUu+VL2CTtj3a7GxoyzWkW2nDplq+USvzdaa3+U XV/jhSX0u6UDu+Y55ekmPUAbYx1LszHrGYHjhqrXJ0rEZfJp5Q9eRAiyIqXnFmUODif4 OEpy96PxsJvEkSgQUFq1y06S1aWwd+7sBODQa0Kp5abYuwkEb9uQ8uUod3gEPQbM3360 umu8P7hK7k+Mn+0RWm+Gn2LnczrpKpL+4MbxPB2C6xGo8lTPqjX1wR4jZZ8NNy0aqaaj YU+nah5SO9SiuKH5gmTZ8FPhWeOHVBW/ZNBLuQuAAJFncOjtZPWq/5ybMyfNAKEp/atM 6/OA== X-Gm-Message-State: AOJu0YyaVz91cMZgwHgvKxUwBmPL3FL0iG2s0Cp26dSd1V3yajMDI9Ex hXdpvGM8z3mlLneepbuA+f+K+tt3noiFF1Kw7+HTyHNM3yF/xRuHAjujRgaCsq7mRERvDNOk3dQ k X-Google-Smtp-Source: AGHT+IHcKk7PadNzltiCJe7/SxHQQeAdUrJQe22On1AgtTHr+7rrO+39rxXpoqDaHmR24SJX5+V7XQ== X-Received: by 2002:a05:6402:4416:b0:5c5:c5c0:74ec with SMTP id 4fb4d7f45d1cf-5c7206449d6mr1554436a12.24.1727253784120; Wed, 25 Sep 2024 01:43:04 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Ross Lagerwall Subject: [PATCH v2 1/6] xen/livepatch: remove useless check for duplicated sections Date: Wed, 25 Sep 2024 10:42:34 +0200 Message-ID: <20240925084239.85649-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240925084239.85649-1-roger.pau@citrix.com> References: <20240925084239.85649-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1727253812190116600 The current check for duplicated sections in a payload is not effective. S= uch check is done inside a loop that iterates over the sections names, it's logically impossible for the bitmap to be set more than once. The usage of a bitmap in check_patching_sections() has been replaced with a boolean, since the function just cares that at least one of the special sections is present. No functional change intended, as the check was useless. Fixes: 29f4ab0b0a4f ('xsplice: Implement support for applying/reverting/rep= lacing patches.') Fixes: 76b3d4098a92 ('livepatch: Do not enforce ELF_LIVEPATCH_FUNC section = presence') Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Andrew Cooper and I'm very --- Changes since v1: - New in this version. --- xen/common/livepatch.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index d93a556bcda2..df41dcce970a 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -473,7 +473,6 @@ static int check_special_sections(const struct livepatc= h_elf *elf) static const char *const names[] =3D { ELF_LIVEPATCH_DEPENDS, ELF_LIVEPATCH_XEN_DEPENDS, ELF_BUILD_ID_NOTE}; - DECLARE_BITMAP(found, ARRAY_SIZE(names)) =3D { 0 }; =20 for ( i =3D 0; i < ARRAY_SIZE(names); i++ ) { @@ -493,13 +492,6 @@ static int check_special_sections(const struct livepat= ch_elf *elf) elf->name, names[i]); return -EINVAL; } - - if ( test_and_set_bit(i, found) ) - { - printk(XENLOG_ERR LIVEPATCH "%s: %s was seen more than once\n", - elf->name, names[i]); - return -EINVAL; - } } =20 return 0; @@ -517,7 +509,7 @@ static int check_patching_sections(const struct livepat= ch_elf *elf) ELF_LIVEPATCH_PREREVERT_HOOK, ELF_LIVEPATCH_REVERT_HOOK, ELF_LIVEPATCH_POSTREVERT_HOOK}; - DECLARE_BITMAP(found, ARRAY_SIZE(names)) =3D { 0 }; + bool found =3D false; =20 /* * The patching sections are optional, but at least one @@ -544,16 +536,11 @@ static int check_patching_sections(const struct livep= atch_elf *elf) return -EINVAL; } =20 - if ( test_and_set_bit(i, found) ) - { - printk(XENLOG_ERR LIVEPATCH "%s: %s was seen more than once\n", - elf->name, names[i]); - return -EINVAL; - } + found =3D true; } =20 /* Checking if at least one section is present. */ - if ( bitmap_empty(found, ARRAY_SIZE(names)) ) + if ( !found ) { printk(XENLOG_ERR LIVEPATCH "%s: Nothing to patch. Aborting...\n", elf->name); --=20 2.46.0 From nobody Sat Dec 21 13:48:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1727253807; cv=none; d=zohomail.com; s=zohoarc; b=SEyN6rlW93fMbsMKZJ4UH8Tnt7bO26ae3FDbR5gwNOOZPtEvxRDvTfSO+Ms7K63SMwLe8PMhTi2pqgB0RN2qvA4FuMtYqBPY1ftBwA677Fb8ngk5+EA/aU5BsFy4J8T+aW8w8IckCMLzsXxD+kUN+unIzDqGArG+qRLG4RLMuKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727253807; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nnMSClB/JlHEd0hi+6Yy8qVmR2fgY2lFCm5wFEZMF2U=; b=M8h+DEIyamXp4+q8qIP2X9Nvfn0NUFGjscVDum5InN5PexVFMcns/nncNvzAPXQSBknvPPUswbHkvNd6qpfGh8ePCtYwkl4nljKOjMlfaqWrVwrXuG2tinlP92pSab9ru+mT78e3vIxXZZKWb201hJqCWIcXo03oVmJYTvqiyfY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727253807540684.6634885931178; Wed, 25 Sep 2024 01:43:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803574.1214245 (Exim 4.92) (envelope-from ) id 1stNc4-0005dz-W7; Wed, 25 Sep 2024 08:43:08 +0000 Received: by outflank-mailman (output) from mailman id 803574.1214245; Wed, 25 Sep 2024 08:43:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc4-0005dS-Nl; Wed, 25 Sep 2024 08:43:08 +0000 Received: by outflank-mailman (input) for mailman id 803574; Wed, 25 Sep 2024 08:43:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc3-0005NX-R3 for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 08:43:07 +0000 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [2a00:1450:4864:20::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2f257778-7b1a-11ef-99a2-01e77a169b0f; Wed, 25 Sep 2024 10:43:06 +0200 (CEST) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a8a7596b7dfso116107866b.0 for ; Wed, 25 Sep 2024 01:43:06 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f54141sm183645366b.83.2024.09.25.01.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 01:43:05 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2f257778-7b1a-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1727253785; x=1727858585; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nnMSClB/JlHEd0hi+6Yy8qVmR2fgY2lFCm5wFEZMF2U=; b=Ry1waOanimGHbuARzKfPApeBxAfggLOEPjPPb1d2EsX9fo0UIda61dp/k63/MVcsSN aGLHxs4pGdkGX8bgjGyJIHQB+ONFGecH/0VH/nXBtVoL7uJMZMQSavtN01Oer4/wi1kg tULrjZrn+b4rxT7ILRMF2ehtIs8QRz0RAbJCQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727253785; x=1727858585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nnMSClB/JlHEd0hi+6Yy8qVmR2fgY2lFCm5wFEZMF2U=; b=AF3y6Z4TpkiG0PwsdZMv7TL0Inl/AVrM2rhnJt/jWB1H3LdEHtEtLC4byqJ2Q0vvhN 6xlIv9ueOQIdvK2PiIioSYwRgaAouO4NU3xKVffYY6yGZH9PZeX2HSgfFv7xWlX3+7bA hvQ/jjXowDxrWMiPj22NyDJZusxWShFuAw27nQIvxh2pJwmpWw2Glyp/cYvI5WbvGe0Y u59p8pxDEEhRfiMWPixC4ZiiWOUTrEd1FA+tUiiuAMx/LjbWw2n9X/7Dh5TeO4xLUqqX RtQsOpL98FtKJ87uorlv9FVheeLFF60vQcXdyVzF4+ylg7xSdQGgIfAf9syzYzIKf37M ypiA== X-Gm-Message-State: AOJu0Yz8ZBVOak6HvOXlWdyAuy3B7x7GxOb9AhOZeaXWfieQbDXs3Xk8 Ros2AsmfaJ7tIYByZYTZeTQ3Byf7ZArmYkNMjZ69rtrjT6Iq6PZCzW0WpkjAetg9uoEFCeRNyg/ q X-Google-Smtp-Source: AGHT+IHkJDPHmXBuT9psZKCEzzfYDng6uBeOeq+mOZpku0Vg3D7V/SVe9mQu0aXanUQbwH0gbitggg== X-Received: by 2002:a17:907:6094:b0:a8a:6db7:665d with SMTP id a640c23a62f3a-a93a170470cmr158573766b.17.1727253785521; Wed, 25 Sep 2024 01:43:05 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Ross Lagerwall Subject: [PATCH v2 2/6] xen/livepatch: zero pointer to temporary load buffer Date: Wed, 25 Sep 2024 10:42:35 +0200 Message-ID: <20240925084239.85649-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240925084239.85649-1-roger.pau@citrix.com> References: <20240925084239.85649-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1727253808149116600 The livepatch_elf_sec data field points to the temporary load buffer, it's = the load_addr field that points to the stable loaded section data. Zero the da= ta field once load_addr is set, as it would otherwise become a dangling pointer once the load buffer is freed. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v1: - New in this version. --- xen/common/livepatch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index df41dcce970a..87b3db03e26d 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -383,6 +383,9 @@ static int move_payload(struct payload *payload, struct= livepatch_elf *elf) } else memset(elf->sec[i].load_addr, 0, elf->sec[i].sec->sh_size); + + /* Avoid leaking pointers to temporary load buffers. */ + elf->sec[i].data =3D NULL; } } =20 --=20 2.46.0 From nobody Sat Dec 21 13:48:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1727253808; cv=none; d=zohomail.com; s=zohoarc; b=eK0Sq3rMJYEqKzX8JSX8Xg9oD36c8fckmjdE60W2GvhIzhNIBf3MRE/xXaq6YiM2s11EgwEtZGmut3OS0qW0olkGxAONhMMa7/tzX/ptmsYdNn1kldSjHOtI2TQZjUZd5SIlMnc1JA5VY5S2gn9lkYE62y/h48xGRSe5Fd+uBI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727253808; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/A7anrJKRONUakwDhBF6Xlt3dpj6kBkDkGt4BhpDYoU=; b=OSabw0d6NGskLnbQACh1w+NBR22A/qUrMLsD+EjGUxXRxuh7ze4dodsC1LZ9zjB8YvjA+65mPJYTnWrY8Xh5uqdu7niRxDJgiaMi1aav9PI7qV2M1CdPOoiqMr+I1A53Y+r6B8TuEaYxcFm6XXXcpIiDqIFo7BjftOJL67bif8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 172725380802955.32454498902632; Wed, 25 Sep 2024 01:43:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803575.1214260 (Exim 4.92) (envelope-from ) id 1stNc6-000661-60; Wed, 25 Sep 2024 08:43:10 +0000 Received: by outflank-mailman (output) from mailman id 803575.1214260; Wed, 25 Sep 2024 08:43:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc6-00065S-16; Wed, 25 Sep 2024 08:43:10 +0000 Received: by outflank-mailman (input) for mailman id 803575; Wed, 25 Sep 2024 08:43:08 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc4-0005cc-ID for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 08:43:08 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2fda582a-7b1a-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 10:43:07 +0200 (CEST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a910860e4dcso445900166b.3 for ; Wed, 25 Sep 2024 01:43:07 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93a5d4a6c8sm40342966b.222.2024.09.25.01.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 01:43:06 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2fda582a-7b1a-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1727253787; x=1727858587; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/A7anrJKRONUakwDhBF6Xlt3dpj6kBkDkGt4BhpDYoU=; b=dlGUN5i9SeeJh08PT5HlEaXjzObD/cux0syuttMW7JUtfLQsLIMLRqTunqb8lHQopa cOGGhCWZVd/IrzqQb43a9YSEzSsE3sHTfm+YgmLMXmsQtJh+cv21Pom5POAT0BVpkodK EDR6ChtmGXx1ijrqmSQiOjR83guc2TqIT1Zr0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727253787; x=1727858587; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/A7anrJKRONUakwDhBF6Xlt3dpj6kBkDkGt4BhpDYoU=; b=BFR0P9nWomMH/vT6InMxWysltFefRjY16eOVhK7jXHvYhp8fEh7v8FCPO2bbUqQpfh FHJwgu5z+qjxXnpAamYO+WNGhpEbjgF8bnuLVeUxgEdapYbBa/W3cm60eoPx4yrCy4xX uOsonh+38yNoR9NdLilSYyxbH5VREDrmdwkI58+TiRJIeex5tuDIbwobf+1eksvBUSrD iuOJs5wlATUZf/xbNq0cRau5fKFM5HoktVBhry2vUx6Rz3wjyN9n1Icn5xeS6gm4KYGw OheEeGG65ksvkKAuI6qK5sHG1seoIxwkwEqSCha5/t5j5tHya2bk+rD8ooSVMy8qUQqd hoGg== X-Gm-Message-State: AOJu0YwFKaIObVeK5a0oKc+IlwKnJCyY8Ik45qWBf8EZe+NU9qp+L3mK 2XpgVQXF8KuPOWQ+8QalQEfprMwvHqC9g0BYwMzKQuZWjt2DmlrkLz/gBfplijh2+RcZZW3P2e4 b X-Google-Smtp-Source: AGHT+IFsXsuXl+00mO3vs6bnEI07yLJnBo+Ue7Qszr7Px4+ZLH7AGyObwzpvnP6H+I/zoaEFZeyXNQ== X-Received: by 2002:a17:907:f197:b0:a8a:85af:7ae8 with SMTP id a640c23a62f3a-a93a0325159mr172110966b.11.1727253786633; Wed, 25 Sep 2024 01:43:06 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Ross Lagerwall Subject: [PATCH v2 3/6] xen/livepatch: simplify and unify logic in prepare_payload() Date: Wed, 25 Sep 2024 10:42:36 +0200 Message-ID: <20240925084239.85649-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240925084239.85649-1-roger.pau@citrix.com> References: <20240925084239.85649-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1727253808198116600 The following sections: .note.gnu.build-id, .livepatch.xen_depends and .livepatch.depends are mandatory and ensured to be present by check_special_sections() before prepare_payload() is called. Simplify the logic in prepare_payload() by introducing a generic function to parse the sections that contain a buildid. Note the function assumes the buildid related section to always be present. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Andrew Cooper --- Changes since v1: - Rename. - Change order of assert. --- xen/common/livepatch.c | 110 +++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 60 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 87b3db03e26d..8e61083f23a7 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -470,6 +470,31 @@ static int xen_build_id_dep(const struct payload *payl= oad) return 0; } =20 +/* Parses build-id sections into the given destination. */ +static int parse_buildid(const struct livepatch_elf_sec *sec, + struct livepatch_build_id *id) +{ + const Elf_Note *n; + int rc; + + /* Presence of the sections is ensured by check_special_sections(). */ + ASSERT(sec); + + n =3D sec->load_addr; + + if ( sec->sec->sh_size <=3D sizeof(*n) ) + return -EINVAL; + + rc =3D xen_build_id_check(n, sec->sec->sh_size, &id->p, &id->len); + if ( rc ) + return rc; + + if ( !id->len || !id->p ) + return -EINVAL; + + return 0; +} + static int check_special_sections(const struct livepatch_elf *elf) { unsigned int i; @@ -641,11 +666,12 @@ static int prepare_payload(struct payload *payload, struct livepatch_elf *elf) { const struct livepatch_elf_sec *sec; + const struct payload *data; unsigned int i; struct livepatch_func *funcs; struct livepatch_func *f; struct virtual_region *region; - const Elf_Note *n; + int rc; =20 sec =3D livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_FUNC); if ( sec ) @@ -663,8 +689,6 @@ static int prepare_payload(struct payload *payload, =20 for ( i =3D 0; i < payload->nfuncs; i++ ) { - int rc; - f =3D &(funcs[i]); =20 if ( f->version !=3D LIVEPATCH_PAYLOAD_VERSION ) @@ -707,69 +731,35 @@ static int prepare_payload(struct payload *payload, LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.revert.action, ELF_LI= VEPATCH_REVERT_HOOK); LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.revert.post, ELF_LIVE= PATCH_POSTREVERT_HOOK); =20 - sec =3D livepatch_elf_sec_by_name(elf, ELF_BUILD_ID_NOTE); - if ( sec ) - { - const struct payload *data; - - n =3D sec->load_addr; - - if ( sec->sec->sh_size <=3D sizeof(*n) ) - return -EINVAL; - - if ( xen_build_id_check(n, sec->sec->sh_size, - &payload->id.p, &payload->id.len) ) - return -EINVAL; - - if ( !payload->id.len || !payload->id.p ) - return -EINVAL; + rc =3D parse_buildid(livepatch_elf_sec_by_name(elf, ELF_BUILD_ID_NOTE), + &payload->id); + if ( rc ) + return rc; =20 - /* Make sure it is not a duplicate. */ - list_for_each_entry ( data, &payload_list, list ) + /* Make sure it is not a duplicate. */ + list_for_each_entry ( data, &payload_list, list ) + { + /* No way _this_ payload is on the list. */ + ASSERT(data !=3D payload); + if ( data->id.len =3D=3D payload->id.len && + !memcmp(data->id.p, payload->id.p, data->id.len) ) { - /* No way _this_ payload is on the list. */ - ASSERT(data !=3D payload); - if ( data->id.len =3D=3D payload->id.len && - !memcmp(data->id.p, payload->id.p, data->id.len) ) - { - dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Already loaded as %s!= \n", - elf->name, data->name); - return -EEXIST; - } + dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Already loaded as %s!\n", + elf->name, data->name); + return -EEXIST; } } =20 - sec =3D livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_DEPENDS); - if ( sec ) - { - n =3D sec->load_addr; - - if ( sec->sec->sh_size <=3D sizeof(*n) ) - return -EINVAL; - - if ( xen_build_id_check(n, sec->sec->sh_size, - &payload->dep.p, &payload->dep.len) ) - return -EINVAL; - - if ( !payload->dep.len || !payload->dep.p ) - return -EINVAL; - } - - sec =3D livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_XEN_DEPENDS); - if ( sec ) - { - n =3D sec->load_addr; - - if ( sec->sec->sh_size <=3D sizeof(*n) ) - return -EINVAL; - - if ( xen_build_id_check(n, sec->sec->sh_size, - &payload->xen_dep.p, &payload->xen_dep.len= ) ) - return -EINVAL; + rc =3D parse_buildid(livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_DEPE= NDS), + &payload->dep); + if ( rc ) + return rc; =20 - if ( !payload->xen_dep.len || !payload->xen_dep.p ) - return -EINVAL; - } + rc =3D parse_buildid(livepatch_elf_sec_by_name(elf, + ELF_LIVEPATCH_XEN_DEPENDS= ), + &payload->xen_dep); + if ( rc ) + return rc; =20 /* Setup the virtual region with proper data. */ region =3D &payload->region; --=20 2.46.0 From nobody Sat Dec 21 13:48:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1727253813; cv=none; d=zohomail.com; s=zohoarc; b=iheIa55/0sV+prMRTYvde5QJDBNh0sn1qBGoqxARgSsjOl6sOvGqE4SwvnxwVlmPcDuU/IWYGHmEtU8JF8jbuJjwMGlInFjlTngfvn9ng8kg9LwvzNjqIWteRnRW7SRefqJ7eHEye68bSwtcLps7fE4r2TaJKENP1YfOZHc047I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727253813; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A9Q7t84HRCJN2WRRUodHKbS/3EHi7/hM9/1ZhkVtq7c=; b=Pmk1lKGobd+yAcO8gr9LgqFEg8Vx5UOTcJqp0JH2YbptF9b3q/5QF9LwvHdVd6ew47l88/Y1WvP5CN4OFc0AudiVGO8HqP3b9Ir6M3i8GPCH+HdDqVNkB/GQfIhp2FQm3JKxu/sKQH7juhkuEoxtkgkt+sz24O5tnvyq2tqf87Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727253813764280.8900926754833; Wed, 25 Sep 2024 01:43:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803576.1214265 (Exim 4.92) (envelope-from ) id 1stNc6-0006Ax-IF; Wed, 25 Sep 2024 08:43:10 +0000 Received: by outflank-mailman (output) from mailman id 803576.1214265; Wed, 25 Sep 2024 08:43:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc6-0006Ae-An; Wed, 25 Sep 2024 08:43:10 +0000 Received: by outflank-mailman (input) for mailman id 803576; Wed, 25 Sep 2024 08:43:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc5-0005cc-DY for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 08:43:09 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 30ae02e0-7b1a-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 10:43:08 +0200 (CEST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-53660856a21so6343505e87.2 for ; Wed, 25 Sep 2024 01:43:08 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4d790esm1618283a12.92.2024.09.25.01.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 01:43:07 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 30ae02e0-7b1a-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1727253788; x=1727858588; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A9Q7t84HRCJN2WRRUodHKbS/3EHi7/hM9/1ZhkVtq7c=; b=Y8hPbvqFnPr2j/FNBWR/FNVnNLzyZx7SGcJLUjmaMcmMzkl680CM13zLf4dKYdBupq uPU4R/rVEDFIWg53AA7fDP4u9lZLw6HT+UNk3XT12fU69LPTknETkhTXS4VytAqqy9pp j2MA3j3xc0QFlN7GBcAZSsHDMKUk9Sw8j8bu0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727253788; x=1727858588; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A9Q7t84HRCJN2WRRUodHKbS/3EHi7/hM9/1ZhkVtq7c=; b=MswkH8Xqxht/krb4QCWF4jyuSKbH4TlH9Yp9SJYFjZQBN8Ehd4VFX6PbMFck45/eKc p4Pfh3o71v1gSm/3PkgZm52uu1G/5vp0VR2q5t6ssFh42Ql6u+/47Hr95qW1ekvBebWv 6BRcT4ID7DtqUtNXgp+Csx+2IhNj0TCAQ9Pr7WOX+td1uRwessH8TqqrL5KWbxA4Ykao 4NId5lW9GZX6xpfCwhbTxFmR1yEZDoJpqzUnnLQDLoAff47ARWCd9nA9mbhJw0Hcj/Rz o4s3cNb9ZHrKwVXHYlZjkCeXBfEOWo8Wj6zorqqdYOspzwE94LbnVFVKHGrh++hH2GfN X4rA== X-Gm-Message-State: AOJu0Yy5dO/pU+AY//7RMMrrSprDEjH1Mwi67F0+8ERCl9I8QJcaZA00 3WrieXoTCKsa6cOE7aGaBPdrsBRgSGxyWAGdzWmxeexcYOXDr548+YU+8itfrVBXeSaZKekGvSf M X-Google-Smtp-Source: AGHT+IFhYdpG5GjPV0eqkcQQJQJRo3wZvmC0rPSjF1eiOtrojuILBGTSMe1wj+c/riPnvnh5u3iH9Q== X-Received: by 2002:a05:6512:108b:b0:52c:e05e:849b with SMTP id 2adb3069b0e04-5387755e295mr1025203e87.39.1727253787949; Wed, 25 Sep 2024 01:43:07 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Ross Lagerwall Subject: [PATCH v2 4/6] xen/livepatch: do Xen build-id check earlier Date: Wed, 25 Sep 2024 10:42:37 +0200 Message-ID: <20240925084239.85649-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240925084239.85649-1-roger.pau@citrix.com> References: <20240925084239.85649-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1727253814261116600 The check against the expected Xen build ID should be done ahead of attempt= ing to apply the alternatives contained in the livepatch. If the CPUID in the alternatives patching data is out of the scope of the running Xen featureset the BUG() in _apply_alternatives() will trigger thus bringing the system down. Note the layout of struct alt_instr could also change between versions. It's also possible for struct exception_table_ent= ry to have changed format, hence leading to other kind of errors if parsing of= the payload is done ahead of checking if the Xen build-id matches. Move the Xen build ID check as early as possible. To do so introduce a new check_xen_buildid() function that parses and checks the Xen build-id before moving the payload. Since the expected Xen build-id is used early to detect whether the livepatch payload could be loaded, there's no reason to store it in the payload struct, as a non-matching Xen build-id won't get the payload populated in the first place. Note parse_buildid() has to be slightly adjusted to allow fetching the sect= ion data from the 'data' field instead of the 'load_addr' one: with the Xen bui= ld ID moved ahead of move_payload() 'load_addr' is not yet set when the Xen bu= ild ID check is performed. Also printing the expected Xen build ID has part of dumping the payload is no longer done, as all loaded payloads would have Xen build IDs matching the running Xen, otherwise they would have failed to loa= d. Fixes: 879615f5db1d ('livepatch: Always check hypervisor build ID upon live= patch upload') Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v1: - Do the Xen build-id check even earlier. --- xen/common/livepatch.c | 66 +++++++++++++++++++---------- xen/include/xen/livepatch_payload.h | 1 - 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 8e61083f23a7..895c425cd5ea 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -448,24 +448,21 @@ static bool section_ok(const struct livepatch_elf *el= f, return true; } =20 -static int xen_build_id_dep(const struct payload *payload) +static int xen_build_id_dep(const struct livepatch_build_id *expected) { const void *id =3D NULL; unsigned int len =3D 0; int rc; =20 - ASSERT(payload->xen_dep.len); - ASSERT(payload->xen_dep.p); + ASSERT(expected->len); + ASSERT(expected->p); =20 rc =3D xen_build_id(&id, &len); if ( rc ) return rc; =20 - if ( payload->xen_dep.len !=3D len || memcmp(id, payload->xen_dep.p, l= en) ) { - printk(XENLOG_ERR LIVEPATCH "%s: check against hypervisor build-id= failed\n", - payload->name); + if ( expected->len !=3D len || memcmp(id, expected->p, len) ) return -EINVAL; - } =20 return 0; } @@ -480,7 +477,8 @@ static int parse_buildid(const struct livepatch_elf_sec= *sec, /* Presence of the sections is ensured by check_special_sections(). */ ASSERT(sec); =20 - n =3D sec->load_addr; + /* Possibly use the temporary load buffer if load_addr isn't yet set. = */ + n =3D sec->load_addr ?: sec->data; =20 if ( sec->sec->sh_size <=3D sizeof(*n) ) return -EINVAL; @@ -495,11 +493,44 @@ static int parse_buildid(const struct livepatch_elf_s= ec *sec, return 0; } =20 +static int check_xen_buildid(const struct livepatch_elf *elf) +{ + struct livepatch_build_id id; + const struct livepatch_elf_sec *sec =3D + livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_XEN_DEPENDS); + int rc; + + if ( !sec ) + { + printk(XENLOG_ERR LIVEPATCH "%s: %s is missing\n", + elf->name, ELF_LIVEPATCH_XEN_DEPENDS); + return -EINVAL; + } + + rc =3D parse_buildid(sec, &id); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH "%s: failed to parse build-id at %s: %= d\n", + elf->name, ELF_LIVEPATCH_XEN_DEPENDS, rc); + return -EINVAL; + } + + rc =3D xen_build_id_dep(&id); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH + "%s: check against hypervisor build-id failed: %d\n", + elf->name, rc); + return -EINVAL; + } + + return 0; +} + static int check_special_sections(const struct livepatch_elf *elf) { unsigned int i; static const char *const names[] =3D { ELF_LIVEPATCH_DEPENDS, - ELF_LIVEPATCH_XEN_DEPENDS, ELF_BUILD_ID_NOTE}; =20 for ( i =3D 0; i < ARRAY_SIZE(names); i++ ) @@ -755,12 +786,6 @@ static int prepare_payload(struct payload *payload, if ( rc ) return rc; =20 - rc =3D parse_buildid(livepatch_elf_sec_by_name(elf, - ELF_LIVEPATCH_XEN_DEPENDS= ), - &payload->xen_dep); - if ( rc ) - return rc; - /* Setup the virtual region with proper data. */ region =3D &payload->region; =20 @@ -1069,6 +1094,10 @@ static int load_payload_data(struct payload *payload= , void *raw, size_t len) if ( rc ) goto out; =20 + rc =3D check_xen_buildid(&elf); + if ( rc ) + goto out; + rc =3D move_payload(payload, &elf); if ( rc ) goto out; @@ -1093,10 +1122,6 @@ static int load_payload_data(struct payload *payload= , void *raw, size_t len) if ( rc ) goto out; =20 - rc =3D xen_build_id_dep(payload); - if ( rc ) - goto out; - rc =3D build_symbol_table(payload, &elf); if ( rc ) goto out; @@ -2199,9 +2224,6 @@ static void cf_check livepatch_printall(unsigned char= key) =20 if ( data->dep.len ) printk("depend-on=3D%*phN\n", data->dep.len, data->dep.p); - - if ( data->xen_dep.len ) - printk("depend-on-xen=3D%*phN\n", data->xen_dep.len, data->xen= _dep.p); } =20 spin_unlock(&payload_lock); diff --git a/xen/include/xen/livepatch_payload.h b/xen/include/xen/livepatc= h_payload.h index 472d6a4a63c1..c6dc7cb5fa21 100644 --- a/xen/include/xen/livepatch_payload.h +++ b/xen/include/xen/livepatch_payload.h @@ -62,7 +62,6 @@ struct payload { unsigned int nsyms; /* Nr of entries in .strtab and s= ymbols. */ struct livepatch_build_id id; /* ELFNOTE_DESC(.note.gnu.build-i= d) of the payload. */ struct livepatch_build_id dep; /* ELFNOTE_DESC(.livepatch.depend= s). */ - struct livepatch_build_id xen_dep; /* ELFNOTE_DESC(.livepatch.xen_de= pends). */ livepatch_loadcall_t *const *load_funcs; /* The array of funcs to ca= ll after */ livepatch_unloadcall_t *const *unload_funcs;/* load and unload of the = payload. */ struct livepatch_hooks hooks; /* Pre and post hooks for apply a= nd revert */ --=20 2.46.0 From nobody Sat Dec 21 13:48:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1727253815; cv=none; d=zohomail.com; s=zohoarc; b=L55odHTMU19qaqYpL33jgbTnqSvaDEVtj8dvEL+gAtDsEhtv4p6EkiJi09hkGeGCUjf5eHiRdaLuc6XTcJ7+SJ7vqoLXfM/tNFUaDkeczxKsopD4xUmGuuTlNnY458GyayBikrCj+mofQ9zANRW6RQUbt5dl+0PSG11UKj7V0UI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727253815; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OIoU0qLfgLq7otbwa+2RabVnL5gbGYSnBya+EH+CZUc=; b=b9l+LypTL/SbWXmJeYE2lrG2HUMp83NB602V7yLJlWhn6vYSp6wJzX2kUToxcEb6Bhf+sKnCMaNEiNELqY8t3HUbpZpOrfD/xP78ehEzPMCBvjz+hnP75wKHIIikbRIjRj3mAppTfi1vJt7fEcMutBjt7lu/YdJ2yyyvcbCKFe8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727253815260195.86812173819646; Wed, 25 Sep 2024 01:43:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803577.1214279 (Exim 4.92) (envelope-from ) id 1stNc7-0006db-Ur; Wed, 25 Sep 2024 08:43:11 +0000 Received: by outflank-mailman (output) from mailman id 803577.1214279; Wed, 25 Sep 2024 08:43:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc7-0006dF-R7; Wed, 25 Sep 2024 08:43:11 +0000 Received: by outflank-mailman (input) for mailman id 803577; Wed, 25 Sep 2024 08:43:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc6-0005cc-NC for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 08:43:10 +0000 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [2a00:1450:4864:20::12c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 316db50a-7b1a-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 10:43:10 +0200 (CEST) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-53659867cbdso9526179e87.3 for ; Wed, 25 Sep 2024 01:43:10 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f342b2sm186015666b.35.2024.09.25.01.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 01:43:08 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 316db50a-7b1a-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1727253789; x=1727858589; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OIoU0qLfgLq7otbwa+2RabVnL5gbGYSnBya+EH+CZUc=; b=ERtN6oMhiFptWQSrK1zE+UjA9479uOME3KUOJxFAfwO/B++VYqEHOLDKcK7vAr4RS6 ES8aIMWrIF1XzhmqDfH73HZeWjx1xgAgTURet51w4oAq+Ub+4kEi9J6p13nynYYYDU+d ZbhqxQ9oE5PZGB7xICwuh3sBRhmLBTl1XVXzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727253789; x=1727858589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OIoU0qLfgLq7otbwa+2RabVnL5gbGYSnBya+EH+CZUc=; b=BqBPR6tvGF7RPM3hbGN1NMv9DztuIFizFzyQb5Ris6RJRlm+pAiVBIS8Uj4fHgwIQx H0xOg/9JQUXvGDa/PpUmCGymehPHqEUaJpjeAdVal7Ev9325CkZa6FmP1LxxVb74kFbT 8AC17Ke5qAiJPr6aHFtjQDgOIV18/bWBrfChjMvCPbs5hpDIjDdzIDT4zB88tRTH4cU9 NRG8GniCKcZJRHKLOueasrLvNeGyi5X73r+51DcxddGP25jiZJYgP+G5at/zRqXGRY9V 5Yd8DKuzQu4VVLKAGgg9EKXlzIpMBU31mfDnzdzOB9g/GmrshFHJZaFhqojQW5Fa78E9 t12g== X-Gm-Message-State: AOJu0YwBdSd7zuMnhekvpMv9bXsyc3bV2YZo0Jiun/9PKkCVQUBqCIXG X5C6kRBzYxlTdPvoENKF9dqcs1LditlqDeWcfN7ES6HmHH/iwYZ/MyDXgOKZbybNC5/eGaNjiM8 4 X-Google-Smtp-Source: AGHT+IGAJxXrOJKWWYE++Az9EmNjRFtYtY10OTMbUrs4O6zomSSaPkMP+kehHNh2F/62zfuytT44Ig== X-Received: by 2002:a05:6512:a8d:b0:536:53e3:feae with SMTP id 2adb3069b0e04-5387048a6cbmr1383668e87.11.1727253789227; Wed, 25 Sep 2024 01:43:09 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Ross Lagerwall Subject: [PATCH v2 5/6] x86/alternatives: do not BUG during apply Date: Wed, 25 Sep 2024 10:42:38 +0200 Message-ID: <20240925084239.85649-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240925084239.85649-1-roger.pau@citrix.com> References: <20240925084239.85649-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1727253818291116600 alternatives is used both at boot time, and when loading livepatch payloads. While for the former it makes sense to panic, it's not useful for the later= , as for livepatches it's possible to fail to load the livepatch if alternatives cannot be resolved and continue operating normally. Relax the BUGs in _apply_alternatives() to instead return an error code. T= he caller will figure out whether the failures are fatal and panic. Print an error message to provide some user-readable information about what went wrong. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v1: - Unconditionally return from _apply_alternative() and let the caller panic if required. - Remove test, as next patch imposes restrictions that break the test. --- xen/arch/x86/alternative.c | 46 ++++++++++++++++++++------ xen/arch/x86/include/asm/alternative.h | 2 +- xen/common/livepatch.c | 10 +++++- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index 7824053c9d33..c8848ba6006e 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -175,9 +175,9 @@ extern void *const __initdata_cf_clobber_end[]; * invocation, such that no CALLs/JMPs to NULL pointers will be left * around. See also the further comment below. */ -static void init_or_livepatch _apply_alternatives(struct alt_instr *start, - struct alt_instr *end, - bool force) +static int init_or_livepatch _apply_alternatives(struct alt_instr *start, + struct alt_instr *end, + bool force) { struct alt_instr *a, *base; =20 @@ -198,9 +198,29 @@ static void init_or_livepatch _apply_alternatives(stru= ct alt_instr *start, uint8_t buf[MAX_PATCH_LEN]; unsigned int total_len =3D a->orig_len + a->pad_len; =20 - BUG_ON(a->repl_len > total_len); - BUG_ON(total_len > sizeof(buf)); - BUG_ON(a->cpuid >=3D NCAPINTS * 32); + if ( a->repl_len > total_len ) + { + printk(XENLOG_ERR + "alt replacement size (%#x) bigger than destination (%#= x)\n", + a->repl_len, total_len); + return -ENOSPC; + } + + if ( total_len > sizeof(buf) ) + { + printk(XENLOG_ERR + "alt destination size (%#x) bigger than buffer (%#zx)\n= ", + total_len, sizeof(buf)); + return -ENOSPC; + } + + if ( a->cpuid >=3D NCAPINTS * 32 ) + { + printk(XENLOG_ERR + "alt CPU feature (%#x) outside of featureset range (%#x= )\n", + a->cpuid, NCAPINTS * 32); + return -ERANGE; + } =20 /* * Detect sequences of alt_instr's patching the same origin site, = and @@ -356,12 +376,14 @@ static void init_or_livepatch _apply_alternatives(str= uct alt_instr *start, =20 printk("altcall: Optimised away %u endbr64 instructions\n", clobbe= red); } + + return 0; } =20 #ifdef CONFIG_LIVEPATCH -void apply_alternatives(struct alt_instr *start, struct alt_instr *end) +int apply_alternatives(struct alt_instr *start, struct alt_instr *end) { - _apply_alternatives(start, end, true); + return _apply_alternatives(start, end, true); } #endif =20 @@ -383,6 +405,8 @@ static int __init cf_check nmi_apply_alternatives( */ if ( !(alt_done & alt_todo) ) { + int rc; + /* * Relax perms on .text to be RWX, so we can modify them. * @@ -394,8 +418,10 @@ static int __init cf_check nmi_apply_alternatives( PAGE_HYPERVISOR_RWX); flush_local(FLUSH_TLB_GLOBAL); =20 - _apply_alternatives(__alt_instructions, __alt_instructions_end, - alt_done); + rc =3D _apply_alternatives(__alt_instructions, __alt_instructions_= end, + alt_done); + if ( rc ) + panic("Unable to apply alternatives: %d\n", rc); =20 /* * Reinstate perms on .text to be RX. This also cleans out the di= rty diff --git a/xen/arch/x86/include/asm/alternative.h b/xen/arch/x86/include/= asm/alternative.h index a86eadfaecbd..69555d781ef9 100644 --- a/xen/arch/x86/include/asm/alternative.h +++ b/xen/arch/x86/include/asm/alternative.h @@ -24,7 +24,7 @@ struct __packed alt_instr { =20 extern void add_nops(void *insns, unsigned int len); /* Similar to alternative_instructions except it can be run with IRQs enab= led. */ -extern void apply_alternatives(struct alt_instr *start, struct alt_instr *= end); +extern int apply_alternatives(struct alt_instr *start, struct alt_instr *e= nd); extern void alternative_instructions(void); extern void alternative_branches(void); =20 diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 895c425cd5ea..c777f64d88d4 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -896,7 +896,15 @@ static int prepare_payload(struct payload *payload, return -EINVAL; } } - apply_alternatives(start, end); + + rc =3D apply_alternatives(start, end); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH "%s applying alternatives failed: = %d\n", + elf->name, rc); + return rc; + } + alt_done:; #else printk(XENLOG_ERR LIVEPATCH "%s: We don't support alternative patc= hing\n", --=20 2.46.0 From nobody Sat Dec 21 13:48:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1727253814; cv=none; d=zohomail.com; s=zohoarc; b=U/Vf61iGqCdf8vQXCkotS7L1n9jtN4sHVkvcEffWnVw03f9PhLCSSDzlFtznJa6hc62B0/QAayOFeiNIJQcO4Co64zE4dxud1pnXEpzEWilApgx//lh00z7hL7DxAJg/jx/GixBxSOdq3xt6+hGqfpu0IATu8+QRudvTEKATgPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727253814; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rrbFrcCzYWqGSlmqm3wvIVsZFjBZlvkit6WWzCebR78=; b=YdHKDq8BnX/r0w425zv5mND7LmzSvDPRAkQwWD7SAZi8aZlSUcQt2WBzgnnXlxx+8ICECg3D3K6Eji0YcCTxohka3UFWq2TpG0saeRm8eId8jJl8Uv09PIfJPZKQwjfpa4nFmXtEQQyh0rjaVsUGenCjxXgYfKE2AoEUqf9bRYk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727253814594712.658006073868; Wed, 25 Sep 2024 01:43:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803578.1214289 (Exim 4.92) (envelope-from ) id 1stNc9-0006uZ-7t; Wed, 25 Sep 2024 08:43:13 +0000 Received: by outflank-mailman (output) from mailman id 803578.1214289; Wed, 25 Sep 2024 08:43:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc9-0006u6-3w; Wed, 25 Sep 2024 08:43:13 +0000 Received: by outflank-mailman (input) for mailman id 803578; Wed, 25 Sep 2024 08:43:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stNc8-0005cc-9Y for xen-devel@lists.xenproject.org; Wed, 25 Sep 2024 08:43:12 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3261813b-7b1a-11ef-a0ba-8be0dac302b0; Wed, 25 Sep 2024 10:43:11 +0200 (CEST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-53655b9bbcdso7758254e87.2 for ; Wed, 25 Sep 2024 01:43:11 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf49dd5asm1622425a12.54.2024.09.25.01.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 01:43:10 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3261813b-7b1a-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1727253790; x=1727858590; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rrbFrcCzYWqGSlmqm3wvIVsZFjBZlvkit6WWzCebR78=; b=h5EDLLBWm3irhhH5RwI9Ay1w4no/akJzdHNv0Txoq0BOQ4Zl2ya8rNe5lpcyXmCuZx eVG7bYrKov7Am3LKeGYKspKLod5L+nTUIW52aBK15YKH4Lci4ben1FcRZxhVvm5M6FPo Harzt0sdPBn8KNN0KBtTIbzd/6eu2HTQUJ358= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727253790; x=1727858590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rrbFrcCzYWqGSlmqm3wvIVsZFjBZlvkit6WWzCebR78=; b=MFCQnAEAGWXNJEJERBmDsdWYvvcc1gxR3nLzbgPyZFom7DesaVNIY4fManGHlt8CLT EW9EDZL8xH1M0reXKeF9BC8C5F0zJtDUZui8EChPsSlLfFjRVy/wiknqN/oqBpvW84hS Vw7XEaPTyywqX0DX2EN0A0q5Zh14hTEG3hELoWELiMDxZW4arVj454h1uZTrKP5/IHsR AktUNpv+Ap8+qcXmAvSWqmGfxwAt9wA0xM4FOQ/GkJ4h71JVzHpFzpEc2OKE7M0uJ2A/ XhHpJBQ8BtJjkKpWquZAfDdhyF89wR7pPJygocx9k20D97yvsUV/RVwv3mN8GGhPq7X7 UkAQ== X-Gm-Message-State: AOJu0YzJmqBoi6WJ6LlwBsNeYD2iqB+4NTgAVow7D1oPFLEX7CITOi54 NZGpCU7GlNt1H+Re7MW7JmCoENd69Uo/TSVI6chNzmywC4/NPFunh3GZ9eunIxZnyBnBEuxu5sc D X-Google-Smtp-Source: AGHT+IF4iBlhUrjeezjidJmN8G+fTE1LWrk+c4d+nA9SwONISctrd7n8uEp8ZsmksdKzywULm6KjSA== X-Received: by 2002:a05:6512:318c:b0:536:542d:d7e8 with SMTP id 2adb3069b0e04-5387048ad56mr1099902e87.8.1727253790416; Wed, 25 Sep 2024 01:43:10 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 6/6] x86/alternative: build time check feature is in range Date: Wed, 25 Sep 2024 10:42:39 +0200 Message-ID: <20240925084239.85649-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240925084239.85649-1-roger.pau@citrix.com> References: <20240925084239.85649-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1727253816213116600 Ensure at build time the feature(s) used for the alternative blocks are in range of the featureset. No functional change intended, as all current usages are correct. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v1: - New in this version. --- xen/arch/x86/include/asm/alternative-asm.h | 3 +++ xen/arch/x86/include/asm/alternative.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/xen/arch/x86/include/asm/alternative-asm.h b/xen/arch/x86/incl= ude/asm/alternative-asm.h index 4092f5ba70a6..83e8594f0eaf 100644 --- a/xen/arch/x86/include/asm/alternative-asm.h +++ b/xen/arch/x86/include/asm/alternative-asm.h @@ -12,6 +12,9 @@ * instruction. See apply_alternatives(). */ .macro altinstruction_entry orig, repl, feature, orig_len, repl_len, pad_l= en + .if \feature >=3D NCAPINTS * 32 + .error "alternative feature outside of featureset range" + .endif .long \orig - . .long \repl - . .word \feature diff --git a/xen/arch/x86/include/asm/alternative.h b/xen/arch/x86/include/= asm/alternative.h index 69555d781ef9..b7f155994b2c 100644 --- a/xen/arch/x86/include/asm/alternative.h +++ b/xen/arch/x86/include/asm/alternative.h @@ -7,6 +7,7 @@ #include #include #include +#include =20 struct __packed alt_instr { int32_t orig_offset; /* original instruction */ @@ -59,6 +60,9 @@ extern void alternative_branches(void); alt_repl_len(n2)) "-" alt_orig_len) =20 #define ALTINSTR_ENTRY(feature, num) \ + " .if " __stringify(feature) " >=3D " __stringify(NCAPINTS * 32) "= \n"\ + " .error \"alternative feature outside of featureset range\"\n" \ + " .endif\n" \ " .long .LXEN%=3D_orig_s - .\n" /* label */ \ " .long " alt_repl_s(num)" - .\n" /* new instruction */ \ " .word " __stringify(feature) "\n" /* feature bit */ \ --=20 2.46.0