From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 273CE9416BA for ; Wed, 3 Jan 2024 13:13:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=4UichS/i6sDFprGe7KjjNs5bF+gtY68NMXoFLrQ3mlE=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1704287597; v=1; b=VI7ND7HbRHhg01Ri8vDQ+/modkA9PrNTHx1kihbxJ/x8yZ8DDvKFTMLd4XBjJm1KpsHAaJvw ULqOD/raJcCoZyOrvMXD6zxxssP7LmdMzeZmx/12W6OWuLzfIAOFLIo6xnn9moPwk8GWbtmOiQx T5nXu/rI3cU+wEYvkJ59nxcs= X-Received: by 127.0.0.2 with SMTP id Z2t0YY7687511xXK0FlW3Qpk; Wed, 03 Jan 2024 05:13:17 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.16953.1704287597067752031 for ; Wed, 03 Jan 2024 05:13:17 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-180-NeP0sMqlMGidJsHv65GgiA-1; Wed, 03 Jan 2024 08:13:13 -0500 X-MC-Unique: NeP0sMqlMGidJsHv65GgiA-1 X-Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B783B101A555; Wed, 3 Jan 2024 13:13:12 +0000 (UTC) X-Received: from [10.39.193.243] (unknown [10.39.193.243]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B439540C6EB9; Wed, 3 Jan 2024 13:13:11 +0000 (UTC) Message-ID: <39ded22c-241e-ff56-c18f-8310c8037d98@redhat.com> Date: Wed, 3 Jan 2024 14:13:10 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v3 1/1] OvmfPkg/VirtNorFlashDxe: sanity-check variables From: "Laszlo Ersek" To: devel@edk2.groups.io, kraxel@redhat.com Cc: Ard Biesheuvel , oliver@redhat.com, mike.maslenkin@gmail.com, Jiewen Yao References: <20231214153156.46812-1-kraxel@redhat.com> <9c5074b8-767d-dd64-b68c-ec5cb6b5e743@redhat.com> In-Reply-To: <9c5074b8-767d-dd64-b68c-ec5cb6b5e743@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 8zw6JVtkSF6YdDePOWqsOizvx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=VI7ND7Hb; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 1/3/24 14:09, Laszlo Ersek wrote: > On 1/3/24 13:56, Laszlo Ersek wrote: >=20 >> (8) Apologies if it was me who suggested ALIGN_VALUE() previously, but >> this is, in effect, an unchecked addition. I can't off-hand see evidence >> that it can never overflow (the previous checks don't seem to prevent an >> overflow here), so I suggest: >> >> // >> // the next variable header starts aligned at 4 bytes >> // >> Status =3D SafeUintnAdd (VarEnd, (4 - (VarEnd & 4)) & 4, &VarOffset); >> if RETURN_ERROR (Status) { >> DEBUG ((DEBUG_ERROR, "%a: integer overflow\n", __func__)); >> return EFI_NOT_FOUND; >> } >=20 > Heh, what I wrote is bogus. Man, binary is hard. :) So, let me try again: >=20 > Status =3D SafeUintnAdd (VarEnd, (4 - (VarEnd & 3)) & 3, &VarOffset); >=20 > Ideally, we'd have a SafeIntLib set of APIs for aligning up... BTW the reason I messed it up was that I'm much more attracted to the "%" operator, so initially I wrote it as Status =3D SafeUintnAdd (VarEnd, (4 - (VarEnd % 4)) % 4, &VarOffset); which was correct, but then I thought, from your code, that you probably liked "&" more (and that "&" might be faster for the CPU...), and then I "replaced" the "%" operator with "&", but forgot to replace the divisor 4 with the bitmask 3... Laszlo -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113088): https://edk2.groups.io/g/devel/message/113088 Mute This Topic: https://groups.io/mt/103171811/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-