Message ID | 20240130112740.882183-1-pizhenwei@bytedance.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-44508-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1161123dyb; Tue, 30 Jan 2024 03:51:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxNVbgX7X4V6SoXPHvyhZXFCXWj8IOsD1S0nnSzdLCEegos4LVmq0+20lr1ZyitAywhUXM X-Received: by 2002:a05:6a21:144f:b0:19c:60e7:a984 with SMTP id oc15-20020a056a21144f00b0019c60e7a984mr3951956pzb.27.1706615471223; Tue, 30 Jan 2024 03:51:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706615471; cv=pass; d=google.com; s=arc-20160816; b=NGmHL/Rx/XMGEayHzxn7SIZH4Hl51PAvsb2wUVgkgTLkWUMmvLHFim2+EqZPwk0fqg bOlTpo5aM/ct9hbo3x5jBRM5lPpo9afsTBVNselMs323qqTpWZ/DX5eNh2ZnuRjQOqXD xRJ1EEqmAZRMsYNwGBC7gUia5c0BtZ2k1/kaJQWOsGk/0OHX+zrcLdpoesokOA3BHSCF 15gRRzuIE9PB8hGuRzGBxN5SCkW9AvLRwYzeTooON487sW+KgOBOhmseLxg12vBYKhTh ukOXoSyhPlaCTegUYgpxvcAbH6bHNvXL9F2XA4K6haWrj00E53A9RCDhj41YHJiaZgiN hQ1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=NFz/ioS5pMtmsywy9UOLGQH2uroA4Qw/qVk4L7fINX0=; fh=JoBQPbzcpfb26whJhf5N9c5Er2YbyQRWHvz64MLMmJI=; b=GNGJIY/Lof40VXZcg6QqQG42wg4fvmZPEfB2uKQVFNmxmdZ/D3Tb5YX0n62tClZUxG 3rLnsDK8ntMiz/y51bfMzPL9JwhhYtINsvq3LdVZ+LzcSFusWt8xvhvID3XYT6xASLT4 +DV1E2ThEntSfH1XNazDgJc6nTVl9EH/UnnGZQ7HOORpJFJgbtvYvprU6oi+63G5s/cC eTBjMbg9R7QA58533hgRxxqoLpHN+Wtn76unoQ/1gnCkWq+7jsiHFlslLCDenIm8wqdd EjPiJvGIH20z6SIc3kjlzePwm1qZubhypw7PQI3kyzyA4N5ySMvW5G6tRfE0Zzpmrbsg 4nKw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Zhe7aujY; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-44508-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e2-20020a17090ada0200b00291041061e3si9317393pjv.124.2024.01.30.03.51.10 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 03:51:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44508-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Zhe7aujY; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-44508-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 44826B2C404 for <ouuuleilei@gmail.com>; Tue, 30 Jan 2024 11:28:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7B5B6773D; Tue, 30 Jan 2024 11:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Zhe7aujY" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FE28664A4 for <linux-kernel@vger.kernel.org>; Tue, 30 Jan 2024 11:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706614079; cv=none; b=Zs0w514ZQekVXl87tH0BMbkdAVhmrr379izf6PZZwzS+A+arWDpJBDUUYYX2OGY0ejAGrD04g8Iz3/X9UnSpGteUvPRZSVPd/kHjho37TcDy9MJxcaaN2jg993lS4juaQo5vQCCYkbgbn+THfljThzUYs74V+P2LXuQ0sBmGLak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706614079; c=relaxed/simple; bh=VJ3WxFyUH1QX/R2FezaIZrc9SHd0VxU+WMrUCCCzWbA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=E5W0CeLQ7cFLJidXSK9TZCct58eRIqmoIHjnYkQZIoG1CapqtBR9rhqsz3CaKUPcfkvt+lPrwKI18K8Kywf6VVWLoZS2EDaMH6HrQlFNFf0EeXfTEthMZuxp75uXefaITCLHMH11j45OAqs/zp+PaYBsMSTphqKseCOj0rCVHtE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=Zhe7aujY; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d71cb97937so20871575ad.3 for <linux-kernel@vger.kernel.org>; Tue, 30 Jan 2024 03:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1706614076; x=1707218876; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NFz/ioS5pMtmsywy9UOLGQH2uroA4Qw/qVk4L7fINX0=; b=Zhe7aujYvlLHVtXJZ3kv02iCcmFKPV5YO9MbmC0Mk12po2UQlDHCIGXR+EjbhYwQLU Wa6IatPOH2E73/nhTv8SCStzr8X58TvEgcnKDd9kOn4uVIIDtbH8NTdtR9Jg1WSEOhMh rmJZuCyJ+qS9UDHBu/miZ/kDCu1+7+xbK8PwDsK5RqzJi1Jgb+ObXi8T9KnpdSewo0Uq 4eFeSd348K4Q3lRNCH9aQmZLwREmG6G534N/sQNvbyf7LgXMHkw/uhhHuKLErvmre5yg /5WvLUMAgIZUhLxgmOf1gHazivLfcDnCp6wXI51bKvcgPiG8ons+6yNYHmK6VbAMQ7JL bQqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706614076; x=1707218876; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NFz/ioS5pMtmsywy9UOLGQH2uroA4Qw/qVk4L7fINX0=; b=Exs/RVrKvuc0bMQeEZH8f9/kZwxOaKSo9CGZiLsu61Qe07TwptyZR04a9QSbLFO8YM 1GSh8mgU1cRBE0GEehcSaf0MSf0iAUn2jWbQzOeY5CQC4hvS9VSdBitanIjtKFr+8f4o V/F2ZmnbdBtwyjM3tijZf6MUuvAt+qCKN09ZVvyBpqkuqeoO0ztIZWzOQVf58NlmlKLt iuyU9LNwsapD36bEN+jbN10l1ZO+PdSoQUEDQLAXXsx7KDPNrZUkEbW2XniabUqskd5l 1CLAAfe55vmxowttLWN4TQ+GNlcsHd0G1lIAmFqB1pWen/rhCQh89GuwSeFCB21KpHgp 4Nhw== X-Gm-Message-State: AOJu0YwBSJUJzSjWs0miKCP84roqxpS8GeLkaVUJ7IskgtZ1AsSOrC7s F1mALiLHPpKu3Q/tCOD73g2tld2IOxFB60E/skpEzvB7HWvTU8ls6lTGaYnXbAA= X-Received: by 2002:a17:903:2692:b0:1d4:4e13:6b59 with SMTP id jf18-20020a170903269200b001d44e136b59mr4044993plb.45.1706614075892; Tue, 30 Jan 2024 03:27:55 -0800 (PST) Received: from always-x1.bytedance.net ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id jz6-20020a170903430600b001d74502d261sm7002041plb.115.2024.01.30.03.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 03:27:55 -0800 (PST) From: zhenwei pi <pizhenwei@bytedance.com> To: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com, herbert@gondor.apana.org.au Cc: xuanzhuo@linux.alibaba.com, virtualization@lists.linux.dev, nathan@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, zhenwei pi <pizhenwei@bytedance.com> Subject: [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy Date: Tue, 30 Jan 2024 19:27:40 +0800 Message-Id: <20240130112740.882183-1-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789516024456716644 X-GMAIL-MSGID: 1789516024456716644 |
Series |
crypto: virtio/akcipher - Fix stack overflow on memcpy
|
|
Commit Message
zhenwei pi
Jan. 30, 2024, 11:27 a.m. UTC
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 <pizhenwei@bytedance.com>
---
drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
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 <pizhenwei@bytedance.com> I can confirm this resolves the warning for me as well. Tested-by: Nathan Chancellor <nathan@kernel.org> # 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 >
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 <pizhenwei@bytedance.com> Cc: stable@vger.kernel.org Acked-by: Michael S. Tsirkin <mst@redhat.com> > --- > 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
On Tue, Jan 30, 2024 at 7:28 PM zhenwei pi <pizhenwei@bytedance.com> 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 <pizhenwei@bytedance.com> Acked-by: Jason Wang <jasowang@redhat.com> Thanks
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);