From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C59D7C76196 for ; Fri, 31 Mar 2023 09:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231873AbjCaJEn (ORCPT ); Fri, 31 Mar 2023 05:04:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbjCaJER (ORCPT ); Fri, 31 Mar 2023 05:04:17 -0400 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net (167-179-156-38.a7b39c.syd.nbn.aussiebb.net [167.179.156.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B820A1FD2A; Fri, 31 Mar 2023 02:03:50 -0700 (PDT) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1piAfN-00AjpH-I6; Fri, 31 Mar 2023 17:03:26 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 31 Mar 2023 17:03:25 +0800 Date: Fri, 31 Mar 2023 17:03:25 +0800 From: Herbert Xu To: Harsha Harsha Cc: davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, michals@xilinx.com, saratcha@xilinx.com, git@amd.com, Dhaval Shah Subject: Re: [PATCH V2 3/4] crypto: xilinx: Add ZynqMP RSA driver Message-ID: References: <20230321053446.4303-1-harsha.harsha@amd.com> <20230321053446.4303-4-harsha.harsha@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230321053446.4303-4-harsha.harsha@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, Mar 21, 2023 at 11:04:45AM +0530, Harsha Harsha wrote: > > +static inline int xilinx_copy_and_save_keypart(u8 **kpbuf, unsigned int *kplen, > + const u8 *buf, size_t sz) > +{ > + int nskip; > + > + for (nskip = 0; nskip < sz; nskip++) > + if (buf[nskip]) > + break; > + > + *kplen = sz - nskip; > + *kpbuf = kmemdup(buf + nskip, *kplen, GFP_KERNEL); > + if (!*kpbuf) > + return -ENOMEM; > + > + return 0; > +} ... > +static int xilinx_rsa_setkey(struct crypto_akcipher *tfm, const void *key, > + unsigned int keylen, bool private) > +{ > + struct xilinx_rsa_tfm_ctx *tctx = akcipher_tfm_ctx(tfm); > + struct rsa_key raw_key; > + int ret; > + > + if (private) > + ret = rsa_parse_priv_key(&raw_key, key, keylen); > + else > + ret = rsa_parse_pub_key(&raw_key, key, keylen); > + if (ret) > + goto n_key; > + > + ret = xilinx_copy_and_save_keypart(&tctx->n_buf, &tctx->n_len, > + raw_key.n, raw_key.n_sz); What happens when you call setkey twice? Wouldn't this leak memory? Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83D52C6FD18 for ; Fri, 31 Mar 2023 09:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pFBMFLv9UV4y8HPBSwMx6z3e6M8Ge+Hz92pMwtMmt2o=; b=copkr+3C+j9Osu E9t/yGR9gZ++YYD0E1RVHIqjxve1z1lqFK5mpJicvIa0vgdzdUORBw844UP0523caVUTWXCFary2L FsHSYrcl9pxeE+UBAfp552SKYfVsCeiAKjYFSaPqhDuHkNIiGfbijrjZHT4090Lr51phz7qwwP1rJ An9rX4n+UMlwX4kQPMT/x9Gy/2/cx62GELnMTsYRaK5tNi0tuTFgGEf5uv2szPNRl7qyPQDv080eZ rUvOsSc5X9mlW8Ab6i+wltRoxIyLKhmgQGU7qap0oGAC1UBwDp+khNwsgLpotgViElBkMIN2a3Kyy 1yaFSohkm/RFb0FgPmiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1piAfw-006aE2-0B; Fri, 31 Mar 2023 09:04:00 +0000 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net ([167.179.156.38]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1piAfq-006a3N-01 for linux-arm-kernel@lists.infradead.org; Fri, 31 Mar 2023 09:03:57 +0000 Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1piAfN-00AjpH-I6; Fri, 31 Mar 2023 17:03:26 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 31 Mar 2023 17:03:25 +0800 Date: Fri, 31 Mar 2023 17:03:25 +0800 From: Herbert Xu To: Harsha Harsha Cc: davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, michals@xilinx.com, saratcha@xilinx.com, git@amd.com, Dhaval Shah Subject: Re: [PATCH V2 3/4] crypto: xilinx: Add ZynqMP RSA driver Message-ID: References: <20230321053446.4303-1-harsha.harsha@amd.com> <20230321053446.4303-4-harsha.harsha@amd.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230321053446.4303-4-harsha.harsha@amd.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230331_020354_060488_8FE8A13A X-CRM114-Status: GOOD ( 10.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 21, 2023 at 11:04:45AM +0530, Harsha Harsha wrote: > > +static inline int xilinx_copy_and_save_keypart(u8 **kpbuf, unsigned int *kplen, > + const u8 *buf, size_t sz) > +{ > + int nskip; > + > + for (nskip = 0; nskip < sz; nskip++) > + if (buf[nskip]) > + break; > + > + *kplen = sz - nskip; > + *kpbuf = kmemdup(buf + nskip, *kplen, GFP_KERNEL); > + if (!*kpbuf) > + return -ENOMEM; > + > + return 0; > +} ... > +static int xilinx_rsa_setkey(struct crypto_akcipher *tfm, const void *key, > + unsigned int keylen, bool private) > +{ > + struct xilinx_rsa_tfm_ctx *tctx = akcipher_tfm_ctx(tfm); > + struct rsa_key raw_key; > + int ret; > + > + if (private) > + ret = rsa_parse_priv_key(&raw_key, key, keylen); > + else > + ret = rsa_parse_pub_key(&raw_key, key, keylen); > + if (ret) > + goto n_key; > + > + ret = xilinx_copy_and_save_keypart(&tctx->n_buf, &tctx->n_len, > + raw_key.n, raw_key.n_sz); What happens when you call setkey twice? Wouldn't this leak memory? Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel