Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3210039rdb; Tue, 26 Dec 2023 22:51:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE/13OXDC00HZAk/clT/D4rUAw2UqWdwiApl4L+q32bVuUoerhnbadmzKcECsyqS87q73l X-Received: by 2002:a05:6808:1190:b0:3b8:b063:505b with SMTP id j16-20020a056808119000b003b8b063505bmr9938825oil.92.1703659913732; Tue, 26 Dec 2023 22:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703659913; cv=none; d=google.com; s=arc-20160816; b=l4B/jdejuh10VVvoQW1dlg6cSSOV1tFoJT7FCcG9yxdkqD5Ul+xmpUfDdn5tzUyARv b8l10HWC3sHmF3jWLnZAeU/js3PNHFlWUp4l/vhhCw5SqmM83lSrNNlYRMyvzh97A7mA 35qmygaD4YH0w+zqAlfaK5c6WLFseJPGuUHpG54QqiizSMoQqaTT+2zf/RdbfkQcJFeT f6WEl0me15LPvhprOJ01b+J8MXoGYj9PShPNg7lFRV7rkrde5wFYueOZfNEATO7TAWNN TkJur59VPNUHgusagc8kjG8qMlIkMgZHhXypAT5mmngDk4yXu61nAqSCdpNAgzXdbw1Z W7nA== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j24-20020a635518000000b005ce17cdb6f3si5188013pgb.872.2023.12.26.22.51.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 22:51:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11869-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11869-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6956FB211A9 for ; Wed, 27 Dec 2023 06:51:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06C5853AC; Wed, 27 Dec 2023 06:51:40 +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 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 --- 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); -- 2.40.1