Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp442828rwi; Wed, 12 Oct 2022 23:39:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vi8Pn0BObYvpu1JJoNQD4TzVUkOOpeUEaxC+DtM1avOp5z2QJqNkUtyxmRYfnQu6YfDNt X-Received: by 2002:a17:902:c20d:b0:17f:7b7e:5a46 with SMTP id 13-20020a170902c20d00b0017f7b7e5a46mr33453571pll.74.1665643193171; Wed, 12 Oct 2022 23:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665643193; cv=none; d=google.com; s=arc-20160816; b=K0980K4i9DhmVealT+RN/loqYyLSDaDONbFQT4S8ux+1pddlcLOR3rXU8rUBJ/W9yc PqzR4hxJPqeX/9WF5d/7RhTX0lpsS1i3f6qW+M77AMHxsWEMyHYyrIkhiEE4CcyleMmv nSkwEJCRzNmKwWiNAwRgZgfnoeOUfFfSvW0MfHU3eITDIqrB2AC37Bgo4sFfTfvBh0HO vpy9ZZq136tsK4c1fS1UxWvXB3M3iuMn7hMOIvbpRb1tooU6MJ/Re22ChxN1ofdCuugV dfvvP5HNkL9kYi/D0mw1FSbv0XNSl6aq6UU2+fU+so0TOrz2wPF0M/l8f1b2hVhnJI7J FeLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=gMU1oYsVQ3ZO2pd5Lj1627G06fVfVov6GV580JVfSQE=; b=AkJBtLNEsF/sUxSdd+E/+/nf5OAsY8sbS7WkVNlwH7594WMx5eLaaF3HFe/dHdlGaj 7ouG5EuXFxxtk46guNW9nrQSQmvt+XtnQgzCJN1efESULTWEHv3VG6/kdyhq/5NXSM2A Z7u9Ko4joI5UOJ7CDVfx/wyCduUQtSPHlTB65hkFtqEf+ZTRDdAlLKepnwzk0Zb3ouhG BsjxJcBUbI0DSBwAmydGOY+MnyzGApn+0MnXMvtBrVJuEChVm3E+O1+JqN0+pqwDWxDf zUkkTvlY7FnHC19EXQl3/ySfb2DO59ClyZ3xk++NA29f9mnw7/lY6MG9Lq/Ke8uzDkrj ye3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BXAIOJlv; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=MeXbCh0X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a170902f78d00b0017f5a057061si17077547pln.500.2022.10.12.23.39.40; Wed, 12 Oct 2022 23:39:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BXAIOJlv; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=MeXbCh0X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbiJMGdI (ORCPT + 99 others); Thu, 13 Oct 2022 02:33:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbiJMGdF (ORCPT ); Thu, 13 Oct 2022 02:33:05 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A977127927; Wed, 12 Oct 2022 23:33:04 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 115F01F385; Thu, 13 Oct 2022 06:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1665642783; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gMU1oYsVQ3ZO2pd5Lj1627G06fVfVov6GV580JVfSQE=; b=BXAIOJlvvDdiXlh+E0ukinetXmdqCsAzNochzKg3N06kAB0ooHvnmq28acwLm5pYNT6ecc ojVsa1V01JKiaf9L3WElxGMA1WAtAP6w5IJwDAe/D1u/PmC6/sArivyxe25OVugafdGzjs FRR6UzEsMhOcbNA5F17/YqMy9uHNBNY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1665642783; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gMU1oYsVQ3ZO2pd5Lj1627G06fVfVov6GV580JVfSQE=; b=MeXbCh0XeTGrKzDrlGAM9y3pDpbdxILiSN2Y97aOdfkmEFxJNwu2nZVfKhkWqverww5I20 MH2IpupvndeQUlAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 858F6139F3; Thu, 13 Oct 2022 06:33:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id B+bVHh6xR2PWJgAAMHmgww (envelope-from ); Thu, 13 Oct 2022 06:33:02 +0000 Date: Thu, 13 Oct 2022 08:33:01 +0200 From: Petr Vorel To: Mimi Zohar Cc: Nikolaus Voss , David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Yael Tzur , Cyril Hrubis , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] KEYS: encrypted: fix key instantiation with user-provided data Message-ID: Reply-To: Petr Vorel References: <20221012151429.391EE9BB@mail.steuer-voss.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nikolaus, all, > Hi Nikolaus, > On Wed, 2022-10-12 at 17:09 +0200, Nikolaus Voss wrote: > > Commit cd3bc044af48 ("KEYS: encrypted: Instantiate key with user-provided > > decrypted data") added key instantiation with user provided decrypted data. > > The user data is hex-ascii-encoded but was just memcpy'ed to the binary buffer. > > Fix this to use hex2bin instead. > > Keys created from user provided decrypted data saved with "keyctl pipe" > > are still valid, however if the key is recreated from decrypted data the > > old key must be converted to the correct format. This can be done with a > > small shell script, e.g.: > > BROKENKEY=abcdefABCDEF1234567890aaaaaaaaaa > > NEWKEY=$(echo -ne $BROKENKEY | xxd -p -c64) > > keyctl add user masterkey "$(cat masterkey.bin)" @u > > keyctl add encrypted testkey "new user:masterkey 32 $NEWKEY" @u > > It is encouraged to switch to a new key because the effective key size > > of the old keys is only half of the specified size. > Thank you for updating the patch description. > > The corresponding test for the Linux Test Project ltp has been fixed > > with this patch: > > https://lists.linux.it/pipermail/ltp/2022-October/031060.html FYI, we use lore, thus: Link: https://lore.kernel.org/ltp/20221006081709.92303897@mail.steuer-voss.de/ > Perhaps make this a "Link:" line and move it before your "Signed-off- > by". > > Changes > > ======= > As per Documentation/process/submitting-patches.rst, the changelog > belongs after the "---" separator. > > v2: - clarify commit message, add example to recover old/broken keys > > - improve example in Documentation/security/keys/trusted-encrypted.rst > > - add link to ltp patch > > Fixes: cd3bc044af48 ("KEYS: encrypted: Instantiate key with user-provided decrypted data") > > Cc: stable > > Signed-off-by: Nikolaus Voss > > --- > > Documentation/security/keys/trusted-encrypted.rst | 3 ++- > > security/keys/encrypted-keys/encrypted.c | 6 +++--- > > 2 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/Documentation/security/keys/trusted-encrypted.rst b/Documentation/security/keys/trusted-encrypted.rst > > index 0bfb4c339748..e81e47db0b4c 100644 > > --- a/Documentation/security/keys/trusted-encrypted.rst > > +++ b/Documentation/security/keys/trusted-encrypted.rst > > @@ -350,7 +350,8 @@ Load an encrypted key "evm" from saved blob:: > > Instantiate an encrypted key "evm" using user-provided decrypted data:: > > - $ keyctl add encrypted evm "new default user:kmk 32 `cat evm_decrypted_data.blob`" @u > > + $ evmkey=abcdefABCDEF1234567890aaaaaaaaaaabcdefABCDEF1234567890aaaaaaaaaa > > + $ keyctl add encrypted evm "new default user:kmk 32 $evmkey" @u > > 794890253 > As example code is often re-used, I would avoid including the key data > on the command line.