From patchwork Fri May 10 01:24:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163790 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1721621ilr; Thu, 9 May 2019 18:28:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPMuaywVx+f/ECJKJQQYdF5liio0mUuWfQaji5k7WFpitYMLJJl7vTGuyB7WJKYzqJoB/s X-Received: by 2002:a5d:52cc:: with SMTP id r12mr5390217wrv.163.1557451691638; Thu, 09 May 2019 18:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451691; cv=none; d=google.com; s=arc-20160816; b=tevjOWVK8kMUgSb2leXkgjJHGLb/MUZTJxK+Jfcc0w9bOe9elSlqN86i/eMIj5913B ZfLyjK2kT3mGVNf+SkottHH+SSthM9KqI/+bJHRrIFttoL6Y17CmQqIQnx7l+nKNM0tI qf0VVXrkm0AiK+bKa3THKr3NMmsKPYMCtoWQODY/iaRPp7z0hoeqr0KvWxQ59TM1pCHF 5lGoBrdvCLA+dZ3/M5YAMUNfNnUX+a3KA8ULaEmCbgldbr2uAVC6XdqKr3Cl0P898IRl z5yHIGCjKb5owODj5x86kZbDoIMvwwRz0sr7PteAA84OfOw6Mj/p2qv+URnkcqCYe+IX Jawg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=xmXHQaelSM8rDlzwsi23ffSEsHhlJ3XeS44lOJu6G0ADWoQ+jFUygNbQPl0R/h+i1Q 6ptM5Mdyb3bHJ5H10wUOoMpYk6eZWAaz4itHW6iANe03CYNValR40rPQmjMvQc9/tpPm eWmMSUkhgxXi6pU5x7vCbbKNiOqESyGx2uFUNgnNX/NcjQ29YE+Btm05T8/t3u7e/XS4 TaR070psZDrjqCGvpuxEOCZwQ22kOZXyisOM9JoGwyGeOhO7q9vYnCIKVeaB0WcRkx1n poKPFIUVty95wwCTwWW1djV/fHVqIkhLKuDsy43vzDRjWCmKoYWwt4zh4AN1Xlp+iZP3 kRuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Y+F5NpWS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v7si2860174wro.295.2019.05.09.18.28.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:28:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Y+F5NpWS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:35028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuKY-0000s2-J9 for patch@linaro.org; Thu, 09 May 2019 21:28:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Iu-EY for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014F-61 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:44434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHi-00011w-VV for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x542.google.com with SMTP id z16so2114604pgv.11 for ; Thu, 09 May 2019 18:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=Y+F5NpWSy54b0g/wbhbxsHPDmCfYJqWRX6IM6C4VBvXuB4apYAabzsMZnZhbWdy8n9 jGWOJ+uKDDk0UZMadgtD940JWfNqC+Jcn/oUjAyYJif0YLFarhMza857k9KdlUBBXHNJ 3jswznxCkEdcsnVLqP2dwHHiabZ7ljI7z3D061mO9xL2Uy55VduIqOTSwEJrN2Q/guEE WGz0ih1/Or6TH98/iTGNzN0dj6Z0p/Lw9bLoOKWb4d7yBB1ghG6AMPG21ab4HlDiqwjx 2cq6Nst2HxZ7tfCNpevOAJb8ht9VOqIuJgygpwCR3ZCKWggxbH28+frtv71gYILf15jp 708w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=aMVmAGPedm0DyjoaQJg1cSvweQijFC9OsZXnegNK6uAyJ+zCt7JC6RFH9ir8NsLOr6 8YexdSGU2VjGj79yhuAsdzsAU7cbomcgNhqBog7Dk4lr/bsqJJsfazWQWrcAax2VDv3L PeK1Wr4xcU/6aCsl7YM+dTbbHQ1gqCwf/98CjsG3/K0hnISjnICOOA6VAiJATsau082h J0gknB2mOPUy6ZzxduZpx8Va/XCH0n9jghvOS9VEucSM7qd/h6mVMWP6Bpjk9FicNId3 VPBFadTd7fmCdl2gkb37pT6r4nBJguuzAK4M82lgzoSk93MKfzMfCjg0W6RdDT212c4B CDBA== X-Gm-Message-State: APjAAAXLbgLDn71d6od4AB07MXCMy1+YtPHG9dvVnz4gbk/MOQ4e1fxh /3eYJYMj5+L1OTR6sOP0Z1CF5XKcIh0= X-Received: by 2002:aa7:9116:: with SMTP id 22mr9828663pfh.165.1557451511450; Thu, 09 May 2019 18:25:11 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:43 -0700 Message-Id: <20190510012458.22706-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v5 09/24] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand(). Fail gracefully if for some reason we cannot use the crypto system. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- v2: Use qcrypto_random_bytes, not qemu_getrandom, as there is no need for deterministic results for this interface. v3: Fail gracefully in the event qcrypto_random_bytes fails. --- ui/vnc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/ui/vnc.c b/ui/vnc.c index 785edf3af1..d83f4a6ff9 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -43,6 +43,7 @@ #include "crypto/hash.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" +#include "crypto/random.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" @@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs) vnc_client_error(vs); } -static void make_challenge(VncState *vs) -{ - int i; - - srand(time(NULL)+getpid()+getpid()*987654+rand()); - - for (i = 0 ; i < sizeof(vs->challenge) ; i++) - vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); -} - static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) { unsigned char response[VNC_AUTH_CHALLENGE_SIZE]; @@ -2628,7 +2619,16 @@ reject: void start_auth_vnc(VncState *vs) { - make_challenge(vs); + Error *err = NULL; + + if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) { + trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes", + error_get_pretty(err)); + error_free(err); + authentication_failed(vs); + return; + } + /* Send client a 'random' challenge */ vnc_write(vs, vs->challenge, sizeof(vs->challenge)); vnc_flush(vs);