From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kFJ3w-00048q-Ka for mharc-grub-devel@gnu.org; Mon, 07 Sep 2020 11:28:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFJ3u-00043Z-HS for grub-devel@gnu.org; Mon, 07 Sep 2020 11:28:06 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:57275) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFJ3s-0007F3-Hz for grub-devel@gnu.org; Mon, 07 Sep 2020 11:28:06 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 16DF04ED; Mon, 7 Sep 2020 11:28:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 07 Sep 2020 11:28:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=pmUqdNv3RA4P7GxqxPQMNQHiflq YAtiUzrxiT5PYKX4=; b=rrpfCYEIJWYD2E13jLPF50/b7yQwvSM9kXEZODTKyJL d/HQMGfwr4PlkeS2RVHZPYSMNb59PuDVVgzVGOaQ1hXqwsruO6dZvOSTOBoHleo0 3xu5arJOXhH8tFqb6X5z9hsFYlnlkFQTdSbidfITsNhWjlbTxFZAm1UBMqI7qVzS FRIVyxeRiPvvQimzlYFwtGhpcWhAHcmgqMscGXwadxnlgVIS1fGSr/v7P4B0A7NE pGMr1mBn5U0IxPla0U58avvZybf8gVr43+hTd4C5GQljGr2Qv3oJJjrQkkZTIpt0 5dZPGxupDe6IeV1ZQQGlgJSX3sBSBQQ5qhym8E8It0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=pmUqdN v3RA4P7GxqxPQMNQHiflqYAtiUzrxiT5PYKX4=; b=hy9g/LoBGeLyHEGD+Ruw8x eWcexoLfz87+4IHpraaeQCYudLHo9xZ9orO0wUogBcbDZrQZulte6TIhZ1+cn+cs eQ/EhlnLgNcEcpznZOnoEHi7LtL4kMmYPpTpttVV3PBqYda80flAoY4D1dtIQUAJ s8eubbeKukAl9fSrg8i1nDSnatsJjC1CAWgBvBZAVbGKHs5Wngd3onOKNNQLZ2Ag x1URQqryUzmQgSxDzSCYkK5qBkYdyH9A4Yr+82tXTeFsIq5qWQOwwT6Qi77tl3xy ZUTEE+YMpD/dl+fk5mtCLa3IauPqckntGwF1PYRnC+8o/9VXvZx4CwbVdEGaOZ4g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudehtddgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucfkphepkeelrddugedrfeekrddufeegnecuvehluhhsthgvrhfuihiivgepieenucfrrg hrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (x590e2686.dyn.telefonica.de [89.14.38.134]) by mail.messagingengine.com (Postfix) with ESMTPA id BBAFB3280059; Mon, 7 Sep 2020 11:28:01 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 3b752ca4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 7 Sep 2020 15:28:00 +0000 (UTC) Date: Mon, 7 Sep 2020 17:27:59 +0200 From: Patrick Steinhardt To: grub-devel@gnu.org Cc: Denis GNUtoo Carikli , Glenn Washburn , Daniel Kiper Subject: [PATCH v3 7/9] cryptodisk: Fix incorrect calculation of start sector Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=64.147.123.25; envelope-from=ps@pks.im; helo=wout2-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/07 11:26:12 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Sep 2020 15:28:06 -0000 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable =46rom: Glenn Washburn Here dev is a grub_cryptodisk_t and dev->offset is offset in sectors of size native to the cryptodisk device. The sector is correctly transformed into native grub sector size, but then added to dev->offset which is not transformed. It would be nice if the type system would help us with this. Signed-off-by: Glenn Washburn Reviewed-by: Patrick Steinhardt --- grub-core/disk/cryptodisk.c | 11 ++++------- include/grub/disk.h | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index b2c6e9a7d..1eea4161f 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -757,9 +757,8 @@ grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_= t sector, size, sector, dev->offset); =20 err =3D grub_disk_read (dev->source_disk, - (sector << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS)) + dev->offset, 0, - size << disk->log_sector_size, buf); + grub_disk_from_native_sector (disk, sector + dev->offset), + 0, size << disk->log_sector_size, buf); if (err) { grub_dprintf ("cryptodisk", "grub_disk_read failed with error %d\n",= err); @@ -816,12 +815,10 @@ grub_cryptodisk_write (grub_disk_t disk, grub_disk_ad= dr_t sector, } =20 /* Since ->write was called so disk.mod is loaded but be paranoid */ - =20 + sector =3D sector + dev->offset; if (grub_disk_write_weak) err =3D grub_disk_write_weak (dev->source_disk, - (sector << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS)) - + dev->offset, + grub_disk_from_native_sector (disk, sector), 0, size << disk->log_sector_size, tmp); else err =3D grub_error (GRUB_ERR_BUG, "disk.mod not loaded"); diff --git a/include/grub/disk.h b/include/grub/disk.h index 316659fee..af9f886d3 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -174,6 +174,13 @@ typedef struct grub_disk_memberlist *grub_disk_memberl= ist_t; /* Return value of grub_disk_get_size() in case disk size is unknown. */ #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL =20 +/* Convert to grub native disk sized sector from disk sized sector */ +static inline grub_disk_addr_t +grub_disk_from_native_sector (grub_disk_t disk, grub_disk_addr_t sector) +{ + return sector << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); +} + /* This is called from the memory manager. */ void grub_disk_cache_invalidate_all (void); =20 --=20 2.28.0 --Kj7319i9nmIyA2yE Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl9WUX4ACgkQVbJhu7ck PpRLWQ//YiOYl3n882jDcYESUs0zBCho4cmEKaMBJc8hH4yXbQaZz7wdNBTV26ra tqX8SDNmUAkBxnW6mPiG/SXBLgO3XwWITUrk9gGp3ZbOr97U/pqhCUok9UOFuEZX Ek5yxQ7pWRTu59aSgG8xcteajcmPCq2l0VW2c8AHTEt8rCG7tDLO6i2L7k3GkwkX i25prDp542/NxRmkKslPcuoeLf6o2j+GbUiUa8s4PT/kINwSfhvdC869SoqFYeT1 ZkSE2jkKtn4oKm9Ss5pU3QfeTezVyABWgQnVjBWlfr+BbIkGHXkf05BK6nBPy/jE 6VUsaB67JTFmZHUfQjfi3xiwbC8EyHAwDb82ZZinOqRsDR4vVp3DH93KyHQUAfEE iOeB3vbBBpBKXywgP17Urm4HR/+f4ZDNwp0WaeTAu/HpPXdoDrjsjocSmsmC/sbO ic3SPcMmZRXQmHCPnpqTk2N3yBxesTTRf2xz4OPxiFajVHlekVHNDuykr/O2SYKq sghe6IvM8gpb8sYhXIraDceFuLFVykd39MiJrWXUB4/UAapuq8xIjTfOeIFecD1o W8z8khfylQh9UOxX+nGKSkr1wYWQ1ZjyVpIR/m92yGgi1E+VlO6dSAk/1Lx+rmJq ARsTNBU3crNxSfkPvXR8H7y3e3n/hl5UzEKeA39LLA/juJQOo74= =hNAP -----END PGP SIGNATURE----- --Kj7319i9nmIyA2yE--