From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.120]) by mx.groups.io with SMTP id smtpd.web11.25729.1574351787367560884 for ; Thu, 21 Nov 2019 07:56:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WAhB9xTO; spf=pass (domain: redhat.com, ip: 205.139.110.120, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574351786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ylHy7sAAmiBT7Av5hw4nA2I5ceimv4ZCIy4I54ChPyY=; b=WAhB9xTO+PcBcCvkn6ThE2Zs038RGj1/krcXEiclM8UeQ8Jsk6fGr1NUbKYKKn3e+nztKI 1rubAO0foQBdt09kYXHjbE37sOUFcnmC3x0PGnuQNhtghoVSPJet3EMSfst185W1lDaUqC LqNX4H0iXJVGIt6f6uZvWmOrNXYKILM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-190-yUffPHCGNsu-fJCxIxPxvw-1; Thu, 21 Nov 2019 10:56:24 -0500 Received: by mail-wr1-f70.google.com with SMTP id e10so2273468wrt.16 for ; Thu, 21 Nov 2019 07:56:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DNzBzRcWQoJSctpMLQJN4tVNiwpOX0Rw1cxfNxnPLuk=; b=KoyxKQVWSOeEZ/jYgxaZgWQTGnL1YzJdmTdA+Rohr06UTflZw4mkoin43PQaBL1/qk Ml9mjMcl3bXbNrn9zN5v6VE4lBCAHZ70MUuF59fG0tTjxkU+J5oxocU+CG/2/FBxfoBo QbJPSJNiEyap5xTXNyvbirKZ1krhq6+fz49XvB2Qt/n9IEp43nI+9VsFJ1Gsj/2ris9D 3vkF7LGU0daj7SR+cRuGYW7iPQ/LUMiMiPNo6u8JA1S7WglPgCMJnq8kXoNV35oOhHQ8 I5S5PWxvGeVZc42K/+9cE/AOLtQ4hrtcJEzP2Fbj0Dsyjgi4t0NRJhrh5BEYuya6mBD8 FOtA== X-Gm-Message-State: APjAAAWbIb452vN0WRlzapbpQg6qzQDN/LNs/gpnxKd2rgLIsQM1BKkT jzo4vh6DD6Cg5i0yhRowg9eT/OBehmB+sMIk9syPz19B9cPNZJ7g5QgBt2K/nhdtNblSmTM+rju Mt+NyYfIGP72a8w== X-Received: by 2002:a1c:9e58:: with SMTP id h85mr11235915wme.77.1574351783345; Thu, 21 Nov 2019 07:56:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxSjRsPa28vrpKTd9nq4PJYBjTLPcwAXPTfMKAjpjtg9xxXhPpO5nPnLYsowsPwJTUgIQSV6Q== X-Received: by 2002:a1c:9e58:: with SMTP id h85mr11235869wme.77.1574351782963; Thu, 21 Nov 2019 07:56:22 -0800 (PST) Return-Path: Received: from [192.168.1.35] (131.red-88-21-102.staticip.rima-tde.net. [88.21.102.131]) by smtp.gmail.com with ESMTPSA id o189sm68762wmo.23.2019.11.21.07.56.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Nov 2019 07:56:22 -0800 (PST) Subject: Re: [edk2-devel] [PATCH v1 06/19] DynamicTablesPkg: Fix GT Block length assignment To: devel@edk2.groups.io, sami.mujawar@arm.com Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, Matteo.Carlini@arm.com, Stephanie.Hughes-Fitt@arm.com, nd@arm.com References: <20190823105539.13260-1-sami.mujawar@arm.com> <20190823105539.13260-7-sami.mujawar@arm.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: <6f91de25-801d-8c70-9943-3c0d598bd48d@redhat.com> Date: Thu, 21 Nov 2019 16:56:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <20190823105539.13260-7-sami.mujawar@arm.com> X-MC-Unique: yUffPHCGNsu-fJCxIxPxvw-1 X-Mimecast-Spam-Score: 0 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On 8/23/19 12:55 PM, Sami Mujawar wrote: > The VS2017 compiler reports 'warning C4267: '=3D': conversion from > 'size_t' to 'UINT16', possible loss of data'. >=20 > The sizeof() operator is used to calculate the size of the > GT Block structure. The length field in the GT Block structure > is 16-bit wide. Since the return type of sizeof() operator > is size_t the VS2017 compiler reports the above warning. >=20 > To fix the warning, an explicit type cast is added. An additional > check is also performed to ensure that the calculated GT Block > length does not exceed MAX_UINT16. >=20 > Signed-off-by: Sami Mujawar > --- > DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c | 25 += +++++++++++++++---- > 1 file changed, 21 insertions(+), 4 deletions(-) >=20 > diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerat= or.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c > index 7e86c30649bd36ecebac75c7e3a86a0c25cd590b..0e996698887aefca8a7240fc2= 7fe3cb9324fd3e2 100644 > --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c > +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c > @@ -350,6 +350,7 @@ AddGTBlockList ( > EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCTURE * GtBlockFrame; > CM_ARM_GTBLOCK_TIMER_FRAME_INFO * GTBlockTimerFrameList; > UINT32 GTBlockTimerFrameCount; > + UINTN Length; > =20 > ASSERT (Gtdt !=3D NULL); > ASSERT (GTBlockInfo !=3D NULL); > @@ -376,11 +377,27 @@ AddGTBlockList ( > return Status; > } > =20 > + Length =3D sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_STRUCTURE) + > + (sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCTURE) * > + GTBlockInfo->GTBlockTimerFrameCount); > + > + // Check that the length of the GT block does not > + // exceed MAX_UINT16 > + if (Length > MAX_UINT16) { > + Status =3D EFI_INVALID_PARAMETER; > + DEBUG (( > + DEBUG_ERROR, > + "ERROR: GTDT: Too many GT Frames. Count =3D %d. " \ > + "Maximum supported GT Block size exceeded. " \ > + "Status =3D %r\n", > + GTBlockInfo->GTBlockTimerFrameCount, > + Status > + )); > + return Status; > + } > + > GTBlock->Type =3D EFI_ACPI_6_3_GTDT_GT_BLOCK; > - GTBlock->Length =3D sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_STRUCTURE) + > - (sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCT= URE) * > - GTBlockInfo->GTBlockTimerFrameCount); > - > + GTBlock->Length =3D (UINT16)Length; > GTBlock->Reserved =3D EFI_ACPI_RESERVED_BYTE; > GTBlock->CntCtlBase =3D GTBlockInfo->GTBlockPhysicalAddress; > GTBlock->GTBlockTimerCount =3D GTBlockInfo->GTBlockTimerFrameCount; >=20 Reviewed-by: Philippe Mathieu-Daude