From nobody Sun May 19 07:16:26 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=1713878020; cv=none; d=zohomail.com; s=zohoarc; b=U13scho0AX/9t0kfA94QvyWRrPs7u35Hd66hJozVT53FqwetD2S2HkhK/bPDcTy3SkMG8gC7jNwQF/01lnQxTtWM3peSu5TJ+JVxKmfAaSruPNPiIjYirjkRFqZ6K5l4CSZc2qx/yMmuHdGOTg7FvUZhdK6rv2aqJrtJficyC9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713878020; 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=AWzQEAY3+mRxGCxTU/L7ZP7N4fVla4pSUQMtUwXNBIc=; b=Pm6d31Apvt54P1tDZzKk9CKcPwKgvsfQU53vBlWMTolCH4G7jePGwbsus5OcNs3wcLtRcAPDIJ8XUoTq6zCa0JrwC+lRO+h4EaVlyMpnEMtxK/VDlwHHPUy6bhXEBGYue70H9CooaF82xR9dy76+FKZvrPHLeCrw98rxD2deKRA= 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 1713878020235432.88327963885604; Tue, 23 Apr 2024 06:13:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.710598.1109889 (Exim 4.92) (envelope-from ) id 1rzFxa-0001fL-5g; Tue, 23 Apr 2024 13:13:22 +0000 Received: by outflank-mailman (output) from mailman id 710598.1109889; Tue, 23 Apr 2024 13:13:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzFxa-0001fC-2W; Tue, 23 Apr 2024 13:13:22 +0000 Received: by outflank-mailman (input) for mailman id 710598; Tue, 23 Apr 2024 13:13:20 +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 1rzFxY-0001Ql-Cg for xen-devel@lists.xenproject.org; Tue, 23 Apr 2024 13:13:20 +0000 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [2607:f8b0:4864:20::829]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 40d951de-0173-11ef-909a-e314d9c70b13; Tue, 23 Apr 2024 15:13:19 +0200 (CEST) Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-434b7ab085fso50736251cf.1 for ; Tue, 23 Apr 2024 06:13:19 -0700 (PDT) Received: from localhost ([213.195.114.223]) by smtp.gmail.com with ESMTPSA id k9-20020ae9f109000000b0078ede0c25b5sm5234661qkg.23.2024.04.23.06.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:13:17 -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: 40d951de-0173-11ef-909a-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1713877998; x=1714482798; 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=AWzQEAY3+mRxGCxTU/L7ZP7N4fVla4pSUQMtUwXNBIc=; b=GB51zKb55YPQuBb9qfcLP3xYfJElaUEglftDEjQsm+KEqwhLbX0Q9THXHF8VOKin0b 6rogT6Kf1kJ7CjQmRZgKWlotTCmEhWoKl2kZzAPG+Qy7PRLMPAbtHO92KMEh1s15tp1N 7Q4uaUdKK8MpA1+zweTf0jK4OK17TSAdbP5Dc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713877998; x=1714482798; 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=AWzQEAY3+mRxGCxTU/L7ZP7N4fVla4pSUQMtUwXNBIc=; b=WXkeDnCPYzgj07/MczYV0e2U3P4Ocmd+o1YRdPWoROCPC1oS8uH/savvXCjXZiMqtg ajgyjETfhq3HgZ/0Di3hN2/YggIh4/HDNoqakIDmq+2JE/m/SNEqzvUvzH7lDxiUj+9A CeimAtHjdKCLz5a150RFFx6c2EyDhd+OseOsyigiZeaaGDLAS4T6VSKguHsYOoj+dpuN i2lCK6HnicMx1ZOI1/6utDj+tpFqCYIwYIY5oKjIsMnEm4yL1lwmiBuziNg5Qg2iIIGF XiYZyQR8W2/zivHDT65CttyRwX06zYs95O8/03c321aq0AUCOgD34NDA/YoErmr9MFg2 /gxg== X-Gm-Message-State: AOJu0YwUnnQ9xDTf0JYGjKQVK+mLs+T3W/yzZ/0CJWrNxzJLGZH29ok5 th0GOh4rTb35ZemlGowWZecgnYqwVa6BvmwPNimAnSa37UVou9aIyBBAKfrOLW4uNQagLQDrs1j X X-Google-Smtp-Source: AGHT+IH8/0GmzJT9k5cmoveTat6xn7RbsFozxi2zmE+Id+1FEtfN9/wbYP9a1twjJcLlNGFBULEoJQ== X-Received: by 2002:a05:622a:11c1:b0:439:e95e:5dd0 with SMTP id n1-20020a05622a11c100b00439e95e5dd0mr4185303qtk.1.1713877997922; Tue, 23 Apr 2024 06:13:17 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Ross Lagerwall , Anthony PERARD Subject: [PATCH v3 1/4] xen-livepatch: fix parameter name parsing Date: Tue, 23 Apr 2024 15:12:46 +0200 Message-ID: <20240423131249.29825-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423131249.29825-1-roger.pau@citrix.com> References: <20240423131249.29825-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: 1713878022480100002 It's incorrect to restrict strncmp to the length of the command line input parameter, as then a user passing a rune like: % xen-livepatch up foo.livepatch Would match against the "upload" command, because the string comparison has been truncated to the length of the input argument. Instead the truncation should be done based on the length of the command name stored in the intern= al array of actions. Fixes: 05bb8afedede ('xen-xsplice: Tool to manipulate xsplice payloads') Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v2: - New in this version. --- tools/misc/xen-livepatch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index 5bf9d9a32b65..a246e5dfd38e 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -572,13 +572,15 @@ int main(int argc, char *argv[]) return 0; } for ( i =3D 0; i < ARRAY_SIZE(main_options); i++ ) - if (!strncmp(main_options[i].name, argv[1], strlen(argv[1]))) + if (!strncmp(main_options[i].name, argv[1], + strlen(main_options[i].name))) break; =20 if ( i =3D=3D ARRAY_SIZE(main_options) ) { for ( j =3D 0; j < ARRAY_SIZE(action_options); j++ ) - if (!strncmp(action_options[j].name, argv[1], strlen(argv[1]))) + if (!strncmp(action_options[j].name, argv[1], + strlen(action_options[j].name))) break; =20 if ( j =3D=3D ARRAY_SIZE(action_options) ) --=20 2.44.0 From nobody Sun May 19 07:16:26 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=1713878024; cv=none; d=zohomail.com; s=zohoarc; b=aaWPAoTwbg9eFt7PjFEpTKMJp3MEUyQheW+Og7Cc1KG/6rz59y6JU2dUW3vd+34IG9Mtco7U3Su/c77EgULFHJZslG0r+sBQxpt34cymxaUKjAQRoN6xFuvmRROVHZinoiRDSsveLI//Z0nCXahy/wL0LbLlS0m2ijE6447qgX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713878024; 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=9lVrOUiErpOt1x6JV3axiTLKkLJOBS6S5d/ZUHk5bIc=; b=Lr6c92zRbF52TJu0ITsjoVBD1mxDpg4Gm+vH11OfBa8ulIbN3+pA61WbXElj5seH+Ny74xCO+s2d5uFqNj6lvc9KBAuFEp8r0vg8Cut0jgBIJuMC8CAKXHgqDCdxRws0Ji5QBK39um/qU9gmOJZ12AQbu1klw7XhCsHT8lC5P0o= 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 1713878024285110.18465338790384; Tue, 23 Apr 2024 06:13:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.710599.1109899 (Exim 4.92) (envelope-from ) id 1rzFxb-0001uC-ES; Tue, 23 Apr 2024 13:13:23 +0000 Received: by outflank-mailman (output) from mailman id 710599.1109899; Tue, 23 Apr 2024 13:13:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzFxb-0001u5-AW; Tue, 23 Apr 2024 13:13:23 +0000 Received: by outflank-mailman (input) for mailman id 710599; Tue, 23 Apr 2024 13:13:22 +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 1rzFxa-0001Ql-Rw for xen-devel@lists.xenproject.org; Tue, 23 Apr 2024 13:13:22 +0000 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [2607:f8b0:4864:20::f2e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 42435226-0173-11ef-909a-e314d9c70b13; Tue, 23 Apr 2024 15:13:22 +0200 (CEST) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-69943ef42b2so35071576d6.3 for ; Tue, 23 Apr 2024 06:13:22 -0700 (PDT) Received: from localhost ([213.195.114.223]) by smtp.gmail.com with ESMTPSA id j13-20020a0c9ccd000000b00696ae38c7bfsm1873408qvf.35.2024.04.23.06.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:13:20 -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: 42435226-0173-11ef-909a-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1713878000; x=1714482800; 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=9lVrOUiErpOt1x6JV3axiTLKkLJOBS6S5d/ZUHk5bIc=; b=BnRAAg28kJD6rteH7YK1NqkGnUaajHjAYnaE4CtlzV9DSTqBKFyDDb4l5fgLJxZQrx +uS8SPafIvRHJfnHjUgK7R2Ak23RkD3k4IpXxInLLV/8M/30vD6nn5TozPMT22wXlCPk r+czaBPH+e6pbDOr/EetIuSzrrPHfJ2fpNPDc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713878000; x=1714482800; 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=9lVrOUiErpOt1x6JV3axiTLKkLJOBS6S5d/ZUHk5bIc=; b=d0ZRIUXKLcbHwsdxSlcUrI2RzqC20BwzlC9JKzhycnpErFo8Uu9gUI7C4ETLHHPUnB evCUgoT7/r68wMncgfRsdmoLz/OWhswoTmh5IbniKFpe6J00MpdjT9uGgF9TIFc/egVq kfkQ3gHCEDS5bx1ZiGoDwEHR1rzAXVbC6nF0lGm4XnbYsXr9V3eOWK4BzyBnala/yp9o BS8j+qdWcV8h0Hu5kjT87Sp+FDsl0LoGTQ1gGGv9ZKO59agEHREd84ThBXrRQpmscy75 2cbuBbkdPCldkPWGe3FzhfbEFs8dy7pWxlZWz/NOIbnMgiBbMEi/waar7UihWm+OJ05+ D9SA== X-Gm-Message-State: AOJu0YxirbD6C1xCZttljN5Gesso1RnsWf64koCnC1HTgByrzs3Fldgj l0kiJV8jRsxitl+bSuZQ9sZsCPR3TpH/aXL/42x9GzNE2zJbK7+HMvqAZfY7wXUOgN/ijIiJ4zE k X-Google-Smtp-Source: AGHT+IGbE3VkQVmviVP1Axw9WTZGVRmI92gcwDwQiFszisQYYKjsnxydqejs4/D22QWc6TiW++s36Q== X-Received: by 2002:ad4:44a1:0:b0:6a0:49d5:c4fb with SMTP id n1-20020ad444a1000000b006a049d5c4fbmr13419031qvt.31.1713878000330; Tue, 23 Apr 2024 06:13:20 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Ross Lagerwall Subject: [PATCH v3 2/4] livepatch: introduce --force option Date: Tue, 23 Apr 2024 15:12:47 +0200 Message-ID: <20240423131249.29825-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423131249.29825-1-roger.pau@citrix.com> References: <20240423131249.29825-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: 1713878026321100002 Introduce a xen-livepatch tool --force option, that's propagated into the hyerpvisor for livepatch operations. The intention is for the option to be used to bypass some checks that would otherwise prevent the patch from being loaded. Re purpose the pad field in xen_sysctl_livepatch_op to be a flags field that applies to all livepatch operations. The flag is currently only set by the hypercall wrappers for the XEN_SYSCTL_LIVEPATCH_UPLOAD operation, as that's= so far the only one where it will be used initially. Other uses can be added = as required. Note that helpers would set the .pad field to 0, that's been removed since = the structure is already zero initialized at definition. No functional usages of the new flag introduced in this patch. Signed-off-by: Roger Pau Monn=C3=A9 Acked-by: Anthony PERARD Acked-by: Jan Beulich --- Changes since v2: - New in this version. --- tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 7 +++---- tools/misc/xen-livepatch.c | 21 +++++++++++++++++++-- xen/common/livepatch.c | 3 ++- xen/include/public/sysctl.h | 4 +++- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e05422..499685594427 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2555,7 +2555,8 @@ int xc_psr_get_hw_info(xc_interface *xch, uint32_t so= cket, #endif =20 int xc_livepatch_upload(xc_interface *xch, - char *name, unsigned char *payload, uint32_t size); + char *name, unsigned char *payload, uint32_t size, + bool force); =20 int xc_livepatch_get(xc_interface *xch, char *name, diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c index 5ecdfa2c7934..50282fd60dcc 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -576,7 +576,8 @@ int xc_getcpuinfo(xc_interface *xch, int max_cpus, int xc_livepatch_upload(xc_interface *xch, char *name, unsigned char *payload, - uint32_t size) + uint32_t size, + bool force) { int rc; struct xen_sysctl sysctl =3D {}; @@ -612,7 +613,7 @@ int xc_livepatch_upload(xc_interface *xch, =20 sysctl.cmd =3D XEN_SYSCTL_livepatch_op; sysctl.u.livepatch.cmd =3D XEN_SYSCTL_LIVEPATCH_UPLOAD; - sysctl.u.livepatch.pad =3D 0; + sysctl.u.livepatch.flags =3D force ? LIVEPATCH_FLAG_FORCE : 0; sysctl.u.livepatch.u.upload.size =3D size; set_xen_guest_handle(sysctl.u.livepatch.u.upload.payload, local); =20 @@ -656,7 +657,6 @@ int xc_livepatch_get(xc_interface *xch, =20 sysctl.cmd =3D XEN_SYSCTL_livepatch_op; sysctl.u.livepatch.cmd =3D XEN_SYSCTL_LIVEPATCH_GET; - sysctl.u.livepatch.pad =3D 0; =20 sysctl.u.livepatch.u.get.status.state =3D 0; sysctl.u.livepatch.u.get.status.rc =3D 0; @@ -985,7 +985,6 @@ static int _xc_livepatch_action(xc_interface *xch, =20 sysctl.cmd =3D XEN_SYSCTL_livepatch_op; sysctl.u.livepatch.cmd =3D XEN_SYSCTL_LIVEPATCH_ACTION; - sysctl.u.livepatch.pad =3D 0; sysctl.u.livepatch.u.action.cmd =3D action; sysctl.u.livepatch.u.action.timeout =3D timeout; sysctl.u.livepatch.u.action.flags =3D flags; diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index a246e5dfd38e..cf2e5fada12d 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -19,11 +19,15 @@ =20 static xc_interface *xch; =20 +/* Global option to disable checks. */ +static bool force; + void show_help(void) { fprintf(stderr, "xen-livepatch: live patching tool\n" - "Usage: xen-livepatch [args] [command-flags]\n" + "Usage: xen-livepatch [--force] [args] [command-flag= s]\n" + " Use --force option to bypass some checks.\n" " An unique name of payload. Up to %d characters.\n" "Commands:\n" " help display this help\n" @@ -240,7 +244,7 @@ static int upload_func(int argc, char *argv[]) return saved_errno; } printf("Uploading %s... ", filename); - rc =3D xc_livepatch_upload(xch, name, fbuf, len); + rc =3D xc_livepatch_upload(xch, name, fbuf, len, force); if ( rc ) { rc =3D errno; @@ -571,6 +575,19 @@ int main(int argc, char *argv[]) show_help(); return 0; } + + if ( !strncmp("--force", argv[1], strlen("--force")) ) + { + if ( argc <=3D 2 ) + { + show_help(); + return EXIT_FAILURE; + } + force =3D true; + argv++; + argc--; + } + for ( i =3D 0; i < ARRAY_SIZE(main_options); i++ ) if (!strncmp(main_options[i].name, argv[1], strlen(main_options[i].name))) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 351a3e0b9a60..1503a84457e4 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -2125,7 +2125,8 @@ int livepatch_op(struct xen_sysctl_livepatch_op *live= patch) { int rc; =20 - if ( livepatch->pad ) + if ( livepatch->flags & ~LIVEPATCH_FLAGS_MASK && + !(livepatch->flags & LIVEPATCH_FLAG_FORCE) ) return -EINVAL; =20 switch ( livepatch->cmd ) diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 9b19679caeb1..febaa4b16ab7 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1139,7 +1139,9 @@ struct xen_sysctl_livepatch_action { =20 struct xen_sysctl_livepatch_op { uint32_t cmd; /* IN: XEN_SYSCTL_LIVEPATCH_*.= */ - uint32_t pad; /* IN: Always zero. */ + uint32_t flags; /* IN, flags. */ +#define LIVEPATCH_FLAG_FORCE (1u << 0) /* Skip some checks. */ +#define LIVEPATCH_FLAGS_MASK LIVEPATCH_FLAG_FORCE union { struct xen_sysctl_livepatch_upload upload; struct xen_sysctl_livepatch_list list; --=20 2.44.0 From nobody Sun May 19 07:16:26 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=1713878025; cv=none; d=zohomail.com; s=zohoarc; b=AwCoU15SG7bwcujprwjI47srryaWIUAsHp4SBVd/2hbGkcaI+tkAGMTzy8b+9yzxRJJTiWXynn8CXPjvuQ+VsGPy20bkvOCkS9fo/DZKdE6UJwP4w7cKNjD8HN4inkC0o50BdYCuglnNQu2++KObEUDezsxKtKCaHwxpok/fnT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713878025; 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=zAW+pmvPvQM6t7OJF1VqQVrXJwKICgDo4XoYwqWkiAY=; b=CeViQ3HrPjQK2jPzTM5voihiTHzyEl2HrOkHfU5R3fHsT5ecMnJHIcP5dOPTycijZc4v0xXnFuekcDTEHCxGkL9El5hBwtftiG404uuOQYpUQ5EsDaBCFDeueAhhvlvOOUT4b6JgbFBG4XttX6JMgqguL4as98OI1ugtsghH6Rg= 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 1713878025901831.1709115381699; Tue, 23 Apr 2024 06:13:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.710600.1109908 (Exim 4.92) (envelope-from ) id 1rzFxg-0002Dw-Lb; Tue, 23 Apr 2024 13:13:28 +0000 Received: by outflank-mailman (output) from mailman id 710600.1109908; Tue, 23 Apr 2024 13:13:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzFxg-0002Dl-Ix; Tue, 23 Apr 2024 13:13:28 +0000 Received: by outflank-mailman (input) for mailman id 710600; Tue, 23 Apr 2024 13:13:27 +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 1rzFxf-0002Bv-PI for xen-devel@lists.xenproject.org; Tue, 23 Apr 2024 13:13:27 +0000 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [2607:f8b0:4864:20::f2c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 43cd262a-0173-11ef-b4bb-af5377834399; Tue, 23 Apr 2024 15:13:24 +0200 (CEST) Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-6a06b12027cso29247336d6.0 for ; Tue, 23 Apr 2024 06:13:24 -0700 (PDT) Received: from localhost ([213.195.114.223]) by smtp.gmail.com with ESMTPSA id w9-20020a0ca809000000b00696b1050be8sm4054360qva.133.2024.04.23.06.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:13:22 -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: 43cd262a-0173-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1713878003; x=1714482803; 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=zAW+pmvPvQM6t7OJF1VqQVrXJwKICgDo4XoYwqWkiAY=; b=Fkw0k+NtCTDpYMDw254y1OnrywcJt63/iu4Zgd7SkjzhgiMga/IzQsK5u/qhiGEMge X5TXlJqPXr5erXpGt3KCS8THf2Pxs1IC+8Zy1XsfdP+sFB6M9fH/HhlSFhH8E4K4T6TJ P7biJaqgCtBKlnnuwuCbLzyEqrYv+zCz4BrI8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713878003; x=1714482803; 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=zAW+pmvPvQM6t7OJF1VqQVrXJwKICgDo4XoYwqWkiAY=; b=UWrzg56NATDdCFABrFQfCwyEClR674fjEBeVdOT7mCIJKT6Cr1n3N9dP9iJAbidlaS bCc+YbPiR1umaNDj6uDUoXjLfdwM3MFZEXIRbBPEfmuQkx44ML+PbRJDKYb9+Ci3sIkp WpRnjD5RZ93fRbJu89wvOnr9nCEzsnPKR174AwYJ3MM4ZI/b5Cw2PAGrZeZ2Gjr8nKeB IBCy9mr7/cr9Vj2Jwc9rxZgLs1YcHJqmoO0gX7qhhI25uxLMhYz8zyvRAjwgC73v3+p1 a/uIAgeM0gC+duLdKgQvhcH6q2pfJiy4d+qBKhaLt+P2akPxbjxLtaLoGi511VLrgk8s 5Dog== X-Gm-Message-State: AOJu0YzWPt4yA0PV0twWmrGolB1xiHb0gQt91MBycJ2hXynjCozIxOiP JB0cLh0yo7pjizqSn5ia3qxhJv90JSjvow4C5WJ9NRV182bLztwnNcb3mPjE+tU3LsP/VNyPvGe u X-Google-Smtp-Source: AGHT+IF/pz23x1VIORoM+H0lMBL+JfXwTpozuDwRz/BpbBd0BgcVEMlCQZbSMNrneqacUV4Xff7xxg== X-Received: by 2002:ad4:5aa3:0:b0:69c:b559:547d with SMTP id u3-20020ad45aa3000000b0069cb559547dmr4971963qvg.25.1713878002905; Tue, 23 Apr 2024 06:13:22 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Ross Lagerwall Subject: [PATCH v3 3/4] livepatch: refuse to resolve symbols that belong to init sections Date: Tue, 23 Apr 2024 15:12:48 +0200 Message-ID: <20240423131249.29825-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423131249.29825-1-roger.pau@citrix.com> References: <20240423131249.29825-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: 1713878026309100001 Livepatch payloads containing symbols that belong to init sections can only lead to page faults later on, as by the time the livepatch is loaded init sections have already been freed. Refuse to resolve such symbols and return an error instead. Note such resolutions are only relevant for symbols that point to undefined sections (SHN_UNDEF), as that implies the symbol is not in the current payl= oad and hence must either be a Xen or a different livepatch payload symbol. Do not allow to resolve symbols that point to __init_begin, as that address= is also unmapped. On the other hand, __init_end is not unmapped, and hence al= low resolutions against it. Since __init_begin can alias other symbols (like _erodata for example) allow the force flag to override the check and resolve the symbol anyway. Signed-off-by: Roger Pau Monn=C3=A9 Acked-by: Jan Beulich --- Changes since v2: - Allow bypassing added check with the force flag. Changes since v1: - Fix off-by-one in range checking. --- xen/common/livepatch.c | 13 ++++++++----- xen/common/livepatch_elf.c | 18 +++++++++++++++++- xen/include/xen/livepatch_elf.h | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 1503a84457e4..36cf4bee8b8a 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1080,7 +1080,8 @@ static void free_payload(struct payload *data) xfree(data); } =20 -static int load_payload_data(struct payload *payload, void *raw, size_t le= n) +static int load_payload_data(struct payload *payload, void *raw, size_t le= n, + bool force) { struct livepatch_elf elf =3D { .name =3D payload->name, .len =3D len }; int rc =3D 0; @@ -1093,7 +1094,7 @@ static int load_payload_data(struct payload *payload,= void *raw, size_t len) if ( rc ) goto out; =20 - rc =3D livepatch_elf_resolve_symbols(&elf); + rc =3D livepatch_elf_resolve_symbols(&elf, force); if ( rc ) goto out; =20 @@ -1133,7 +1134,8 @@ static int load_payload_data(struct payload *payload,= void *raw, size_t len) return rc; } =20 -static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload) +static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload, + bool force) { struct payload *data, *found; char n[XEN_LIVEPATCH_NAME_SIZE]; @@ -1162,7 +1164,7 @@ static int livepatch_upload(struct xen_sysctl_livepat= ch_upload *upload) { memcpy(data->name, n, strlen(n)); =20 - rc =3D load_payload_data(data, raw_data, upload->size); + rc =3D load_payload_data(data, raw_data, upload->size, force); if ( rc ) goto out; =20 @@ -2132,7 +2134,8 @@ int livepatch_op(struct xen_sysctl_livepatch_op *live= patch) switch ( livepatch->cmd ) { case XEN_SYSCTL_LIVEPATCH_UPLOAD: - rc =3D livepatch_upload(&livepatch->u.upload); + rc =3D livepatch_upload(&livepatch->u.upload, + livepatch->flags & LIVEPATCH_FLAG_FORCE); break; =20 case XEN_SYSCTL_LIVEPATCH_GET: diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c index 45d73912a3cd..0436f2d5fcbd 100644 --- a/xen/common/livepatch_elf.c +++ b/xen/common/livepatch_elf.c @@ -4,6 +4,7 @@ =20 #include #include +#include #include #include #include @@ -276,7 +277,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const= void *data) return 0; } =20 -int livepatch_elf_resolve_symbols(struct livepatch_elf *elf) +int livepatch_elf_resolve_symbols(struct livepatch_elf *elf, bool force) { unsigned int i; int rc =3D 0; @@ -310,6 +311,21 @@ int livepatch_elf_resolve_symbols(struct livepatch_elf= *elf) break; } } + + /* + * Ensure not an init symbol. Only applicable to Xen symbols,= as + * livepatch payloads don't have init sections or equivalent. + */ + else if ( st_value >=3D (uintptr_t)&__init_begin && + st_value < (uintptr_t)&__init_end && !force ) + { + printk(XENLOG_ERR LIVEPATCH + "%s: symbol %s is in init section, not resolving\n", + elf->name, elf->sym[i].name); + rc =3D -ENXIO; + break; + } + dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Undefined symbol resolved= : %s =3D> %#"PRIxElfAddr"\n", elf->name, elf->sym[i].name, st_value); break; diff --git a/xen/include/xen/livepatch_elf.h b/xen/include/xen/livepatch_el= f.h index 7116deaddc28..84e9c5eb7be5 100644 --- a/xen/include/xen/livepatch_elf.h +++ b/xen/include/xen/livepatch_elf.h @@ -44,7 +44,7 @@ livepatch_elf_sec_by_name(const struct livepatch_elf *elf, int livepatch_elf_load(struct livepatch_elf *elf, const void *data); void livepatch_elf_free(struct livepatch_elf *elf); =20 -int livepatch_elf_resolve_symbols(struct livepatch_elf *elf); +int livepatch_elf_resolve_symbols(struct livepatch_elf *elf, bool force); int livepatch_elf_perform_relocs(struct livepatch_elf *elf); =20 static inline bool livepatch_elf_ignore_section(const Elf_Shdr *sec) --=20 2.44.0 From nobody Sun May 19 07:16:26 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=1713878030; cv=none; d=zohomail.com; s=zohoarc; b=aY6EG6RKptQR6tcj640lB6xkkrT8h7LsNyBXiG6yO8B6Tx0+5GxnNS+ypk1f9ukvryPYy6ei4YkmTl8I+mIEPZz51AkAbhrQ7uPheKwGDXUJGjxxw0LmLC8VDIw3+HC0zabDyH1cFRZpQYgAiIMe7KwQdSdmnA1msYulFiVfoIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713878030; 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=ltxaBFTJztn56Gj0rvozRmGOtEvpUWdcCGzbpKGl1aA=; b=ekXk/6LITFbTcIGAc+8k2hulAjmqosocU+QZ4zi8rLPzoS33LcfwRHjIv2YtKVniYYwsdzTsxl5ZE+S+09gTDW/VLRj62JqCTE1qwePBCwC1jCYkPu+/UJyt7glPBQPZwM9SFOTgIm1m0+ZN8BNV1aMakz6J6XWZmK5gNGNEdUc= 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 1713878030068947.7916450181293; Tue, 23 Apr 2024 06:13:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.710601.1109919 (Exim 4.92) (envelope-from ) id 1rzFxh-0002Tu-Vy; Tue, 23 Apr 2024 13:13:29 +0000 Received: by outflank-mailman (output) from mailman id 710601.1109919; Tue, 23 Apr 2024 13:13:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzFxh-0002Tl-SV; Tue, 23 Apr 2024 13:13:29 +0000 Received: by outflank-mailman (input) for mailman id 710601; Tue, 23 Apr 2024 13:13:28 +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 1rzFxg-0002Bv-L1 for xen-devel@lists.xenproject.org; Tue, 23 Apr 2024 13:13:28 +0000 Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [2001:4860:4864:20::32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4515543e-0173-11ef-b4bb-af5377834399; Tue, 23 Apr 2024 15:13:27 +0200 (CEST) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-23319017c4cso3589291fac.2 for ; Tue, 23 Apr 2024 06:13:27 -0700 (PDT) Received: from localhost ([213.195.114.223]) by smtp.gmail.com with ESMTPSA id wl20-20020a05620a57d400b0078ec846066fsm5232607qkn.7.2024.04.23.06.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:13:24 -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: 4515543e-0173-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1713878005; x=1714482805; 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=ltxaBFTJztn56Gj0rvozRmGOtEvpUWdcCGzbpKGl1aA=; b=U5ELi145Z1UiFRwVOAxeZOOJKZnpHqSdUteUZ0h/D5mFtDhHW4dv2k1xY8Z/ALuKVQ zA1/0pgZMiMRbhMwZZSJz047aL90qUB5qaisf9VPs59lu7vGKNo1RGInQJ8vF7E1Vykn zqPfuKl23zQJDy21W9O4KpxQP/hHG2fWltBMM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713878005; x=1714482805; 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=ltxaBFTJztn56Gj0rvozRmGOtEvpUWdcCGzbpKGl1aA=; b=TpVlxLHAMAE8XBjH3LMXtPcS1+niv38Cq4IuwrOb4pIeZ8pSMQp8dAfEQWjDBbsrnx INauZB2ROumOWcNlwtQwSvj7j0oAd7BcEqWw5ojU2n8wZ1stYyeqU4CuoTN6RP23fNAK WwmkmZ1SLkzfnxpGqH1t9ymv/xFRQLVO1Mt6IDsrGAFbs6LAQliwFzrpwTZw/szs4hG/ tOTGo+8JK72yV5wbAE5swcvJwbAHzCP9K/xftCP/Qj0FdbUAFRQp6LoOPRYlmbVcq/D8 epw3ZwSn3ZlrQo38ibbPbwdmwWNmpzTk1F7Cag1hXa9xpCQRZJga0wL0VpxfsmnmyLhX 5v3A== X-Gm-Message-State: AOJu0YxrGZSPDH/RPFm1uoq2yTrEXbkcZCiog9krecbEVz85gaxGZg+8 otkcSfDI8v9D02M68pHxc3HYGYxwfYpxrdLxmyKvueTl93MfyAhFX5ylzld3dUM2zNmMgOBeXPh x X-Google-Smtp-Source: AGHT+IGzgYuYJsC+Pa5n306mOLAuD9o831fD7pohs4qVzhEmBwNtlnur1k4ygK0/dzHUTAI7xP9zBQ== X-Received: by 2002:a05:6870:4309:b0:22e:9125:eade with SMTP id w9-20020a056870430900b0022e9125eademr16010630oah.44.1713878005051; Tue, 23 Apr 2024 06:13:25 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Ross Lagerwall Subject: [PATCH v3 4/4] x86/livepatch: perform sanity checks on the payload exception table contents Date: Tue, 23 Apr 2024 15:12:49 +0200 Message-ID: <20240423131249.29825-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423131249.29825-1-roger.pau@citrix.com> References: <20240423131249.29825-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: 1713878030395100001 Ensure the entries of a payload exception table only apply to text regions = in the payload itself. Since the payload exception table needs to be loaded a= nd active even before a patch is applied (because hooks might already rely on = it), make sure the exception table (if any) only contains fixups for the payload text section. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v2: - New in this version. --- xen/arch/x86/extable.c | 18 ++++++++++++++++++ xen/arch/x86/include/asm/uaccess.h | 4 ++++ xen/common/livepatch.c | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index 8415cd1fa249..9e91e8234e71 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -228,3 +228,21 @@ unsigned long asmlinkage search_pre_exception_table(st= ruct cpu_user_regs *regs) } return fixup; } + +#ifdef CONFIG_LIVEPATCH +bool extable_is_between_bounds(const struct exception_table_entry *ex_star= t, + const struct exception_table_entry *ex_end, + const void *start, const void *end) +{ + for ( ; ex_start < ex_end; ex_start++ ) + { + const void *addr =3D (void *)ex_addr(ex_start); + const void *cont =3D (void *)ex_cont(ex_start); + + if ( addr < start || addr >=3D end || cont < start || cont >=3D en= d ) + return false; + } + + return true; +} +#endif diff --git a/xen/arch/x86/include/asm/uaccess.h b/xen/arch/x86/include/asm/= uaccess.h index 48b684c19d44..0dad61e21a9c 100644 --- a/xen/arch/x86/include/asm/uaccess.h +++ b/xen/arch/x86/include/asm/uaccess.h @@ -426,5 +426,9 @@ extern unsigned long search_exception_table(const struc= t cpu_user_regs *regs, extern void sort_exception_tables(void); extern void sort_exception_table(struct exception_table_entry *start, const struct exception_table_entry *stop); +extern bool extable_is_between_bounds( + const struct exception_table_entry *ex_start, + const struct exception_table_entry *ex_end, + const void *start, const void *end); =20 #endif /* __X86_UACCESS_H__ */ diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 36cf4bee8b8a..67b6815d87ac 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -912,6 +912,15 @@ static int prepare_payload(struct payload *payload, s =3D sec->load_addr; e =3D sec->load_addr + sec->sec->sh_size; =20 + if ( !extable_is_between_bounds(s, e, payload->text_addr, + payload->text_addr + payload->text_size) ) + { + printk(XENLOG_ERR LIVEPATCH + "%s: Invalid exception table with out of bounds entries= \n", + elf->name); + return -EINVAL; + } + sort_exception_table(s ,e); =20 region->ex =3D s; --=20 2.44.0