From nobody Mon May 6 18:03:56 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=fail(p=quarantine dis=quarantine) header.from=epam.com ARC-Seal: i=1; a=rsa-sha256; t=1621846854; cv=none; d=zohomail.com; s=zohoarc; b=PSbyu+nSu5H0vUVrtcle8+JamLtugugCVUAe/jyT+NKmtbD54DzFN+MwfKJgWrlzRRIirB0yzkhzTMx5UnQCl0psKXjAtMNoV5xhdV0N8utuOfbd6hbvkFDPDSKjDHkHXmrc1ENVMvbbs0eiil2ZjPCkfRwym/MqcHGL8wtMxQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621846854; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=7FCcAADCeP25ZLoHjRnh7izFINgCkr5IVMcNSNKDkVE=; b=FIatX9OTwmWYw7NELRkgx+OicHi+C94yenK71YTeErqdjKLnZKdn1taubYf1IgO4k3weSYDrr6C8BsZk7o9v3btXYQw+SrF2jkCQEpfzKgbov27OYcubei6eDKJqVfJSU+568wmIJsIwHLr1JwEE7uni9d3hi7gpKBfM06GlEyc= 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=fail header.from= (p=quarantine dis=quarantine) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1621846854591315.14843067209097; Mon, 24 May 2021 02:00:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.131701.246014 (Exim 4.92) (envelope-from ) id 1ll6Rm-0005lU-ED; Mon, 24 May 2021 09:00:26 +0000 Received: by outflank-mailman (output) from mailman id 131701.246014; Mon, 24 May 2021 09:00:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ll6Rm-0005kd-8Z; Mon, 24 May 2021 09:00:26 +0000 Received: by outflank-mailman (input) for mailman id 131701; Mon, 24 May 2021 08:59:07 +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.92) (envelope-from ) id 1ll6QV-0004xC-GZ for xen-devel@lists.xenproject.org; Mon, 24 May 2021 08:59:07 +0000 Received: from pb-smtp1.pobox.com (unknown [64.147.108.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 22e90eb8-1801-4bd7-b845-4aed584d810b; Mon, 24 May 2021 08:59:05 +0000 (UTC) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 76323C5336; Mon, 24 May 2021 04:59:05 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 6CD61C5335; Mon, 24 May 2021 04:59:05 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [95.67.114.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id AC917C5334; Mon, 24 May 2021 04:59:04 -0400 (EDT) (envelope-from sakib@darkstar.site) 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: 22e90eb8-1801-4bd7-b845-4aed584d810b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; s=sasl; bh=N3y2IUOrV3tiaMzNDcpoZJubh8fsBaImgmUzGyl9YYg=; b=k0bv mGxaD3or+1r/4ZAdUHMIq/qVK51+Ra3roGoCKfOuK9Wie1Y71IwuuawCq24jMbxl fzQyLGFDR06/M/NX+7VtjR+XfpPgW/8L/3FxGmuyoWTQb50z7LIhqSbfR0DOeJ+U 8jE2ZpsrrGf1o/OLi279T0EI7Xhys9CteC615EI= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , Sergiy Kibrik Subject: [XEN PATCH v1] libxl: use getrandom() syscall for random data extraction Date: Mon, 24 May 2021 08:58:58 +0000 Message-Id: <20210524085858.1902-1-Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Pobox-Relay-ID: 4A7FC54E-BC6E-11EB-928E-D152C8D8090B-90055647!pb-smtp1.pobox.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @pobox.com) Content-Type: text/plain; charset="utf-8" Simplify libxl__random_bytes() routine by using a newer dedicated syscall. This allows not only to substantially reduce its footprint, but syscall also considered to be safer and generally better solution: https://lwn.net/Articles/606141/ getrandom() available on Linux, FreeBSD and NetBSD. Signed-off-by: Sergiy Kibrik --- tools/libxl/libxl_utils.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index b039143b8a..f3e56a4026 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -16,6 +16,7 @@ #include "libxl_osdeps.h" /* must come before any other headers */ =20 #include +#include =20 #include "libxl_internal.h" #include "_paths.h" @@ -1226,26 +1227,10 @@ void libxl_string_copy(libxl_ctx *ctx, char **dst, = char * const*src) */ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len) { - static const char *dev =3D "/dev/urandom"; - int fd; - int ret; - - fd =3D open(dev, O_RDONLY); - if (fd < 0) { - LOGE(ERROR, "failed to open \"%s\"", dev); + ssize_t ret =3D getrandom(buf, len, 0); + if (ret !=3D len) return ERROR_FAIL; - } - ret =3D libxl_fd_set_cloexec(CTX, fd, 1); - if (ret) { - close(fd); - return ERROR_FAIL; - } - - ret =3D libxl_read_exactly(CTX, fd, buf, len, dev, NULL); - - close(fd); - - return ret; + return 0; } =20 int libxl__prepare_sockaddr_un(libxl__gc *gc, --=20 2.25.1