From nobody Tue May 14 13:46:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1648643665; cv=none; d=zohomail.com; s=zohoarc; b=QnCWcvy+49wd5SNskILUERBZlm8fuPmbc4zK7m1a1o42UkXNx0fECaN9wtXbxdoDM4ZeszR5pNS/ZIYCFb8IuktC9SzZh4eQ4UO16Mv0l/s5l83/6lQx4CB2ykQW0I6e5MI6aur2p75DA2dYNoozCXAaRfePUhP43mnm1ysJhwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648643665; 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=RtRh16gcXXNOF9gCjAk+suBEWx4vrk69O4jQvBw7iH8=; b=C7E6uSlxbxoBwXXk8MVuLzeFM93ZSw1Qjz0j59cNRXGOR1/cy/e2pE7uqjxlSK/3ixREj207HT2CPIvmmLRB8DNOaY2ttTtCjsA8oTuXsQaKjsdmMQ7jeouQBH+nHDoQY4JCdUpEbSyF3+6Rr+4eXxY+G5bQm9DFr/L4ArWteaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1648643665170374.3603154212607; Wed, 30 Mar 2022 05:34:25 -0700 (PDT) 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-314-TLL1FlpPMtmQySoSqOylYg-1; Wed, 30 Mar 2022 08:34:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C1A3280297E; Wed, 30 Mar 2022 12:34:16 +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 6F4ED1454539; Wed, 30 Mar 2022 12:34:14 +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 2975D19451F3; Wed, 30 Mar 2022 12:34:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EBABC19466DF for ; Wed, 30 Mar 2022 12:19:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D628E401E48; Wed, 30 Mar 2022 12:19:21 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.34.245.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E28E401E2A for ; Wed, 30 Mar 2022 12:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648643664; 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=RtRh16gcXXNOF9gCjAk+suBEWx4vrk69O4jQvBw7iH8=; b=P2wM1NyHTX7oWXemFvIXr3sLvjC3ela30UcnriIcXSIL/M/aVJFpeZaDx1tawRGmOftWXW dinm0RWWKoAe2mniOUNbFlZE4aOdq07lgIfajDCmzqUrT3Z8Dyg1BRxGXP8qjAaFpAhuMV +zIjL3FkL/7zFTAlclIcOCk0Sh53ImA= X-MC-Unique: TLL1FlpPMtmQySoSqOylYg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virsh: Fix integer overflow in allocpages Date: Wed, 30 Mar 2022 14:19:14 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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 2.85 on 10.11.54.7 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 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1648643665950100001 Content-Type: text/plain; charset="utf-8"; x-default="true" I've came across an aarch64 system which supports hugepages up to 16GiB of size. However, I was unable to allocate them using virsh allocpages. This is because cmdAllocpages() uses vshCommandOptScaledInt(), which scales passed value into bytes, but since the virNodeAllocPages() expects size in KiB the variable holding bytes is then divided by 1024. However, the limit for the biggest value passed to vshCommandOptScaledInt() is UINT_MAX which is now obviously wrong, as it needs to be UINT_MAX * 1024. The same bug is in completer. But here, let's use ULLONG_MAX so that we don't have to care about it anymore. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/virsh-completer-host.c | 2 +- tools/virsh-host.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c index 40cb687582..cbdc3f0d49 100644 --- a/tools/virsh-completer-host.c +++ b/tools/virsh-completer-host.c @@ -42,7 +42,7 @@ virshPagesizeNodeToString(xmlNodePtr node) unit =3D virXMLPropString(node, "unit"); if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) return NULL; - if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) + if (virScaleInteger(&byteval, unit, 1024, ULLONG_MAX) < 0) return NULL; size =3D vshPrettyCapacity(byteval, &suffix); ret =3D g_strdup_printf("%.0f%s", size, suffix); diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 2e3cbc39b6..1e83d19fa1 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -488,7 +488,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) return false; =20 - if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX)= < 0) + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX = * 1024ULL) < 0) return false; pageSizes[0] =3D VIR_DIV_UP(tmp, 1024); =20 --=20 2.35.1