Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2949223rwi; Tue, 11 Oct 2022 16:08:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KhTe6vKxqMKlKiPImSm/9rGeCJpwvG4n7F5bM7tEAJ6WaHDmVdvHlQ145SPVO7ReN5Ra+ X-Received: by 2002:a05:6402:1c1c:b0:45c:35b2:2a98 with SMTP id ck28-20020a0564021c1c00b0045c35b22a98mr10083518edb.182.1665529707037; Tue, 11 Oct 2022 16:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665529707; cv=none; d=google.com; s=arc-20160816; b=TpTcyOeoLn4mQrLLiSBA70nFRD/f4z1d2UCMB/jeCvVTDOb13oZHoIoVjchZct+azr 11aqPIiZJc3C7OtKFFH36rwAheuCGOn+mQ2JubZ0B1DVaF5mjMK/Lou8MToY/yZi7urQ AN7umeqSNwaL7MN1fF+nTxYsm4VRQNdRgu+zM5Tg66HEzz/0wOZx2KEX3buLZ6VBnXog K58fxtTJtKSNxHqH7fNurT7jhc0YAao/HTUx6blVUUZsjAnwz8x+mh3SctsyMglGaHFf Z0GI56r7im3P8+383eWhNMyPfyEkZbSgKK8Ubw9SIVcYA2LoWqXhhYlDV5qHWizA+Xek c+XA== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=DV8bx8T9Y3U0qlPMogpLsWhEfJUA14xPjha24wDlFOs=; b=oLfw/bCfGSLUb++eFhK2V8aUtqkbwR3MzLfnEpn8n1OCA8ZSmhhukUvy6lQ1mjjSIG fni0usWQZsXXi3hpvWeUYUU7pt3nN+muGjECviInjudeEqtv6wVhRJlJsRKeBcTt+5us fv01MJucrsWuFgvXFmlBr2PnbzvjqFjuJ1D461C2P8TgTUVWCUa7eczO/zrTbZcK4Du3 IbfUMOvuQOBIUJq3nTkOSB9lvOuoDr4MzgrYexGyxSGhVe1iijrgh6TCDsyb240KdYm2 q68ImvxUEcxZU8Co23KqdbE7L3X4T9ZaBoNgYeWME3cV79gUZegNyu9H0obkjZq3LrSK X2OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rKxbc3kM; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a509504000000b0044e8dc744a4si12924210eda.142.2022.10.11.16.08.02; Tue, 11 Oct 2022 16:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@kernel.org header.s=k20201202 header.b=rKxbc3kM; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229451AbiJKXHp (ORCPT + 99 others); Tue, 11 Oct 2022 19:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbiJKXHo (ORCPT ); Tue, 11 Oct 2022 19:07:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E18C143179; Tue, 11 Oct 2022 16:07:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 95A3FB80EA9; Tue, 11 Oct 2022 23:07:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F92EC433C1; Tue, 11 Oct 2022 23:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665529650; bh=SErtSIzqJxf+58W8QNfx55+T8mc2aypbI8+RKkBM1NU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rKxbc3kMqi/LJTyTUGXFRLKx3dYkrBmlCOsXgRH+zLTGOe+s+BU6aFd36t2Fg4GT0 wu4xJ9phEcXV7ySn8/qU7s/u555o2LpoE5VCCEwPnmcaPdhy5qVg5H9EADieyF6LSc wWNK21Ze42XzpKMuOyRkRNIcBcmGVbP7Hohe2bsBQ9XbshxFIuLmJgcRa2w9sgLcqD UMLJKusnEJqS/GnkDEUDukGMoHbXSR6wmyxdVX0eewKY2/TXm0Eyb0qoLBC/T0NIsU RD64piGKrTIqnQ+Rhc2ISuGdI0wAdbZaln5POCyVJUbQyjaJ0FmLRPSNcYPU+Bb/GK eOXuzAdtvtvoA== Date: Tue, 11 Oct 2022 16:07:27 -0700 From: Eric Biggers To: Frederick Lawler Cc: herbert@gondor.apana.org.au, davem@davemloft.net, hch@lst.de, smueller@chronox.de, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-team@cloudflare.com, Ondrej Mosnacek Subject: Re: [RFC PATCH 1/1] crypto: af_alg - Support symmetric encryption via keyring keys Message-ID: References: <20221004212927.1539105-1-fred@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221004212927.1539105-1-fred@cloudflare.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-crypto@vger.kernel.org Hi Frederick, On Tue, Oct 04, 2022 at 04:29:27PM -0500, Frederick Lawler wrote: > We want to leverage keyring to store sensitive keys, and then use those > keys for symmetric encryption via the crypto API. Among the key types we > wish to support are: user, logon, encrypted, and trusted. > > User key types are already able to have their data copied to user space, > but logon does not support this. Further, trusted and encrypted keys will > return their encrypted data back to user space on read, which make them not > ideal for symmetric encryption. > > To support symmetric encryption for these key types, add a new > ALG_SET_KEY_BY_KEY_SERIAL setsockopt() option to the crypto API. This > allows users to pass a key_serial_t to the crypto API to perform > symmetric encryption. The behavior is the same as ALG_SET_KEY, but > the crypto key data is copied in kernel space from a keyring key, > which allows for the support of logon, encrypted, and trusted key types. > > Keyring keys must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set > to leverage this feature. This follows the asymmetric_key type where key > lookup calls eventually lead to keyring_search_rcu() without the > KEYRING_SEARCH_NO_CHECK_PERM flag set. > > Signed-off-by: Frederick Lawler There was a similar patch several years ago by Ondrej Mosnacek: https://lore.kernel.org/linux-crypto/20190521100034.9651-1-omosnace@redhat.com/T/#u Have you addressed all the feedback that was raised on that one? Two random nits below: > + *dest_len = key->datalen; > + *dest = kmalloc(*dest_len, GFP_KERNEL); > + if (!*dest) > + return -ENOMEM; > + > + memcpy(*dest, ukp->data, *dest_len); This should use kmemdup(). > + } else if (IS_ENABLED(CONFIG_ENCRYPTED_KEYS) && > + !strcmp(key->type->name, "encrypted")) { > + read_key = &read_key_type_encrypted; > + } else if (IS_ENABLED(CONFIG_TRUSTED_KEYS) && > + !strcmp(key->type->name, "trusted")) { > + read_key = &read_key_type_trusted; These need to use IS_REACHABLE(), not IS_ENABLED(). - Eric