Received: from list by lists.gnu.org with archive (Exim 4.71) id 1exew6-0006nO-K8 for mharc-grub-devel@gnu.org; Sun, 18 Mar 2018 16:29:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exew3-0006ma-IL for grub-devel@gnu.org; Sun, 18 Mar 2018 16:29:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exew0-00041H-Dk for grub-devel@gnu.org; Sun, 18 Mar 2018 16:29:43 -0400 Received: from avasout05.plus.net ([84.93.230.250]:58934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exew0-0003zz-6r for grub-devel@gnu.org; Sun, 18 Mar 2018 16:29:40 -0400 Received: from [10.0.200.1] ([212.159.104.145]) by smtp with ESMTP id xevje1bon1fhExevkesud7; Sun, 18 Mar 2018 20:29:36 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=J9KEEjvS c=1 sm=1 tr=0 a=LmiDhuzNXzDmzyv3sIr6Rw==:117 a=LmiDhuzNXzDmzyv3sIr6Rw==:17 a=IkcTkHD0fZMA:10 a=mDV3o1hIAAAA:8 a=FzA-yAM6SgVs88mUKEYA:9 a=QEXdDO2ut3YA:10 a=_FVE-zBwftR9WsbkzFJk:22 Subject: Re: [PATCH 2/7] Cryptomount support key files To: grub-devel@gnu.org, TJ References: <20180314094504.6177-1-grub@jelmail.com> <20180314094504.6177-2-grub@jelmail.com> From: John Lane Message-ID: Date: Sun, 18 Mar 2018 20:29:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfDAQHnH5bxcE1c6JBLVuMvnVAvYfe5HQEXLiDtFVJJWCvDJS1CoQOBWrQ92V1Jlvnzn8Cc+kseJ26r1vFrpm2Vt95BDAVCuyYaru7Ejh767Qf8DjvySU fSSGNlvi1MtxkTVkvWS6upM+Awa9dbjsMP6pjhWaSVy1gBK40AstD5Y0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 84.93.230.250 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Mar 2018 20:29:44 -0000 On 17/03/18 11:10, TJ wrote: > On 14/03/18 09:44, John Lane wrote: >> --- a/grub-core/disk/cryptodisk.c >> +++ b/grub-core/disk/cryptodisk.c >> @@ -949,6 +954,45 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) >> hdr = NULL; >> >> have_it = 0; >> + key = NULL; >> + >> + if (state[4].set) /* Key file; fails back to passphrase entry */ >> + { >> + grub_file_t keyfile; >> + int keyfile_offset; >> + grub_size_t requested_keyfile_size; >> + >> + requested_keyfile_size = state[6].set ? grub_strtoul(state[6].arg, 0, 0) : 0; >> + >> + if (requested_keyfile_size > GRUB_CRYPTODISK_MAX_KEYFILE_SIZE) >> + grub_printf (N_("Key file size exceeds maximum (%llu)\n"), \ >> + (unsigned long long) GRUB_CRYPTODISK_MAX_KEYFILE_SIZE); >> + else >> + { >> + keyfile_offset = state[5].set ? grub_strtoul (state[5].arg, 0, 0) : 0; >> + keyfile_size = requested_keyfile_size ? requested_keyfile_size : \ >> + GRUB_CRYPTODISK_MAX_KEYFILE_SIZE; >> + >> + keyfile = grub_file_open (state[4].arg); >> + if (!keyfile) >> + grub_printf (N_("Unable to open key file %s\n"), state[4].arg); >> + else if (grub_file_seek (keyfile, keyfile_offset) == (grub_off_t)-1) >> + grub_printf (N_("Unable to seek to offset %d in key file\n"), keyfile_offset); >> + else >> + { >> + keyfile_size = grub_file_read (keyfile, keyfile_buffer, keyfile_size); >> + if (keyfile_size == (grub_size_t)-1) > > grub_file_read() returns grub_ssize_t (signed). Is casting to > grub_size_t (unsigned) required or going to work as intended? > > Is the only possible error -1? Underlying readwrite functions can return > error codes via grub_error() that are > 0: see include/grub/err.h > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > I have applied these changes. Builds clean but I need to test it. I might have time to do that tomorrow, otherwise next weekend will be soonest.