Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1858373rdb; Wed, 31 Jan 2024 11:10:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6EopcKfpUlj/L5zBmiXjPNUcfGasGKHyKzgPuoo4lpJg5TQBGN+An2oppdy0DQXj/a+pc X-Received: by 2002:a17:90a:de91:b0:290:c0a:fccc with SMTP id n17-20020a17090ade9100b002900c0afcccmr2417968pjv.36.1706728221079; Wed, 31 Jan 2024 11:10:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706728221; cv=pass; d=google.com; s=arc-20160816; b=oNT7JBbn1fAXz0ytUeTR5+LMSWd2Cr0iq0DERulglJm4Mq1x5odi1BwHiajVJnxoC+ 48XWePcql5tf+sNQGVmd/ghi38QXXMlPrrutqbj/sshmD3obTwdtFmYuNzmq6eINK9NK lMHjZ3fyoevsntJrruobaf+D7xSo8W2noQdMGuSAXOhQlrzijuU2W5e+rbMEahLS4Gtu IVdnuL4YqZrIQ5Wocwhz08jZOYOtBQpJhxMI2Jjjv9nrDCIPL6QEDsaSmchljyEentbo NJDCFT2kebDNKIlBgl6WJGrUnmq78y5VAnXrPJSS6QMlK9cIs+G4H7h33MaupbVToXtz X6MA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=826zwgHPxCpGWXxSCeYNHfsZwm+p/3krwKKe1NSTBvc=; fh=1GuYtKC7Lx+cPETmdfL2cJfy1EKanNiTmJDD4CIfvlg=; b=JLTFCzDL/H+Y8HF7YITV0VQERFeFabHZtS16o6ahwwDSu9+MUImjEUPCINzUw3mNkn A773XTDKNec72X2txxDcrydAPqpVOI14RZwQc1wEu23tuqo42/SjD4XWiF5I5TXZHhpW L7hlwFS1+tGKLMTZ8VxeTwO59g/DhtnN5LH08rJNuETOXScEvrh5YFOc/EB1OIgNuuaX 3xrUBbXeH+mIIwcSdJv9WmzG04G12HcIZGnOd4jlLYaztaW8nArEUn4Ls4raL7bKFNzE z4AgZQQQXDKGnIpVp8bSrILSS7rIKD0Q6LI0oWWfgIe5pAz2/jYa2rKvbyVOC/l6/REw B4Dg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WZN8QliN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-1758-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i16-20020a17090ad35000b002931b3873dasi1875082pjx.22.2024.01.31.11.10.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:10:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1758-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WZN8QliN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-1758-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B8F332878C4 for ; Wed, 31 Jan 2024 19:10:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C0B13770C; Wed, 31 Jan 2024 19:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WZN8QliN" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 210233715E; Wed, 31 Jan 2024 19:10:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706728214; cv=none; b=TvlH+fsSQDcg08Hb/fUDjcLMN0AxEN7UeB8MZnuXXv1GGzTm7IbSJzyTnFGvxfTZAiB9d51Ntvzdo0utEq6YIgxMvAob4hgSWUuxAUzkEgat1EUIo3PVDV7povMB8o3oU6R88B6ERaXgfoPExeEymA/TjIbLbPspxt8b10bzzZA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706728214; c=relaxed/simple; bh=YuGBlaaDD6uC/KXsWtFTjEBqEGYGFxartz53V+KSBQU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aOfo0pcl0fbKhtoCRdH8e+HZCURH6LMIz/VwJkm5myrVnI2sT+shwNYO0JIL7EhvRzcA8u5FtMEjd1CHchtc52lr7zvteooki0qjKpqbvv9MI1VkQbqTafRb/XsEq1EewXRoBLECkSEi6Wllwb4Y5tDT02vyjx6vwbHc1yFcj28= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WZN8QliN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE521C433F1; Wed, 31 Jan 2024 19:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706728213; bh=YuGBlaaDD6uC/KXsWtFTjEBqEGYGFxartz53V+KSBQU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WZN8QliNA2knu33YvywVNAsuKerSk0V11V6U2pfWg1KSPUQq0x3NY8psX+IU6uQw2 7uHgK95gmRPhnEgKK1DymD2ss8Su/LxCV98VMotPQz8LtS1/VjIthbdFRbuqShAH3z ZeoiXhxlmeB8NU4KKrCqmeUO5kO+cCe476SZ6Ux29lc9M9Nzx7ob1/q3bzVfoh3X5F Bt5smSIC7nCg13w+SRXqRa7MxZoTUwTlOIDuNSSz7n9cB6IKWlTRw/oPcjVw1n6MuF MxHR6UMVHG1JP273RiNj/Gvoyo1fH76JluEr+4e2WsBufIaUdYC4Qv1Rhu2HwMsE5O grkcvAk+7yk2A== Date: Wed, 31 Jan 2024 12:10:11 -0700 From: Nathan Chancellor To: zhenwei pi Cc: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com, herbert@gondor.apana.org.au, xuanzhuo@linux.alibaba.com, virtualization@lists.linux.dev, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net Subject: Re: [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy Message-ID: <20240131191011.GA679548@dev-arch.thelio-3990X> References: <20240130112740.882183-1-pizhenwei@bytedance.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240130112740.882183-1-pizhenwei@bytedance.com> On Tue, Jan 30, 2024 at 07:27:40PM +0800, zhenwei pi wrote: > sizeof(struct virtio_crypto_akcipher_session_para) is less than > sizeof(struct virtio_crypto_op_ctrl_req::u), copying more bytes from > stack variable leads stack overflow. Clang reports this issue by > commands: > make -j CC=clang-14 mrproper >/dev/null 2>&1 > make -j O=/tmp/crypto-build CC=clang-14 allmodconfig >/dev/null 2>&1 > make -j O=/tmp/crypto-build W=1 CC=clang-14 drivers/crypto/virtio/ > virtio_crypto_akcipher_algs.o > > Fixes: 59ca6c93387d ("virtio-crypto: implement RSA algorithm") > Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/ > Signed-off-by: zhenwei pi I can confirm this resolves the warning for me as well. Tested-by: Nathan Chancellor # build I suspect Guenter should have a formal Reported-by tag. Should this be CC'd for stable@ as well? Cheers, Nathan > --- > drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c > index 2621ff8a9376..de53eddf6796 100644 > --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c > +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c > @@ -104,7 +104,8 @@ static void virtio_crypto_dataq_akcipher_callback(struct virtio_crypto_request * > } > > static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher_ctx *ctx, > - struct virtio_crypto_ctrl_header *header, void *para, > + struct virtio_crypto_ctrl_header *header, > + struct virtio_crypto_akcipher_session_para *para, > const uint8_t *key, unsigned int keylen) > { > struct scatterlist outhdr_sg, key_sg, inhdr_sg, *sgs[3]; > @@ -128,7 +129,7 @@ static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher > > ctrl = &vc_ctrl_req->ctrl; > memcpy(&ctrl->header, header, sizeof(ctrl->header)); > - memcpy(&ctrl->u, para, sizeof(ctrl->u)); > + memcpy(&ctrl->u.akcipher_create_session.para, para, sizeof(*para)); > input = &vc_ctrl_req->input; > input->status = cpu_to_le32(VIRTIO_CRYPTO_ERR); > > -- > 2.34.1 >