Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp424269ybg; Tue, 28 Jul 2020 09:17:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBiDdilCtW+HlCH0yYsLAne3nIQ6hz+PIC1U44zlcT1+KDF+81M6q2MChJrAdxAvJfZU5G X-Received: by 2002:a17:906:160f:: with SMTP id m15mr27425077ejd.423.1595953051144; Tue, 28 Jul 2020 09:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595953051; cv=none; d=google.com; s=arc-20160816; b=0E9VF5A93E6SZLDthoggwiu1Ow00Za6x+M0kV8/ke35BKjcuJ9RYNnjfHatWPOOU4Y inVjZWRLtcANuBZTQkmlWQnwmlD1tnfn1f92Z1e61/upQ1np0ZnTXtvgQynouQ3hk0Po X/PTIgCNIXCV0PP/4daTpYuR0uR/0JGeIf3ND2mdQMc4aD4lAowHNRT6+eRp3xBCypl1 F7iiWKUuZt+Xpagb46xyihyaqy9Zpnxc5m7fiuOLBGZesd4JoD4MOoT+Uoy35Nvjggjz 0oLgD7qu+EDbT2TkxluwudCHvbXsDALJjPw9gDGBMb0oIRrumkTld5bVMj6eMmTPAtuc W1BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=gc+GryM2NEU65ZC/SbbkbBgZ/JTXoDUe5MifWJuSVMk=; b=zI8Ya5HBuZ3QbZ38IiOdSQlOUs1sBpKzW7Iji8tJ8UAuXZ4R07Iqxeet/IbD3kCF9c w/mXMSV/io5ipSBVJqG1rA2hL8XLUiZfVjq/FQrDdrP0gGpt5OYLHm6x87UWT+xYuVxT /U1hwBSYrZwSkWZFeHMPp9F19XXFZHgZ/3qi/GCfQxTQsb3bmkMFtgyqXjGbGMyMc8dH cjCSSxDhG24etPRlLoOS232d5RAkFxwT2LSAtfiSiqOls1gkT0gnEu/PZHDIrh6+4P8k RfsgcWMSmh6Dm33IHBuW5SbjJ8x2JWbVjEJDF5tqSlJ2zSqoqn5B4ya7xJ3/c65u8mnw CrFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KxtAVUFF; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si7884249edx.430.2020.07.28.09.17.01; Tue, 28 Jul 2020 09:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KxtAVUFF; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730810AbgG1QQ2 (ORCPT + 99 others); Tue, 28 Jul 2020 12:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730556AbgG1QQ2 (ORCPT ); Tue, 28 Jul 2020 12:16:28 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 199EEC061794 for ; Tue, 28 Jul 2020 09:16:28 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id g6so1745510ilc.7 for ; Tue, 28 Jul 2020 09:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gc+GryM2NEU65ZC/SbbkbBgZ/JTXoDUe5MifWJuSVMk=; b=KxtAVUFFTxd6tArwAyIW8a5ZD8mzymmT57GH4NfSTosVKWniqlgecWlp9GcCNot5vG TzTQ6AopVUZ8sMzR2xXAOZHH8EbbaArgboxO+bfCe+9wGbO0KtE813vat0xMZdKTBtoG CuGPZIOFG7yQhGqDDfwoUs3bvOf8PZgLN9RlHZRUzxQf5XIbY7OgEm2Y20qKpZBosmqF uCcC8NwQ1L8lwdg74x9fJCq3zvNdhSfpsUaCX0Ly1um97XS8RIbksYOg7Y2kDigbMOS2 zv2+fhvb4M2xqNZpuWAWvZuqWyypiYKgQZ3YOamoojwTuDaE/XEKDiInfUnYzgfw5KA5 nZpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gc+GryM2NEU65ZC/SbbkbBgZ/JTXoDUe5MifWJuSVMk=; b=V9ecEdrYHNsFVjv4OteQVpA8737Vw8v7Y50c4Ed9p92+Qz/UAYFcJQCcvwvmyT0Fg8 ZTBCSFUrc0Mr3DpANk4bz+EG3HYEwhFd/nEDh0NinXeH9RTGhDaxSGNS9N+hZ58Y+JuP ogIVcufUNKnZtXxUhLMz68K+MHJHmUfBuUq7JohTyro4GN+3yuIo0OdRrSfN13q6vB6F 05fZ9zQ/+JeJPw0tHoXpxbkqnbx28IwGYueUm+J2H2JaFtYcjjE9nEOvglejGVBKHckb /at5uMA7xFJ2mwH3aHvCyOE1L+9hYOf6beHo+LFnwm3UJNFiJkzzS1ce/QhmT+GG/Vft KmUA== X-Gm-Message-State: AOAM532Jt+YXfB3IMQ/H5lMtkZh9AskhQKMG0C+H8NooPQU1+e4RyirY lRRPScGAV+0sQPfEPQX5OO7OsIlCF8vScx6sfARha9s4cBA= X-Received: by 2002:a92:d84d:: with SMTP id h13mr31683484ilq.102.1595952987153; Tue, 28 Jul 2020 09:16:27 -0700 (PDT) MIME-Version: 1.0 References: <13569541.ZYm5mLc6kN@tauon.chronox.de> <9149882.4vTCxPXJkl@tauon.chronox.de> In-Reply-To: <9149882.4vTCxPXJkl@tauon.chronox.de> From: Elena Petrova Date: Tue, 28 Jul 2020 17:16:16 +0100 Message-ID: Subject: Re: [PATCH v2] crypto: af_alg - add extra parameters for DRBG interface To: Stephan Mueller Cc: "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Eric Biggers , Ard Biesheuvel , Jeffrey Vander Stoep Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Stephan, On Tue, 21 Jul 2020 at 14:19, Stephan Mueller wrote: > > Am Dienstag, 21. Juli 2020, 14:55:14 CEST schrieb Elena Petrova: > > Hi Elena, > > > > > +#ifdef CONFIG_CRYPTO_CAVS_DRBG > > > > +static int rng_setentropy(void *private, const u8 *entropy, unsigned > > > > int > > > > len) +{ > > > > + struct rng_parent_ctx *pctx = private; > > > > + u8 *kentropy = NULL; > > > > + > > > > + if (!capable(CAP_SYS_ADMIN)) > > > > + return -EPERM; > > > > + > > > > + if (pctx->entropy) > > > > + return -EINVAL; > > > > + > > > > + if (len > MAXSIZE) > > > > + len = MAXSIZE; > > > > + > > > > + if (len) { > > > > + kentropy = memdup_user(entropy, len); > > > > + if (IS_ERR(kentropy)) > > > > + return PTR_ERR(kentropy); > > > > + } > > > > + > > > > + crypto_rng_alg(pctx->drng)->set_ent(pctx->drng, kentropy, len); > > > > + pctx->entropy = kentropy; > > > > > > Why do you need to keep kentropy around? For the check above whether > > > entropy was set, wouldn't a boolean suffice? > > > > I need to keep the pointer to free it after use. Unlike the setting of > > the key, DRBG saves the entropy pointer in one of its internal > > structures, but doesn't do any memory > > management. I had only two ideas on how to prevent memory leaks: > > either change drbg code to deal with the memory, or save the pointer > > somewhere inside the socket. I opted for the latter. But if you know a > > better approach I'm happy to rework my code accordingly. > > I was thinking of calling crypto_rng_alg(pctx->drng)->seed() directly after > set_ent. This call performs a DRBG instantatiate where the entropy buffer is > used. See crypto_drbg_reset_test for the approach. > > But maybe you are right, the test "entropy" buffer inside the DRBG currently > cannot be reset. So, for sanity purposes, you need to keep it around. I looked into this, and afaik `->seed()` needs the seed buffer (a.k.a. key); and seed() is also invoked on ALG_SET_KEY setsockopt. So we would need both entropy and seed values at the same time. To avoid complicating the matters, I decided to leave the code as is. I added a comment in v3 [https://lore.kernel.org/linux-crypto/20200728155159.2156480-1-lenaptr@google.com/] explaining why the `kentropy` pointer is saved. > Ciao > Stephan Regards, Elena