From nobody Fri Apr 19 19:54:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669038063; cv=none; d=zohomail.com; s=zohoarc; b=iFE9TwaE/rtz+iG7QFXCoc/tDnYySgard/kPqSCxw13H9LclePQ2xpt+FQ5KHWt2t8yn/z31KkNR18QMgeXhTyzacHpd14KKxBgKBw91zCA3YTej0MrT2jfAlqD9Q9YOT9ZBdxuGPYgwZC9Yg6lQjZ9vaVr8pBAuorJXM3f38cc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669038063; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ZNOZg+/wOR7/2TgL1Hz/ZCi3XMmdjkXiiXHcXI50Jpc=; b=IrR9BHwBDSoAxjprvp0Sgnxs1QmdOmkTImGIMNT8IoiK5LtuCINwJMHv5/lTMT46LIIyWX8L+selxQxQTHz+eyqGe7+s8bYkPxgy71kTdpR26uZJTkK+/gFy1IrXGRGGO0N5oWbu1aRB6Mkk/2+B2WDuDesCp5629czYhBqIlgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1669038063892322.98281625801496; Mon, 21 Nov 2022 05:41:03 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-Kx1qHaT_MGWjXglaNoJwpA-1; Mon, 21 Nov 2022 08:41:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7511338173C2; Mon, 21 Nov 2022 13:40:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BC6C4EA47; Mon, 21 Nov 2022 13:40:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DB6A41946588; Mon, 21 Nov 2022 13:40:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6F8151946587 for ; Mon, 21 Nov 2022 13:40:56 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 53F2E2024CBE; Mon, 21 Nov 2022 13:40:56 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFECC2024CB7 for ; Mon, 21 Nov 2022 13:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669038062; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZNOZg+/wOR7/2TgL1Hz/ZCi3XMmdjkXiiXHcXI50Jpc=; b=hjIRUNT4kr5wfcZpCAMO/jsjO81CV+MQ0LXgNJlAmAcVtqMdoqT4GOQUEFsBpKWU7KRV3J jR152ymFSAaCwDFYbIak6pG+p8jkadUU6egA2V4JhgQ1RzOr3fNnmQwJljbqD2Vz8T0zqv f45KJpzjOHcjEfsoLggW8klnzoZVqds= X-MC-Unique: Kx1qHaT_MGWjXglaNoJwpA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virmockstathelpers: Load aliases for 64-bit time Date: Mon, 21 Nov 2022 14:40:52 +0100 Message-Id: <0bd7ca3e0d8716e53401533e73d0ce51e644e20a.1669030983.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669038064836100001 Content-Type: text/plain; charset="utf-8"; x-default="true" On 32-bit arches, it's possible not only to request -D_FILE_OFFSET_BITS=3D64 (which is always done with meson) but also -D_TIME_BITS=3D64. With glibc, both of these affect what variant of stat() or lstat() is called. With 64 bit time it's: __stat64_time64() or __lstat64_time64(), respectively. Fortunately, no other variant (__xstat(), __xstat64()) has _time64 alternative and thus does not need similar treatment. Similarly, musl is not affected by this. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/404 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- Mind you, after this I still see two tests failing: 1) virnettlscontexttest 2) virnettlssessiontest But I believe the problem is that GnuTLS on my 32bit RPi was not built with -D_TIME_BITS=3D64 and thus when generating certificates and setting their activation/expiry times I get the following errors: TEST: virnettlscontexttest 1) TLS Context cacertreq.filename + servercertreq.filename ... l= ibvirt: XML-RPC error : The server certificate servercertreq-ctx.pem is not= yet active FAILED TEST: virnettlssessiontest 1) TLS Session servercertreq.filename + clientcertreq.filename ... l= ibvirt: XML-RPC error : authentication failed: Failed to verify peer's cert= ificate FAILED Setting of activation/expiry times is done by calling: 1) gnutls_x509_crt_set_activation_time(..., time_t act_time) 2) gnutls_x509_crt_set_expiration_time(..., time_t exp_time) And this is how calling the first looks under disassembly: 7428: e51b1128 ldr r1, [fp, #-296] ; 0xfffffed8 742c: e14b2dd4 ldrd r2, [fp, #-212] ; 0xffffff2c 7430: e1a00001 mov r0, r1 7434: ebfff23d bl 3d30 Now, ldrd instruction modifies both r2 and r3 by loading 4+4 bytes from a memory address [1]. But the first thing that gnutls_x509_crt_set_activation_time() does is overwriting r3 register: 000fb4a0 : fb4a0: e52de004 push {lr} ; (str lr, [sp, #-4= ]!) fb4a4: e250c000 subs ip, r0, #0 fb4a8: e59f3080 ldr r3, [pc, #128] ; fb530 fb4ac: e24dd00c sub sp, sp, #12 fb4b0: e08f3003 add r3, pc, r3 fb4b4: 0a000009 beq fb4e0 With 32-bit time_t the disassembly looks a bit different: 73e4: e51b3114 ldr r3, [fp, #-276] ; 0xfffffeec 73e8: e51b10f4 ldr r1, [fp, #-244] ; 0xffffff0c 73ec: e1a00003 mov r0, r3 73f0: ebfff250 bl 3d38 1: It should be 'ldrd r2, r3, $memAddr' but the second register is implied by the first one, so it can be shortened: https://developer.arm.com/documentation/ddi0406/c/Application-Level-Archite= cture/Instruction-Details/Alphabetical-list-of-instructions/LDRD--immediate- tests/virmockstathelpers.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c index 39e270eaac..5b1f3b08a7 100644 --- a/tests/virmockstathelpers.c +++ b/tests/virmockstathelpers.c @@ -54,6 +54,10 @@ * Unfortunately, because we are trying to mock replace the C library, * we need to know about this internal impl detail. * + * Furthermore, support for 64-bit time can be enabled, which on 32-bit + * systems with glibc overwrites stat64() to __stat64_time64() and lstat64= () + * to __lstat64_time64(). + * * On macOS stat() and lstat() are resolved to _stat$INODE64 and * _lstat$INODE64, respectively. stat(2) man page also declares that * stat64(), lstat64() and fstat64() are deprecated, and when @@ -168,7 +172,11 @@ static void virMockStatInit(void) fdebug("real stat %p\n", real_stat); #endif #ifdef MOCK_STAT64 +# if defined(__GLIBC__) && defined(_TIME_BITS) && _TIME_BITS =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(stat64, "__stat64_time64"); +# else VIR_MOCK_REAL_INIT(stat64); +# endif fdebug("real stat64 %p\n", real_stat64); #endif #ifdef MOCK___XSTAT @@ -188,7 +196,11 @@ static void virMockStatInit(void) fdebug("real lstat %p\n", real_lstat); #endif #ifdef MOCK_LSTAT64 +# if defined(__GLIBC__) && defined(_TIME_BITS) && _TIME_BITS =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(lstat64, "__lstat64_time64"); +# else VIR_MOCK_REAL_INIT(lstat64); +# endif fdebug("real lstat64 %p\n", real_lstat64); #endif #ifdef MOCK___LXSTAT --=20 2.37.4