From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kbG8g-0008P8-N2 for mharc-grub-devel@gnu.org; Fri, 06 Nov 2020 23:47:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbG8b-0008Lr-LT for grub-devel@gnu.org; Fri, 06 Nov 2020 23:47:43 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:43511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbG8V-0002oC-OA for grub-devel@gnu.org; Fri, 06 Nov 2020 23:47:41 -0500 Received: by mail-ot1-x341.google.com with SMTP id y22so3314171oti.10 for ; Fri, 06 Nov 2020 20:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n8oO7X5U4gOpxHa6MWYaClrIPkKPudRdQcIY14MOp/8=; b=h0ukBU630eXQI/7agcIfFUV390e+8tS4/51Vs3S3+5LofDz1PGEFqmoPxooc9VtknQ S19cN4DPwb9eLW7GrVSINRy5H2DAi3Gb/vi0lFj4ulHU/tCGjRaBugXIQkKFGsZraBBm hZMIxR/XaWu0GTBkroeZFGE7MOKIry/TGii5DX8vyQXwqIAcyr44oy6s/9nshZYeaMyV ZofDf5z3PUE/tZr6TFovMu72z4R3AoOLu8Z5glmbhfqjjtihjHh4fvflxMQ6OMiwgl3l MrYuGgSoJdGmQ20kTnoID1P7t02xD/uhMJIzaldQwy2zEIoIx31PQGV1B10qyTIvtXqV h5xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n8oO7X5U4gOpxHa6MWYaClrIPkKPudRdQcIY14MOp/8=; b=CTzgB/uGIEIk5OTiNkC+qIeHZLns5PxbDvJYHkzudoVm67XMuJy8v3eV+bYIrcxmGH lmSJPCPotZ6qTbLrqLHEG+SCX2WoIM+HJ7vp768JWVaitphXIJjc08YVIEJ2wOpI8oZY vs/cqjdMvxOYqmaSh4BjtKqouwyC7hWHXCK9INgQ0LFoZWMQfo78RZq4gkz8J0mVLGsg tZeWQYjXEMvP0g4rlEq3/RGrYhXsO6UVPkikGmTTXhs1KuQBt/0cair5MAWx0DAisD6+ oaEG9pws8DWh8GJvHUR4/+h4d0Hl8zeIJqgzz/xbXN/Z8juc1liZaIepB5RJPOdaIUVX UhXA== X-Gm-Message-State: AOAM533MFyrDze0tIASATiOk/mwEva5mDxvBZOep56/yFLJZyeSdOJbK SnhKpsy2PKFHaY9zl3iEtQSxBDly3NrIPstU X-Google-Smtp-Source: ABdhPJyb5txK9w9O/OiOCpKCn+HhRkacfsFY/mAQje1/8R3lV+uEpGMOibVCOwVGZ/TDPsPO3NtM2A== X-Received: by 2002:a9d:3636:: with SMTP id w51mr3091759otb.71.1604724454342; Fri, 06 Nov 2020 20:47:34 -0800 (PST) Received: from localhost.localdomain ([136.49.44.103]) by smtp.gmail.com with ESMTPSA id x25sm836888oie.17.2020.11.06.20.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 20:47:33 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v4 02/15] cryptodisk: Rename offset in grub_cryptodisk_t to offset_sectors. Date: Fri, 6 Nov 2020 22:44:22 -0600 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::341; envelope-from=development@efficientek.com; helo=mail-ot1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: Sat, 07 Nov 2020 04:47:43 -0000 This makes it clear that the offset represents sectors, not bytes, in order to improve readability. Signed-off-by: Glenn Washburn --- grub-core/disk/cryptodisk.c | 10 +++++----- grub-core/disk/geli.c | 2 +- grub-core/disk/luks.c | 4 ++-- grub-core/disk/luks2.c | 4 ++-- include/grub/cryptodisk.h | 7 ++++++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 3703da221..473c93976 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -754,10 +754,10 @@ grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_dprintf ("cryptodisk", "Reading %" PRIuGRUB_SIZE " sectors from sector 0x%" PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT64_T "\n", - size, sector, dev->offset); + size, sector, dev->offset_sectors); err = grub_disk_read (dev->source_disk, - grub_disk_from_native_sector (disk, sector + dev->offset), + grub_disk_from_native_sector (disk, sector + dev->offset_sectors), 0, size << disk->log_sector_size, buf); if (err) { @@ -803,7 +803,7 @@ grub_cryptodisk_write (grub_disk_t disk, grub_disk_addr_t sector, grub_dprintf ("cryptodisk", "Writing %" PRIuGRUB_SIZE " sectors to sector 0x%" PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT64_T "\n", - size, sector, dev->offset); + size, sector, dev->offset_sectors); gcry_err = grub_cryptodisk_endecrypt (dev, (grub_uint8_t *) tmp, size << disk->log_sector_size, @@ -815,7 +815,7 @@ grub_cryptodisk_write (grub_disk_t disk, grub_disk_addr_t sector, } /* Since ->write was called so disk.mod is loaded but be paranoid */ - sector = sector + dev->offset; + sector = sector + dev->offset_sectors; if (grub_disk_write_weak) err = grub_disk_write_weak (dev->source_disk, grub_disk_from_native_sector (disk, sector), @@ -1228,7 +1228,7 @@ luks_script_get (grub_size_t *sz) ptr = grub_stpcpy (ptr, "luks_mount "); ptr = grub_stpcpy (ptr, i->uuid); *ptr++ = ' '; - grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ", i->offset); + grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ", i->offset_sectors); while (*ptr) ptr++; for (iptr = i->cipher->cipher->name; *iptr; iptr++) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 4ec875821..0175ce4c4 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -361,7 +361,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, } newdev->cipher = cipher; newdev->secondary_cipher = secondary_cipher; - newdev->offset = 0; + newdev->offset_sectors = 0; newdev->source_disk = NULL; newdev->benbi_log = 0; if (grub_le_to_cpu16 (header.alg) == 0x16) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 429db4ad8..aa9877b68 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -122,10 +122,10 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, newdev = grub_zalloc (sizeof (struct grub_cryptodisk)); if (!newdev) return NULL; - newdev->offset = grub_be_to_cpu32 (header.payloadOffset); + newdev->offset_sectors = grub_be_to_cpu32 (header.payloadOffset); newdev->source_disk = NULL; newdev->log_sector_size = 9; - newdev->total_sectors = grub_disk_get_size (disk) - newdev->offset; + newdev->total_sectors = grub_disk_get_size (disk) - newdev->offset_sectors; grub_memcpy (newdev->uuid, uuid, sizeof (uuid)); newdev->modname = "luks"; diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index 3173a098d..26fb14a12 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -605,11 +605,11 @@ luks2_recover_key (grub_disk_t disk, grub_dprintf ("luks2", "Trying keyslot %"PRIuGRUB_SIZE"\n", i); /* Set up disk according to keyslot's segment. */ - crypt->offset = grub_divmod64 (segment.offset, segment.sector_size, NULL); + crypt->offset_sectors = grub_divmod64 (segment.offset, segment.sector_size, NULL); crypt->log_sector_size = sizeof (unsigned int) * 8 - __builtin_clz ((unsigned int) segment.sector_size) - 1; if (grub_strcmp (segment.size, "dynamic") == 0) - crypt->total_sectors = grub_disk_get_size (disk) - crypt->offset; + crypt->total_sectors = grub_disk_get_size (disk) - crypt->offset_sectors; else crypt->total_sectors = grub_strtoull (segment.size, NULL, 10); diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 21dc69501..258b777bf 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -66,7 +66,12 @@ struct grub_cryptodisk struct grub_cryptodisk **prev; char *source; - grub_disk_addr_t offset; + + /* + * The number of sectors the start of the encrypted data is offset into the + * underlying disk, where sectors are the size noted by log_sector_size. + */ + grub_disk_addr_t offset_sectors; /* Total number of encrypted sectors of size (1<