From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596196; cv=none; d=zohomail.com; s=zohoarc; b=Q6mo2lK7JoASfZgDm76SPY4hz/R1gMV992wOzvYNFGQ6+EtWWUmXGs+U+jU2SSF6l301NKLi0ODZa2vGRvZFM9bfQE2Uiloj/g9zFmD1UfuZ3ThO3yNX2T+u4+kUUUYuD+YpIBMvxMqhaZg15zJqEeC5tvvpBN1EGobkC6HUyTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596196; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=m6d++yISFYoabczO21ysTR9r+GhnJXbvqXk0ITsPtjo=; b=Ah9NzPKw8G/oTZv183vPP3oohqB6jPhTJMgm0URdgCJkWgFZv9zspdS9ZeU1LTGrsPQmiNhlxFAdFcMw1ttlMUzjeNBOb0MGNNLJN3JKLSuVLCeGkxEC5BQGiqJH86JMbl1BIUWWlRAdpINcpQf2G+AJMmA0iLfkjKFSceDtfq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596196190668.7920698317726; Mon, 30 Mar 2020 12:23:16 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzz9-0005wt-Up; Mon, 30 Mar 2020 19:22:11 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzz8-0005wo-5k for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:10 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bf42d45a-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:08 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzz5-0003l1-M9; Mon, 30 Mar 2020 19:22:07 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzz5-0007AJ-DC; Mon, 30 Mar 2020 19:22:07 +0000 X-Inumbo-ID: bf42d45a-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=m6d++yISFYoabczO21ysTR9r+GhnJXbvqXk0ITsPtjo=; b=CRq9bVLPhYr/5ywgpu35lYfrCq XihjmGslycLYzQhv117hy3z2K8TYeOD1/D5zjZe1fDtH3qJ0YyTqtTPL0U92tDmU94hdS3kSzhuWx gYQcvWvk5K/6bI1b4fNymdAoOgfxqAoM5FwuuvdQFRneHwNYTG9hWDpGy0DoS2sN+5Kk=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:50 +0100 Message-Id: <20200330192157.1335-2-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 1/8] xen/guest_access: Harden copy_to_guest_offset to prevent const dest operand X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Julien Grall , dfaggioli@suse.com, Jan Beulich , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, copy_to_guest_offset() will allow the hypervisor to copy data to guest handle marked const. Thankfully, no users of the helper will do that. Rather than hoping this can be caught during review, harden copy_to_guest_offset() so the build will fail if such users are introduced. Signed-off-by: Julien Grall Acked-by: Christian Lindig --- xen/include/asm-arm/guest_access.h | 2 +- xen/include/asm-x86/guest_access.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest= _access.h index 8997a1cbfe..ff2eec237d 100644 --- a/xen/include/asm-arm/guest_access.h +++ b/xen/include/asm-arm/guest_access.h @@ -126,7 +126,7 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_= t ipa, void *buf, =20 #define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ const typeof(*(ptr)) *_s =3D (ptr); \ - char (*_d)[sizeof(*_s)] =3D (void *)(hnd).p; \ + typeof(*((hnd).p)) *_d =3D (hnd).p; \ ((void)((hnd).p =3D=3D (ptr))); \ __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\ }) diff --git a/xen/include/asm-x86/guest_access.h b/xen/include/asm-x86/guest= _access.h index ca700c959a..2693c6540b 100644 --- a/xen/include/asm-x86/guest_access.h +++ b/xen/include/asm-x86/guest_access.h @@ -86,7 +86,7 @@ */ #define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ const typeof(*(ptr)) *_s =3D (ptr); \ - char (*_d)[sizeof(*_s)] =3D (void *)(hnd).p; \ + typeof(*((hnd).p)) *_d =3D (hnd).p; \ ((void)((hnd).p =3D=3D (ptr))); \ raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr)); \ }) --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596194; cv=none; d=zohomail.com; s=zohoarc; b=EEQ5UwqVKE4HtaYF9gd2jII70/T6u1RYIlbSOAXVjwqrPu1+QIiJeSh7tr8CQYvuLDtahdWb1aJahFiVS/fOJLNZWbYxqbWvCssH4ZUASvgSwCqHrfN2K9ICgW2tLcl3aMf6HlPHTMZaYdKF+YiZ6KIbAXpWDrljoZl/UmbjwC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596194; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=r3hOtP/jXPcCtes7l0jKraBeKHXjJ8jvdB/4BpY9Tk4=; b=JqHvVDR+P03kIhuxYNcBANhSwvwc/cV+bk9oyqvWeWTOLbOaXOltW5xKgewX4/YangZxxW15HbqaID9+x25U/qpgtpv/KNP8eit78kganbTwsVdoW3AcXD5bchT7cnad4O4XwjRwKvgFogTBlFn2TQjl5iDZWKaf+gXyyINtAL0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158559619416567.75652710577094; Mon, 30 Mar 2020 12:23:14 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzC-0005x8-7X; Mon, 30 Mar 2020 19:22:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzA-0005wz-MD for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:12 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c0b69ec0-72bb-11ea-b4f4-bc764e2007e4; Mon, 30 Mar 2020 19:22:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzz7-0003l9-Aw; Mon, 30 Mar 2020 19:22:09 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzz7-0007AJ-1R; Mon, 30 Mar 2020 19:22:09 +0000 X-Inumbo-ID: c0b69ec0-72bb-11ea-b4f4-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=r3hOtP/jXPcCtes7l0jKraBeKHXjJ8jvdB/4BpY9Tk4=; b=ry2T9/59Z0GKkxLpHpaoeEFpZ0 W/D5IRQopyYOy/39rSCrp8OMSUSkzUuStRSJLmY3/wIRPROLW6F8gc8yzkEGzGDlMnUnyZJnhPfmq D8DDGOQdd1ehyckpg0i7KGsNQdc0Q0A8EKcifa2mITwySHMMWAMlVIe17piHIdupy7x4=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:51 +0100 Message-Id: <20200330192157.1335-3-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 2/8] xen/public: sysctl: set_parameter.params and debug.keys should be const X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Julien Grall , Ian Jackson , George Dunlap , dfaggioli@suse.com, Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall The fields set_parameter.params and debug.keys should never be modified by the hypervisor. So mark them as const. Signed-off-by: Julien Grall Acked-by: Christian Lindig Reviewed-by: Jan Beulich --- I am not entirely sure whether we should bump the systcl version for this change. Any thoughts? --- xen/include/public/sysctl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 3d72fab49f..3a08c512e8 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -170,7 +170,7 @@ struct xen_sysctl_getdomaininfolist { /* XEN_SYSCTL_debug_keys */ struct xen_sysctl_debug_keys { /* IN variables. */ - XEN_GUEST_HANDLE_64(char) keys; + XEN_GUEST_HANDLE_64(const_char) keys; uint32_t nr_keys; }; =20 @@ -1037,7 +1037,7 @@ struct xen_sysctl_livepatch_op { */ =20 struct xen_sysctl_set_parameter { - XEN_GUEST_HANDLE_64(char) params; /* IN: pointer to parameters. = */ + XEN_GUEST_HANDLE_64(const_char) params; /* IN: pointer to parameters. = */ uint16_t size; /* IN: size of parameters. */ uint16_t pad[3]; /* IN: MUST be zero. */ }; --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596199; cv=none; d=zohomail.com; s=zohoarc; b=YN1BftnZX8XhQ10YOLg0krMRbi0pH3pMPh6JyMQug7qTD1W7LUZrL5FZ7LoK2IEd1EW4npZP9K194njhSLFqPWCkgdkFmKvaRYuaYM4n8Ns9cxEvzuz6dNtErW2fIi6/HBNHC+ifj3/eUcxlZsUWDdDLxUZecvujPTMIV+WKTmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596199; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=cY01mY86IvlEBi9LBC0n631juFx7p42WJ2oDnAMsp50=; b=n4n+p8OJ9VNdjr7WwT8Ov4wXu0OBWHIIqw4QPnT+xgIuxYVxDC7UUGIc4AopxFHi4T74aXZc8PWy5nFx6tcKpgegW+ZgJ44qWEGoHC6KHTcOsErqkAKpj05jxdy5VBrmWa/Svs94VfvebaNct3Fbf1KzIc+51rD6Ul6VejWDL7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596199851647.2932387511842; Mon, 30 Mar 2020 12:23:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzE-0005xh-Jm; Mon, 30 Mar 2020 19:22:16 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzD-0005xW-5y for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:15 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c0dbf5b2-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzz8-0003lE-Bt; Mon, 30 Mar 2020 19:22:10 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzz8-0007AJ-3D; Mon, 30 Mar 2020 19:22:10 +0000 X-Inumbo-ID: c0dbf5b2-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cY01mY86IvlEBi9LBC0n631juFx7p42WJ2oDnAMsp50=; b=wut8A6a2aSgZO+eHz0HH0rqTy4 rvgwJNTmIhTbrd5jDC/zDcJvGDdefAooOvvpqh+Lpp+eA4WLYBXCAN0whFWfK8h8RuvdTH/hQ4nXL oezV4/psEFV14HQH6fiTJg44b7opJMuv3YFyAhsI4/P3eV9jj9dpK7YLX+Gpp/+2iu2A=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:52 +0100 Message-Id: <20200330192157.1335-4-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 3/8] tools/libxc: misc: Mark const the parameter 'keys' of xc_send_debug_keys() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Ian Jackson , Wei Liu , dfaggioli@suse.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall OCaml is using a string to describe the parameter 'keys' of xc_send_debug_keys(). Since Ocaml 4.06.01, String_val() will return a const char * when using -safe-string. This will result to a build failure because xc_send_debug_keys() expects a char *. The function should never modify the parameter 'keys' and therefore the parameter should be const. Unfortunately, this is not directly possible because DECLARE_HYPERCALL_BOUNCE() is expecting a non-const variable. A new macro DECLARE_HYPERCALL_BOUNCE_IN() is introduced and will take care of const parameter. The first user will be xc_send_debug_keys() but this can be used in more place in the future. Reported-by: Dario Faggioli Signed-off-by: Julien Grall Acked-by: Christian Lindig Reviewed-by: Ian Jackson --- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/xc_misc.c | 4 ++-- tools/libxc/xc_private.h | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index fc6e57a1a0..d8874eb846 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1225,7 +1225,7 @@ int xc_readconsolering(xc_interface *xch, unsigned int *pnr_chars, int clear, int incremental, uint32_t *pindex); =20 -int xc_send_debug_keys(xc_interface *xch, char *keys); +int xc_send_debug_keys(xc_interface *xch, const char *keys); int xc_set_parameters(xc_interface *xch, char *params); =20 typedef struct xen_sysctl_physinfo xc_physinfo_t; diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 093fa44081..957c03415c 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -167,11 +167,11 @@ int xc_readconsolering(xc_interface *xch, return ret; } =20 -int xc_send_debug_keys(xc_interface *xch, char *keys) +int xc_send_debug_keys(xc_interface *xch, const char *keys) { int ret, len =3D strlen(keys); DECLARE_SYSCTL; - DECLARE_HYPERCALL_BOUNCE(keys, len, XC_HYPERCALL_BUFFER_BOUNCE_IN); + DECLARE_HYPERCALL_BOUNCE_IN(keys, len); =20 if ( xc_hypercall_bounce_pre(xch, keys) ) return -1; diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index adc3b6a571..c77edb3c4c 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -181,6 +181,14 @@ enum { */ #define DECLARE_HYPERCALL_BOUNCE(_ubuf, _sz, _dir) DECLARE_NAMED_HYPERCALL= _BOUNCE(_ubuf, _ubuf, _sz, _dir) =20 +/* + * Declare a bounce buffer shadowing the named user data pointer that + * cannot be modified. + */ +#define DECLARE_HYPERCALL_BOUNCE_IN(_ubuf, _sz) \ + DECLARE_NAMED_HYPERCALL_BOUNCE(_ubuf, (void *)(_ubuf), _sz, \ + XC_HYPERCALL_BUFFER_BOUNCE_IN) + /* * Set the size of data to bounce. Useful when the size is not known * when the bounce buffer is declared. --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596196; cv=none; d=zohomail.com; s=zohoarc; b=ehr56fWBo8NH+/J+IxaxnhTEFCjreVzWwI3xjiWr1fCXQ+ekDanbFgH5npQyW/L4H00kKUVLVZPKeE46lCJptlvYV7IoOqI1n9kiZN+ouX+znm+UrzZ1qCMIjNvIKzzRjfGYPJEpWmeoamYP5ND4Y6Q3vU9W1FYbK0DwWsPsgPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596196; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=peJcPgQ/w5GYJTqL3knAugPTmzSwJ80t6fz1TAFDEK0=; b=d4X1+P6lkoNO3fgg/Z9zprui5M90CIfKrPPHbpW8E1HtvYlLpoo78FAj81eYp3vfbsbIR8q6smo/nHyUjQ3R1ao1wE3iC+dA+O4XEuhseV+PJEgyEUVowMZBltWxYjH9tprY4oCEqBJnIJl4CIsW3G1iSYHGLC+Ft6q4tOZ1sCs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596196918204.78598622865286; Mon, 30 Mar 2020 12:23:16 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzK-0005zI-6k; Mon, 30 Mar 2020 19:22:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzI-0005yY-6q for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:20 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c14e495c-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:12 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzz9-0003lS-Dv; Mon, 30 Mar 2020 19:22:11 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzz9-0007AJ-50; Mon, 30 Mar 2020 19:22:11 +0000 X-Inumbo-ID: c14e495c-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=peJcPgQ/w5GYJTqL3knAugPTmzSwJ80t6fz1TAFDEK0=; b=En/uO1WbEIm4lGhBErwCW2lV6A brHekkrx6Xl/3KGnU6ngnnWrHOwZr8X4rUozTWdNySK9YDaFHYXIqApXOqU22jgsaGTF0898Hssvi M81Ir5RC/ekjJnZL2zIeyicc7jWpEHbtvj1vdy2+4AA8IJbqctbW1GKpoNUIGfSByrbY=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:53 +0100 Message-Id: <20200330192157.1335-5-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 4/8] tools/libxc: misc: Mark const the parameter 'params' of xc_set_parameters() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Ian Jackson , Wei Liu , dfaggioli@suse.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall The parameter 'params' of xc_set_parameters() should never be modified. So mark it as const. Signed-off-by: Julien Grall Acked-by: Christian Lindig Reviewed-by: Ian Jackson --- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/xc_misc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index d8874eb846..58fa931de1 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1226,7 +1226,7 @@ int xc_readconsolering(xc_interface *xch, int clear, int incremental, uint32_t *pindex); =20 int xc_send_debug_keys(xc_interface *xch, const char *keys); -int xc_set_parameters(xc_interface *xch, char *params); +int xc_set_parameters(xc_interface *xch, const char *params); =20 typedef struct xen_sysctl_physinfo xc_physinfo_t; typedef struct xen_sysctl_cputopo xc_cputopo_t; diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 957c03415c..fe477bf344 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -187,11 +187,11 @@ int xc_send_debug_keys(xc_interface *xch, const char = *keys) return ret; } =20 -int xc_set_parameters(xc_interface *xch, char *params) +int xc_set_parameters(xc_interface *xch, const char *params) { int ret, len =3D strlen(params); DECLARE_SYSCTL; - DECLARE_HYPERCALL_BOUNCE(params, len, XC_HYPERCALL_BUFFER_BOUNCE_IN); + DECLARE_HYPERCALL_BOUNCE_IN(params, len); =20 if ( xc_hypercall_bounce_pre(xch, params) ) return -1; --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596197; cv=none; d=zohomail.com; s=zohoarc; b=J1/5PIyc9ThS2qfHQxKkekl76q0MvlpveSa2NBODi1FBtgeRtOFqOQGTw7wNk8sfIIZ9h2macmoxKymG5Mbcfb0HSQA4dcdsiNI6h/xTR6IYU4g/P/KkypxjtrhtiCyvv+nSnA4Kw4PKpuxRIwYMQBvJgD+q5mbeJQtemk2xo4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596197; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=P/pIVztCOZ+Oro9OyPZ8rpK5+2/IrWNjAFttuxKSq30=; b=Oynm7Bnz3GgDOYrk2sHQea4NfUBQbbV6WsXp2+fS+NcmO6cqzWnL7PRz35zTjEelfaYNekU6vulpXS/FzaZ1emDDHQxcoodn1s+O+FYYXctuQTv9q/Mxf3Rr7Q2oyHo76K1CmKdfYufW3moB96mYBMnr4hdrtDcv5+SUwWEibyY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158559619717426.064169851332736; Mon, 30 Mar 2020 12:23:17 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzO-00062B-J7; Mon, 30 Mar 2020 19:22:26 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzN-00061L-6a for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:25 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c268c1f8-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:13 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzA-0003la-NF; Mon, 30 Mar 2020 19:22:12 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzzA-0007AJ-EK; Mon, 30 Mar 2020 19:22:12 +0000 X-Inumbo-ID: c268c1f8-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=P/pIVztCOZ+Oro9OyPZ8rpK5+2/IrWNjAFttuxKSq30=; b=tbXnFvDrokb0deanZ48HiDe08H 3BaJ7R53ka4p7uR+B9abIT0HELSLTbhFBGducfWVCW91JzRKgC35rbnW5vYwhJox/xPAatYHdSJB+ RZXq3RWpcZDqKEfXao+JjMU4rjQKEkq7Ms53msDaflHyehtEbYpSrI6Kjd4NDYWeDUlU=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:54 +0100 Message-Id: <20200330192157.1335-6-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 5/8] tools/ocaml: libxc: Check error return in stub_xc_vcpu_context_get() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Julien Grall , Ian Jackson , dfaggioli@suse.com, Christian Lindig , David Scott Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall xc_vcpu_getcontext() may fail to retrieve the vcpu context. Rather than ignoring the return value, check it and throw an error if needed. Signed-off-by: Julien Grall Acked-by: Christian Lindig --- tools/ocaml/libs/xc/xenctrl_stubs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 904da45c4f..0fdbeac158 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -497,6 +497,8 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, valu= e domid, vcpu_guest_context_any_t ctxt; =20 ret =3D xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt); + if ( ret < 0 ) + failwith_xc(_H(xch)); =20 context =3D caml_alloc_string(sizeof(ctxt)); memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c)); --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596198; cv=none; d=zohomail.com; s=zohoarc; b=IhZv4dkSSkIMhVyFRPcOinMG96z9/60scVB7jXKf79wI4QBgquCrfOGLcQ8cAbTfJzuENzF02/74dvUHrHJUGhBswA9SpVUD7ltYL7rWpMBrPjD+KeJFFGuCiYKmm8xO/3MVERkpp4KMAe27zaU66WEsDyxPh2IG+KN/EBB1xcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596198; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=SeTP5PjKpdztRFSH2djowiTCzoQ8o/T7Y3wvlnDwhHk=; b=n7AGOpL6Tm+Z16rpW/Nh6V8QYvm/e65VoIR8Ikm9HtTTBvbA3sA0FMwOhpyu+kar3fOEe2dSyBOSUR4Vj4DHL5VyuGcJ0Ghsjcvna+MW0xtiSxxh3aX7BQSX87AQP0uHbGG7AUck4NTqm9t++Dqr6zBMbxHD4WCxzqBOuyu9v8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596198408128.44853768790642; Mon, 30 Mar 2020 12:23:18 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzS-00064E-S3; Mon, 30 Mar 2020 19:22:30 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzS-000642-6J for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:30 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c34cee6e-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:15 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzC-0003li-0H; Mon, 30 Mar 2020 19:22:14 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzzB-0007AJ-Nd; Mon, 30 Mar 2020 19:22:13 +0000 X-Inumbo-ID: c34cee6e-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=SeTP5PjKpdztRFSH2djowiTCzoQ8o/T7Y3wvlnDwhHk=; b=TcefiyBlZ3lnjAHdNvaPZbBRWS Zah8M9C9laLhy/vo/xoCPcadFcuM9Adik5NQImgEHUSYG+YwnjbxGeO5CHaoUIZPbPcU1Fctr5J8E IcL9yFfsYQWLm5rZqWpWrJ9ScAFqXG7HfEnybEJqt/D7szWcUlE6bn88nziw/so2aLJw=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:55 +0100 Message-Id: <20200330192157.1335-7-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 6/8] tools/ocaml: libxb: Harden stub_header_of_string() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Julien Grall , Ian Jackson , dfaggioli@suse.com, Christian Lindig , David Scott Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall stub_header_of_string() should not modify the header. So mark the variable 'hdr' as const. Signed-off-by: Julien Grall Acked-by: Christian Lindig --- tools/ocaml/libs/xb/xenbus_stubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ocaml/libs/xb/xenbus_stubs.c b/tools/ocaml/libs/xb/xenbu= s_stubs.c index a68e783f70..001bb03371 100644 --- a/tools/ocaml/libs/xb/xenbus_stubs.c +++ b/tools/ocaml/libs/xb/xenbus_stubs.c @@ -40,12 +40,12 @@ CAMLprim value stub_header_of_string(value s) { CAMLparam1(s); CAMLlocal1(ret); - struct xsd_sockmsg *hdr; + const struct xsd_sockmsg *hdr; =20 if (caml_string_length(s) !=3D sizeof(struct xsd_sockmsg)) caml_failwith("xb header incomplete"); ret =3D caml_alloc_tuple(4); - hdr =3D (struct xsd_sockmsg *) String_val(s); + hdr =3D (const struct xsd_sockmsg *) String_val(s); Store_field(ret, 0, Val_int(hdr->tx_id)); Store_field(ret, 1, Val_int(hdr->req_id)); Store_field(ret, 2, Val_int(hdr->type)); --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596199; cv=none; d=zohomail.com; s=zohoarc; b=LZOhDGdNCD4UELcM6OOOS9PDawXoPjOBT/54wrfuEgiZKEr7Ibm6EAzYNx8P2Ld+N2OJ9rpsPjZK0KW5D7h7Dlprjl9bzBw6qGg/FmG2Sjp34/PD8vJeF/nhHDy67jC28DrqB7cbgp6shMt9qBXdWxPkovNlbR+waExJGNY2yFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596199; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5RK/M/BD78N+wYg8aAJcgWTuFyhsFJhP/rvS9tnG5ds=; b=GgknnDrasZu21itgtCE1Y7MLMX6J1kC1mASpMzWzdEhXee5MrvKVIbKBQq556OSFoYn+tsYUrwL7hQpdEYB0K3k6WL1KIEB15G3T2AW3FzTVGmMmHajwOaol38a8wdkBqWCpZv9UYNGMpEBRepu0MDSyN3TYuw5WBaZNKVVdOpg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596199056367.9186881343651; Mon, 30 Mar 2020 12:23:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzG-0005y6-TR; Mon, 30 Mar 2020 19:22:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzF-0005xt-Lf for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:17 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c3fd449e-72bb-11ea-83d8-bc764e2007e4; Mon, 30 Mar 2020 19:22:16 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzD-0003lr-9V; Mon, 30 Mar 2020 19:22:15 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzzD-0007AJ-0d; Mon, 30 Mar 2020 19:22:15 +0000 X-Inumbo-ID: c3fd449e-72bb-11ea-83d8-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5RK/M/BD78N+wYg8aAJcgWTuFyhsFJhP/rvS9tnG5ds=; b=gbelpuF+8nz0EGiSJb3ROmX5Bv umYGB/CtTDuxmb+xsgzL0NFR5tPOe0tUb42dp6RXODkcn0OzQ6KMi2XYcbQzcmwTRjA/mik4lNUbe Moh7iklMlInYb6VDchoCZCSYSFrCr6wKSm0dKGmAer1iVQvH1bUKtEWU+d4yaAwJzdBY=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:56 +0100 Message-Id: <20200330192157.1335-8-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 7/8] tools/ocaml: libxb: Avoid to use String_val() when value is bytes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Julien Grall , Ian Jackson , dfaggioli@suse.com, Christian Lindig , David Scott Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Commit ec7d54dd1a "ocaml/libs/xb: Use bytes in place of strings for mutable buffers" switch mutable buffers from string to bytes. However the C code were still using String_Val() to access them. While the underlying structure is the same between string and bytes, a string is meant to be immutable. OCaml 4.06.1 and later will enforce it. Therefore, it will not be possible to build the OCaml libs when using -safe-string. This is because String_val() will return a const value. To avoid plain cast in the code, the code is now switched to use Bytes_val(). As the macro is not defined in older OCaml version, we need to provide a stub. Take the opportunity to switch to const the buffer in ml_interface_write() as it should not be modified. Reported-by: Dario Faggioli Signed-off-by: Julien Grall Acked-by: Christian Lindig --- tools/ocaml/libs/xb/xs_ring_stubs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/ocaml/libs/xb/xs_ring_stubs.c b/tools/ocaml/libs/xb/xs_r= ing_stubs.c index 473787064a..7537a23949 100644 --- a/tools/ocaml/libs/xb/xs_ring_stubs.c +++ b/tools/ocaml/libs/xb/xs_ring_stubs.c @@ -36,6 +36,14 @@ =20 #define GET_C_STRUCT(a) ((struct mmap_interface *) a) =20 +/* + * Bytes_val has been introduced by Ocaml 4.06.1. So define our own version + * if needed. + */ +#ifndef Bytes_val +#define Bytes_val(x) ((unsigned char *) Bp_val(x)) +#endif + CAMLprim value ml_interface_read(value ml_interface, value ml_buffer, value ml_len) @@ -44,7 +52,7 @@ CAMLprim value ml_interface_read(value ml_interface, CAMLlocal1(ml_result); =20 struct mmap_interface *interface =3D GET_C_STRUCT(ml_interface); - char *buffer =3D String_val(ml_buffer); + unsigned char *buffer =3D Bytes_val(ml_buffer); int len =3D Int_val(ml_len); int result; =20 @@ -103,7 +111,7 @@ CAMLprim value ml_interface_write(value ml_interface, CAMLlocal1(ml_result); =20 struct mmap_interface *interface =3D GET_C_STRUCT(ml_interface); - char *buffer =3D String_val(ml_buffer); + const unsigned char *buffer =3D Bytes_val(ml_buffer); int len =3D Int_val(ml_len); int result; =20 --=20 2.17.1 From nobody Fri May 3 07:32:51 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585596196; cv=none; d=zohomail.com; s=zohoarc; b=c1SVlOFmVkMlEEQMQH1FclOAEJ9wv3/79qy0wrUbzprXkzRWlIc4RzI4WiCsGhp5PIzZwXORwydZpS2DNpigvh+dGqViipM4L+Iq3quI9yvxVEltTSdoLKWMr7M7TFGzuTKpGik3v0omKpk5I3qohwAqpZBIc1QrxSk6hlf/Qm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596196; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ar+pkUkHO0IhgHIuaQM/KErTZxeGYex2N8R3XcCHzrQ=; b=dhSGIWvPUpBdmnZarkicmIKRfED6seTad4J3q+4A1vjv4HAQ7sLS7ERmxqiGJfvrWrU80g3dwBmp3IZIHV5YHta/emAEKi3TIDB9zvTdgsZpxXJm552J47Mda9NoS4OKYrqaJc7tgJ7gw2cJ37e6rOKpEg7HlCYGFjDCSb5T9gg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596196480338.0264012300795; Mon, 30 Mar 2020 12:23:16 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzY-00067D-54; Mon, 30 Mar 2020 19:22:36 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzX-00066b-6R for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:35 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c4a4302e-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:17 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzE-0003lx-Io; Mon, 30 Mar 2020 19:22:16 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzzE-0007AJ-9t; Mon, 30 Mar 2020 19:22:16 +0000 X-Inumbo-ID: c4a4302e-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ar+pkUkHO0IhgHIuaQM/KErTZxeGYex2N8R3XcCHzrQ=; b=eAP96CDy+hf5LJjWKoslWCgnDV OBlDEhaQoQj082EWORgY45D5O5I4WegRSYbXD9+2//3vREl11FF+w0VcF2kCnqgSrtTmqanAsNBpK Y2Ha3KBi3ShH+xu21RbgHeoDNkWzNUtdUwUHxtJM762kIWqu+ujOJvTy/l4RWhbHEV/E=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:57 +0100 Message-Id: <20200330192157.1335-9-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 8/8] tools/ocaml: Fix stubs build when OCaml has been compiled with -safe-string X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Julien Grall , Ian Jackson , dfaggioli@suse.com, Christian Lindig , David Scott Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall The OCaml code has been fixed to handle properly -safe-string in Xen 4.11, however the stubs part were missed. On OCaml newer than 4.06.1, String_Val() will return a const char * when using -safe-string leading to build failure when this is used in place where char * is expected. The main use in Xen code base is when a new string is allocated. The suggested approach by the OCaml community [1] is to use the helper caml_alloc_initialized_string() but it was introduced by OCaml 4.06.1. The next best approach is to cast String_val() to (char *) as the helper would have done. So use it when we need to update the new string using memcpy(). Take the opportunity to remove the unnecessary cast of the source as mempcy() is expecting a void *. [1] https://github.com/ocaml/ocaml/pull/1274 Reported-by: Dario Faggioli Signed-off-by: Julien Grall Acked-by: Christian Lindig --- I thought about detecting whether caml_alloc_initialized_string() strings exist and implement it if not. This requires a bit more work, so I would like to get feedback first whether this is worth it. --- tools/ocaml/libs/xb/xenbus_stubs.c | 2 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/ocaml/libs/xb/xenbus_stubs.c b/tools/ocaml/libs/xb/xenbu= s_stubs.c index 001bb03371..3065181a55 100644 --- a/tools/ocaml/libs/xb/xenbus_stubs.c +++ b/tools/ocaml/libs/xb/xenbus_stubs.c @@ -65,7 +65,7 @@ CAMLprim value stub_string_of_header(value tid, value rid= , value ty, value len) }; =20 ret =3D caml_alloc_string(sizeof(struct xsd_sockmsg)); - memcpy(String_val(ret), &xsd, sizeof(struct xsd_sockmsg)); + memcpy((char *) String_val(ret), &xsd, sizeof(struct xsd_sockmsg)); =20 CAMLreturn(ret); } diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 0fdbeac158..94aba38a42 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -501,7 +501,7 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, valu= e domid, failwith_xc(_H(xch)); =20 context =3D caml_alloc_string(sizeof(ctxt)); - memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c)); + memcpy((char *) String_val(context), &ctxt.c, sizeof(ctxt.c)); =20 CAMLreturn(context); } @@ -680,7 +680,7 @@ CAMLprim value stub_xc_readconsolering(value xch) conring_size =3D size; =20 ring =3D caml_alloc_string(count); - memcpy(String_val(ring), str, count); + memcpy((char *) String_val(ring), str, count); free(str); =20 CAMLreturn(ring); --=20 2.17.1