Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1953233rdb; Wed, 31 Jan 2024 14:37:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8CPHuWjbakLH6PcYkk3OgWP3qLYi7mJbXXJHcSK4Kl9UBI3aL6EaBPxAwsC6jEVx1KKIm X-Received: by 2002:a0d:ea96:0:b0:5f6:a23b:9d4f with SMTP id t144-20020a0dea96000000b005f6a23b9d4fmr2307061ywe.3.1706740626929; Wed, 31 Jan 2024 14:37:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706740626; cv=pass; d=google.com; s=arc-20160816; b=m6tZEKl0hLaqwQlBrsqVtR4WFGnBNm3jL51OqQEmCBDMmziMjsxXXnAA9LgrPgQTQg BdhwvfpkcoEzCEUV7y0Xh4OEzn4sxrdycr7lDqRVPHGgXXG1ZxXyerudDMSks5xMoNpG HqUlHFDK7QxxRbAH7kIhIE69ZNChFo20NBINYwymAiXEmb+U0gQrtlZlVKP/WDiwDDfq KLsIoWoIZepRfCfyMNdhTZIZ5YfGSWLXLs+C7Bdm1tnsLPMC4s8CYxgGm0Ey05x3TqJE kpOM8CdvMe/lXbw8Q/Dab+BsIongznQbYf/uE59E4moNPxHIfYV5FsjaP0I5wMzQ+Eo/ GvJg== 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=pCoZH7HUiSU0yflw5IfG5DX6qgN8kXKIe4+R5MH+S1U=; fh=XQqQHsQv8HoS9QeXrC8u3vo7xqOxGC7oPcUb3rRr/A4=; b=ptZXn+yedwF/ZGmjaXR6pbFT3ei1HghLaMRMM1iib0kdwN3bqS5nCbCVCY+iD+qNcx 2iNPidc2SPldy3Cd279du7XF1CiN3idikHllMBb9qgWIQSQQVqttEcJsDYM8zJFu9dqI WS+JZliSIN5ujLdRN9aqjwE5HT4chkI3m0MQSa+PdyJBCymT1yg8iZeQofjO+omqQFGe 85MN/jwQHoSKFHf6uahVi2GnXWh04rQvi4qS8fc6xuNrmqr6FU04rySVc9DXXou2C5Rm Se6sflGSI6XFXQupFZACniV7mwIMYLo0C7hZlzxYXzt7ZeQa4guWPFtBxFtG97wvKdEN eZoA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Pp/t1pJe"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-crypto+bounces-1760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s14-20020a05622a178e00b0042aa6bcf6f0si7473177qtk.680.2024.01.31.14.37.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:37:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Pp/t1pJe"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-crypto+bounces-1760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 602AF1C227E9 for ; Wed, 31 Jan 2024 22:37:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 129AB39FEB; Wed, 31 Jan 2024 22:37:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Pp/t1pJe" X-Original-To: linux-crypto@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4747539AF0 for ; Wed, 31 Jan 2024 22:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706740621; cv=none; b=oD1IztUWFnHzeT15egis+bS5ZpvGN7xalLBZ/wth33Ru0h8SZIeg7F59ZKjFkZLbDdWOpcdZ1liqI+/8HVUuPM/N3v6iHxAfc0xvHvw18SC0t9JNVppMasMxIOhmy9ssf6n01dK5qNA6VCl/QVsfS3v9OLv1zQwKBwn8BXEs2HY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706740621; c=relaxed/simple; bh=Iu+8D8k16qGF05cFe22hv0MQBwz9+bj5LdTjBKDOWeo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XrJCN7Eq1MLOVotvvKzzeoaiJhNft1+f8qx+x9D4PKi0sVKdBdrr6lV48cih1PCQCqnOMjnRx1Bz8M8h4FrlEXjYV+eZFwQSbAG23gIZ8wCt0k9yeYyFQ9FD1ZO8kMhA/PqpQ1ettoW3pG7Wq7hgAPoUFkP8l3Gmq069ajt6Uxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Pp/t1pJe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706740618; h=from:from:reply-to:subject:subject: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=pCoZH7HUiSU0yflw5IfG5DX6qgN8kXKIe4+R5MH+S1U=; b=Pp/t1pJe9FkBKxQawWmrE41nXMZG3iXS7rjSYNsC9ZgSdN0u/YJqSKUhL3fnYTkdC+JGNZ qJVQbNgVw/ug+VUxAJBPhPSCeNO50GZBNuyQlT1/7Czh0rvBX5v8kdcJwoyZJ6NHKExWM/ qyFX6oaPLHJFewzKlyYMZI7NBR9VpZ4= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-2cMT88fBM-aj09Y4ByT62Q-1; Wed, 31 Jan 2024 17:36:56 -0500 X-MC-Unique: 2cMT88fBM-aj09Y4ByT62Q-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-5110bf1635eso176136e87.0 for ; Wed, 31 Jan 2024 14:36:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706740615; x=1707345415; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pCoZH7HUiSU0yflw5IfG5DX6qgN8kXKIe4+R5MH+S1U=; b=ksvAD+32ZaHRHH8cXaE23LcPr3YIbeGJoTgDXRRN2Zgf1gUAMwflJNWqdAR1X3/64Q tCxNxLYvkkESFyjI2PU+gV67EcxY/scxIlJyoRY27eHJZsn+jqorZwaxdagEKCVQ7pMp 2+ZvTVeOIyRjNcGZ6IWFTi5BF0QvufjvnEyM8ezfkIsh7cb/Xmn0Hk08BEHBHcady+TD TH/4cBDOgZsmTBP2jNJWdhzL0nL1/hTjgsUU8RCmZ96m7iT/pG3TPyDPNlJL3IzumLFM L6/C7FgPMT9ANXxcKG5mK6tWqy8e/UKW9+lFHve1CXHwWPUyoEhO4HCwvJXMagTAX4QU m+0w== X-Gm-Message-State: AOJu0Yz/91mkANodIpaepWfLptBKZakbKqiWbHTyvMLy0P8mSFsT/wem RNjyoMOulpEC1EtbF4/NDBRdLOn4UC5JI/7k4+FD5rbjZFh6E76frRNFONz37Sq44SGCp7RntsJ weoW5yBKsM32wO30I6XIpniVtdgeAyNuONILeh4lD2awspWs0SknXJkTpywjK1g== X-Received: by 2002:a19:4f42:0:b0:510:11f4:6741 with SMTP id a2-20020a194f42000000b0051011f46741mr368286lfk.17.1706740615141; Wed, 31 Jan 2024 14:36:55 -0800 (PST) X-Received: by 2002:a19:4f42:0:b0:510:11f4:6741 with SMTP id a2-20020a194f42000000b0051011f46741mr368273lfk.17.1706740614525; Wed, 31 Jan 2024 14:36:54 -0800 (PST) Received: from redhat.com ([2a02:14f:177:15f2:27d8:8291:1cb6:8df6]) by smtp.gmail.com with ESMTPSA id fx20-20020a170906b75400b00a34b15c5cedsm6703708ejb.170.2024.01.31.14.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:36:53 -0800 (PST) Date: Wed, 31 Jan 2024 17:36:45 -0500 From: "Michael S. Tsirkin" To: zhenwei pi Cc: arei.gonglei@huawei.com, jasowang@redhat.com, herbert@gondor.apana.org.au, xuanzhuo@linux.alibaba.com, virtualization@lists.linux.dev, nathan@kernel.org, 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: <20240131173615-mutt-send-email-mst@kernel.org> 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 Cc: stable@vger.kernel.org Acked-by: Michael S. Tsirkin > --- > 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