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 69846AC154E for ; Thu, 4 Jan 2024 15:06:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=7SfXr/yBtO4vYC7SNn6vY+QA2v6PLoXjOuJJ8N+OQgw=; c=relaxed/simple; d=groups.io; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Disposition; s=20140610; t=1704380796; v=1; b=t/bB+vKSH81Z5HIZjzA++53z5l69cCOK/BMqOc2Ru3M/jsYl6UGHfQ53lpsSMAa441toD157 cPXG8Ju/tqLoLDzoHJYmw4nqkQm0mHt7rnkldEgyMYyX0k3+P29B1FooExgkhPHSV5Zwgfy21r6 uK/tLq9HrMuyXob7eIP2gvMk= X-Received: by 127.0.0.2 with SMTP id xafyYY7687511xc1J5EVCnVq; Thu, 04 Jan 2024 07:06:36 -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.web10.56051.1704380796211594636 for ; Thu, 04 Jan 2024 07:06:36 -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-84-DFX7jgfkMKS7oXIAHXm3pQ-1; Thu, 04 Jan 2024 10:06:32 -0500 X-MC-Unique: DFX7jgfkMKS7oXIAHXm3pQ-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 9B99D837183; Thu, 4 Jan 2024 15:06:31 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 711BB40C6EBC; Thu, 4 Jan 2024 15:06:31 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 41BC91800605; Thu, 4 Jan 2024 16:06:30 +0100 (CET) Date: Thu, 4 Jan 2024 16:06:30 +0100 From: "Gerd Hoffmann" To: Laszlo Ersek Cc: devel@edk2.groups.io, Ard Biesheuvel , oliver@redhat.com, mike.maslenkin@gmail.com, Jiewen Yao Subject: Re: [edk2-devel] [PATCH v3 1/1] OvmfPkg/VirtNorFlashDxe: sanity-check variables Message-ID: References: <20231214153156.46812-1-kraxel@redhat.com> MIME-Version: 1.0 In-Reply-To: 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,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 27fFzckegfughdhVnWWJ8xUix7686176AA= Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="t/bB+vKS"; 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 Hi, > >> - if the StartId is 0x55aa, then we need to look further, beause we > >> can't decide yet. For example, if State is VAR_HEADER_VALID_ONLY (0x7f), > >> then it might be fine for the variable header (at the very end of the > >> varstore) *not* to be followed by payload bytes (name, data). > > > > Not sure this makes sense. VAR_HEADER_VALID_ONLY is a temporary state, > > while the variable driver writes name and data just after the header, > > to be updated to VAR_ADDED when the write completed successfully. So > > I'd expect to never find a header without space for name + data. > > - Do we know for sure that VAR_HEADER_VALID_ONLY is never expected to be > seen? Writing goes like this: (1) find free space (2) write header, with VAR_HEADER_VALID_ONLY. (3) write name + data (4) update header, set state = VAR_ADDED. > What if the variable update design defines VAR_HEADER_VALID_ONLY > specifically so that the variable driver can recover from a power loss > "in the middle"? Power loss in step (3) can surely lead to variables in VAR_HEADER_VALID_ONLY state, and I'd expect the variable driver can actually recover from that. [ side note: The (2) write should be small enough that it fits into the flash block write buffer (128 bytes). Which could be important to maintain variable store consistency. ] Nevertheless we should never find a header at the end of the variable store, without space allocated for name + date. Minimal space for the name is 4 bytes (one char16 + '\0'), for the data 1 byte, alignment rounds the latter to 4 bytes too, so this should be true: VarOffset + sizeof(*VarHeader) + 8 <= VariableStoreHeader->Size > So I figure, if we accept VAR_HEADER_VALID_ONLY in that logic, then we > should also accept VAR_HEADER_VALID_ONLY if it's at the very end of > the varstore. Disagree, see above. Storing the header at a place which leaves no room for name + data doesn't make sense to me. We could go the extra mile and look at the next StartId location, verify StartId != 0x55aa, in the no-space-left-for-header case. take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113182): https://edk2.groups.io/g/devel/message/113182 Mute This Topic: https://groups.io/mt/103171811/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-