From patchwork Wed Dec 27 06:50:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 183429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1276896dyb; Tue, 26 Dec 2023 22:52:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IExDJW6EORmS2QoS7+fClfYTIjxpwYnEopkyuHQSbv1KdV+4Wt1mhmer6vbZtRIXxvyNv9Q X-Received: by 2002:a05:6808:ecc:b0:3b8:b063:5065 with SMTP id q12-20020a0568080ecc00b003b8b0635065mr8752404oiv.102.1703659932164; Tue, 26 Dec 2023 22:52:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703659932; cv=none; d=google.com; s=arc-20160816; b=vAf6SGbDk2aaJre2tdiRpuWhMnKKaiOsHzxZiWsRFhGKg52EmDQ/ect2q+04abtN9Y TizdcunW4ilYjoImVgvoLeE3B3YzjH2jpW8mQZkYIQ64ldNFEIW//uGJerI4VZ05qTMY 94EDBHeN0s2UtX4zgQfoNI8LTmJceDIHuAVIB8x5pnTea7KJTWJbmt0K7y7w2jOmVjrS /pyaKcjKiarmz6EP8hxZY98UVU7BEXvJqSxdLvzID+n+2jq/QdU2p/fBsUGTH5MRQF3l mRcpN6evnpUcRPOcJv8AjU6/IptSGOX3yU19wxUBZ1q6Jtv9uonvGyMUkP9NEfSovAE5 AEnA== 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=OeQExhHi5Vd7SrAH5ft3KCB3OQiAlGwuGPIjrZR0NGs=; fh=kB37YKnXwto0n2PeWnHiaXro5DFlj+MeV7LqMVMDhb4=; b=etkq4+q4+O6cHQO0IP8f0tFGpksP/JYs+oDXDSLjV3Roy4mksCsBctU+T78XEvfS5c 4nEfA32OTIZSbsd1wvgFcnbaLjVxEsvCxQYYGKHSwp6hvUM44KYcnLhg0/wuX8EiXvwh 79VqDAc8aQt97Eq04GX6B95wQAp+Q6hBeWn5Kbi6GEf8y8F//mCjwHtjYD0dkng6+irc WOvw45NrHL9aFhpe8xwTaXH324ga9Z829cY/Um2kmD2NVM5vhWEPCp025g6Ew4zRPbSU I37QfFpH1gaY8nc6OjOG+om9JpQoGo2PZ52RWkmW+r+6OB9ZN+AsDZVb12vQ75jBRSP3 AWhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Rs48Z6p5; spf=pass (google.com: domain of linux-kernel+bounces-11869-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11869-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ei48-20020a056a0080f000b006d9a2bef966si6550522pfb.238.2023.12.26.22.52.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 22:52:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11869-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=@linux.dev header.s=key1 header.b=Rs48Z6p5; spf=pass (google.com: domain of linux-kernel+bounces-11869-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11869-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 214ACB2260C for ; Wed, 27 Dec 2023 06:51:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D56D15CB5; Wed, 27 Dec 2023 06:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Rs48Z6p5" X-Original-To: linux-kernel@vger.kernel.org Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (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 B2A9B538D for ; Wed, 27 Dec 2023 06:51:36 +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=1703659894; 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=OeQExhHi5Vd7SrAH5ft3KCB3OQiAlGwuGPIjrZR0NGs=; b=Rs48Z6p5Rzw/WnnJJKYcVqrZ5ATPIk7PnNRMZ+elLdJan//SC9HkBIlxbv0aqWuosQMvMV MudkpdctEIn/2loZRlq2K6apF+whT+rEt6qSsqL6KkaF8aVGlD/bOULpZv+dAv4ZTjHzij 1kJc4LA/uX5xM7AjhmS84oSA2ZQZRU4= 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] crypto: scompress - fix req->dst buffer overflow Date: Wed, 27 Dec 2023 06:50:43 +0000 Message-Id: <20231227065043.2730440-1-chengming.zhou@linux.dev> In-Reply-To: <0000000000000b05cd060d6b5511@google.com> References: <0000000000000b05cd060d6b5511@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786416916508003782 X-GMAIL-MSGID: 1786416916508003782 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 --- crypto/scompress.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto/scompress.c b/crypto/scompress.c index 442a82c9de7d..e654a120ae5a 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 = -ENOMEM; + goto out; } scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen, 1);