From nobody Mon Apr 29 02:47:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612772937; cv=none; d=zohomail.com; s=zohoarc; b=Xsc/6u2sLDispIRTjVCDCYy3+E1o9qcgM3YotSCt6hjHPeFgpQNfgx1wEALB5N8cloE81zeFLWjyFtp/duwOpSLwA4a2nfSRARqHxHgvaDNQOldy9+BpRet2K8vfq9fRW+vzMhzsVGmy1OnE4GhdKulqdxV9uMon9yvGkJxElvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612772937; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=uEnFBepAID8ic5Wd1OcXHMGFGq83kMF0m9XNtSpQ8Go=; b=hVk5aqfZqWHiKxecB83CHQSpPbec/dYfaCHtQx6OJHdLBiyXsDzeur2famday+mJHJkm49IAuiz80F5NhX/bHDUUEbsrrek4d1StjnUif6Rkh4WhCcDesm+zCCYK3usyKBNkwTDNyJtgZaqYGSbkfTP6nkW2FM4RZLloGmtnJ3s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 161277293705118.885308667700087; Mon, 8 Feb 2021 00:28:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-23-M-zgjJg1MwWt3QupkhO7QA-1; Mon, 08 Feb 2021 03:28:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 93397107ACF7; Mon, 8 Feb 2021 08:28:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 097FF60CF1; Mon, 8 Feb 2021 08:28:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5985818095CA; Mon, 8 Feb 2021 08:28:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1188Sc2Y027797 for ; Mon, 8 Feb 2021 03:28:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 28ABF2166B2C; Mon, 8 Feb 2021 08:28:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 220742166B29 for ; Mon, 8 Feb 2021 08:28:36 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B8F7801233 for ; Mon, 8 Feb 2021 08:28:36 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-lHnXb6EjP7qrTDKBzYbTtw-1; Mon, 08 Feb 2021 03:28:32 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DYzHs2s0tz7htr for ; Mon, 8 Feb 2021 16:11:21 +0800 (CST) Received: from Y00470486.china.huawei.com (10.174.187.147) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Mon, 8 Feb 2021 16:12:33 +0800 X-MC-Unique: M-zgjJg1MwWt3QupkhO7QA-1 X-MC-Unique: lHnXb6EjP7qrTDKBzYbTtw-1 From: BiaoxiangYe To: Subject: [PATCH] rpc: avoid crash when system time jump back Date: Mon, 8 Feb 2021 08:12:27 +0000 Message-ID: <1612771947-8968-1-git-send-email-yebiaoxiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.147] X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: xiexiangyou@huawei.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: BiaoXiang Ye Setting the system time backward would lead to a multiplication overflow in function virKeepAliveStart. FunctionvirKeepAliveTimerInternal got the same bug too. Backtrace below: #0 0x0000ffffae898470 in raise () from /usr/lib64/libc.so.6 #1 0x0000ffffae89981c in abort () from /usr/lib64/libc.so.6 #2 0x0000ffffaf9a36a8 in __mulvsi3 () from /usr/lib64/libvirt.so.0 #3 0x0000ffffaf8fd9e8 in virKeepAliveStart (ka=3D0xaaaaf954ce10, interval= =3Dinterval@entry=3D0, count=3Dcount@entry=3D0) at ../../src/rpc/virkeepalive.c:283 #4 0x0000ffffaf908560 in virNetServerClientStartKeepAlive (client=3D0xaaa= af954cbe0) at ../../src/rpc/virnetserverclient.c:1628 #5 0x0000aaaac57eb6dc in remoteDispatchConnectSupportsFeature (server=3D0= xaaaaf95309d0, msg=3D0xaaaaf9549d90, ret=3D0xffff8c007fc0, args=3D0xffff8c002e70, rer= r=3D0xffff9ea054a0, client=3D0xaaaaf954cbe0) at ../../src/remote/remote_daemon_dispatch.c:= 5063 #6 remoteDispatchConnectSupportsFeatureHelper (server=3D0xaaaaf95309d0, c= lient=3D0xaaaaf954cbe0, msg=3D0xaaaaf9549d90, rerr=3D0xffff9ea054a0, args=3D0xffff8c002e70, re= t=3D0xffff8c007fc0) at ./remote/remote_daemon_dispatch_stubs.h:3503 #7 0x0000ffffaf9053a4 in virNetServerProgramDispatchCall(msg=3D0xaaaaf954= 9d90, client=3D0xaaaaf954cbe0, server=3D0x0, prog=3D0xaaaaf953a170) at ../../src/rpc/virnetserverprog= ram.c:451 #8 virNetServerProgramDispatch (prog=3D0xaaaaf953a170, server=3D0x0, serv= er@entry=3D0xaaaaf95309d0, client=3D0xaaaaf954cbe0, msg=3D0xaaaaf9549d90) at ../../src/rpc/virnet= serverprogram.c:306 #9 0x0000ffffaf90a6bc in virNetServerProcessMsg (msg=3D, p= rog=3D, client=3D, srv=3D0xaaaaf95309d0) at ../../src/rpc/virne= tserver.c:137 #10 virNetServerHandleJob (jobOpaque=3D0xaaaaf950df80, opaque=3D0xaaaaf953= 09d0) at ../../src/rpc/virnetserver.c:154 #11 0x0000ffffaf812e14 in virThreadPoolWorker (opaque=3D) at ../../src/util/virthreadpool.c:163 #12 0x0000ffffaf81237c in virThreadHelper (data=3D) at ../.= ./src/util/virthread.c:246 #13 0x0000ffffaea327ac in ?? () from /usr/lib64/libpthread.so.0 #14 0x0000ffffae93747c in ?? () from /usr/lib64/libc.so.6 (gdb) frame 3 #3 0x0000ffffaf8fd9e8 in virKeepAliveStart (ka=3D0xaaaaf954ce10, interval= =3Dinterval@entry=3D0, count=3Dcount@entry=3D0) at ../../src/rpc/virkeepalive.c:283 283 timeout =3D ka->interval - delay; (gdb) list 278 now =3D time(NULL); 279 delay =3D now - ka->lastPacketReceived; <=3D'delay' got a negative = value 280 if (delay > ka->interval) 281 timeout =3D 0; 282 else 283 timeout =3D ka->interval - delay; 284 ka->intervalStart =3D now - (ka->interval - timeout); 285 ka->timer =3D virEventAddTimeout(timeout * 1000, virKeepAliveTimer,= <=3D multiplication overflow 286 ka, virObjectFreeCallback); 287 if (ka->timer < 0) (gdb) p now $2 =3D 18288001 (gdb) p ka->lastPacketReceived $3 =3D 1609430405 Signed-off-by: BiaoXiang Ye --- src/rpc/virkeepalive.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c index 860b91b6b1..e662484ea6 100644 --- a/src/rpc/virkeepalive.c +++ b/src/rpc/virkeepalive.c @@ -119,12 +119,25 @@ virKeepAliveTimerInternal(virKeepAlivePtr ka, if (ka->interval <=3D 0 || ka->intervalStart =3D=3D 0) return false; =20 + if (now < ka->intervalStart) { + VIR_WARN("system time jump back detected. now=3D%ld," + " intervalStart=3D%ld", + now, ka->intervalStart); + ka->intervalStart =3D now; + } + if (now - ka->intervalStart < ka->interval) { timeval =3D ka->interval - (now - ka->intervalStart); virEventUpdateTimeout(ka->timer, timeval * 1000); return false; } =20 + if (now < ka->lastPacketReceived) { + VIR_WARN("system time jump back detected. now=3D%ld," + " lastPacketReceived=3D%ld", + now, ka->lastPacketReceived); + ka->lastPacketReceived =3D now; + } timeval =3D now - ka->lastPacketReceived; PROBE(RPC_KEEPALIVE_TIMEOUT, "ka=3D%p client=3D%p countToDeath=3D%d idle=3D%d", @@ -271,6 +284,13 @@ virKeepAliveStart(virKeepAlivePtr ka, ka, ka->client, interval, count); =20 now =3D time(NULL); + if (now < ka->lastPacketReceived) { + VIR_WARN("system time jump back detected. now=3D%ld," + " lastPacketReceived=3D%ld", + now, ka->lastPacketReceived); + ka->lastPacketReceived =3D now; + } + delay =3D now - ka->lastPacketReceived; if (delay > ka->interval) timeout =3D 0; --=20 2.23.0