Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3266747rdb; Wed, 27 Dec 2023 01:35:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxSbm41QiqSLKyr7PCYzt9ahVySC8Prdvg5WgeU1MH4nzh5qHJdKxGwmZxk5g03nxB6ByX X-Received: by 2002:a05:6a20:6a0a:b0:187:4cf5:f171 with SMTP id p10-20020a056a206a0a00b001874cf5f171mr3793406pzk.2.1703669749194; Wed, 27 Dec 2023 01:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703669749; cv=none; d=google.com; s=arc-20160816; b=XSs8Bes2SnDwrwLhRbjG62K12j9/1vrV/Vzr6Z9Rxl8f65ygWhzhylL4/1VlzQFV45 Wx+Rx0CXCdrD5n7quiLQgTrhJb/a4xOt9O27hK0HRbIwzmxAUEpP/aA8CKP4UV66SP11 YtEhxoxgg/BcQdGGIqb4MOglaLF9eIDy/bWSaqEuwq0EWXXq5uABKPzaBVSwBQEHOvup Pn//rkjIIfcqQeDAXyyliM1iJPTd6cw3yMEkI5bNWcWTzLZTVFFf9JVsVhBdRq0J0KS7 wesH1j0JVx5PKEWIfWPSBf25cNzWRx29vXjw6ZTgDlmdf0yzLKPZa1zZCASldQRs3xDJ gaPQ== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=WEC4zcxwHKDFTEYmQ6GdpdDwW3vxNmvaojdQff3FHAk=; fh=kB37YKnXwto0n2PeWnHiaXro5DFlj+MeV7LqMVMDhb4=; b=EYexSNN38S1L9lbapYxQKMV1klwb6a6Utl5Ouwo//xhE58BRoNcUz79oBvX5V3KcU/ UlR3BRDp2KU7RtKcGEjXvUhkIR42gFP7bfaCzmzTDkrw6sUhq+PoNJLncHngdquawPdj xRvmrTJm2zKD+sipo6Mw1oSUEyshgG5TxgQKUc9gIAhb3sUGnl2KI+WHkjL4MGtPAjA9 odCMbxtPFDV61vodrb4bNPMEE5xLzDY/1nfTheIgaMKpdQilbZOAICIolV7RZJ7aurvQ nvCO2xxMrsMzHE0kScf+No7e8Y7URTASe4OV45zoxYbbyCBnWWMjLpCULU5hsBXeS6PU iI+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Fv1yKosl; spf=pass (google.com: domain of linux-crypto+bounces-1063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n11-20020a170902d2cb00b001d39bf446f8si5643249plc.232.2023.12.27.01.35.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 01:35:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1063-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=@linux.dev header.s=key1 header.b=Fv1yKosl; spf=pass (google.com: domain of linux-crypto+bounces-1063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 9949D282BAF for ; Wed, 27 Dec 2023 09:35:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B4ED2D79B; Wed, 27 Dec 2023 09:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Fv1yKosl" X-Original-To: linux-crypto@vger.kernel.org Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 59CB72D78C for ; Wed, 27 Dec 2023 09:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703669738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WEC4zcxwHKDFTEYmQ6GdpdDwW3vxNmvaojdQff3FHAk=; b=Fv1yKoslVKu0i9egT0ibBU1nyc4CKUyHnyH+qi17lqjCS0jj0JYBrxMwvMLV7hvhNxbM/p HpIykdOBZY0q/858UD8D0zRuJoUv2iUHGpuS7VKIxeliXcaOOblewxHuLdjcyAcsCbzghF bKen7TGflyzTOf6YUpJLzfFIK0zaKew= From: chengming.zhou@linux.dev To: akpm@linux-foundation.org, chrisl@kernel.org, davem@davemloft.net, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, nphamcs@gmail.com, syzkaller-bugs@googlegroups.com, yosryahmed@google.com, 21cnbao@gmail.com Cc: zhouchengming@bytedance.com, syzbot+3eff5e51bf1db122a16e@syzkaller.appspotmail.com Subject: [PATCH v2] crypto: scompress - fix req->dst buffer overflow Date: Wed, 27 Dec 2023 09:35:23 +0000 Message-Id: <20231227093523.2735484-1-chengming.zhou@linux.dev> In-Reply-To: <0000000000000b05cd060d6b5511@google.com> References: <0000000000000b05cd060d6b5511@google.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Chengming Zhou The req->dst buffer size should be checked before copying from the scomp_scratch->dst to avoid req->dst buffer overflow problem. Fixes: 1ab53a77b772 ("crypto: acomp - add driver-side scomp interface") Reported-by: syzbot+3eff5e51bf1db122a16e@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/0000000000000b05cd060d6b5511@google.com/ Signed-off-by: Chengming Zhou --- v2: - change error code to ENOSPC. --- crypto/scompress.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto/scompress.c b/crypto/scompress.c index 442a82c9de7d..b108a30a7600 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -117,6 +117,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) struct crypto_scomp *scomp = *tfm_ctx; void **ctx = acomp_request_ctx(req); struct scomp_scratch *scratch; + unsigned int dlen; int ret; if (!req->src || !req->slen || req->slen > SCOMP_SCRATCH_SIZE) @@ -128,6 +129,8 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) if (!req->dlen || req->dlen > SCOMP_SCRATCH_SIZE) req->dlen = SCOMP_SCRATCH_SIZE; + dlen = req->dlen; + scratch = raw_cpu_ptr(&scomp_scratch); spin_lock(&scratch->lock); @@ -145,6 +148,9 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) ret = -ENOMEM; goto out; } + } else if (req->dlen > dlen) { + ret = -ENOSPC; + goto out; } scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen, 1); -- 2.40.1