From patchwork Fri May 29 08:08:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianchu Chen X-Patchwork-Id: 2390 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id DAC501C08B5 for ; Fri, 29 May 2026 10:14:00 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=linux.dev; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-23696-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-23696-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id D46D03004278 for ; Fri, 29 May 2026 08:08:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC4382EC0B0; Fri, 29 May 2026 08:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IzCxCgfY" X-Original-To: linux-sunxi@lists.linux.dev Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 D0BD833F5B1 for ; Fri, 29 May 2026 08:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780042091; cv=none; b=JapiS2X0TVgjh/pBmeT7ecrdT56QQ7h1sptV048gseMLrs0iJ9do/soMW1+HJcNcYbFLwlEo4PQWtcRR5zG0+nChKQkEJGVVmmWmaxhRhvbx0V1XdC2+bgpLZtxuf66OQEVQykHP4l+c5Mxy9qEkh0u+pFfzeFj1Ain/78l5+iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780042091; c=relaxed/simple; bh=pwbq1GQXPiFQwNmyslF6wkzZlnjwVzAbBnldA7Mxa1U=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=fzJR2TJ72icy3gQkiWTlqPO2SjcFQCY3s1n5/R4WDUwxEnwf3UyjQyc/h5m257OkwtWetGo6nhre1tQQ6C8luJ1FdnsJEOGgjojKMeMw9i9OBq6ImXGtlNM93oeHvTe6AxHS1QljgQdOSwxgWr9lHbzZYVpWe6wZ8kU/Lu3TpmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IzCxCgfY; arc=none smtp.client-ip=95.215.58.172 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 Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780042087; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cn8RGbbWhMK+fmOfLvNDrpH9fQ9BHow0UZabfx8bzzE=; b=IzCxCgfYrXXqAra8csjkLDYzBUaXEP1y+20GkUNHakvuHgvPcnDcVazIECq/qCx+KlXa51 z9zMh+/V02p5KPJoKO5ii3Pkefr2lloZdWh0UE1xSxUpDsPzd/rR0+qFVIIf51SCtyi4Aw tnYQobxdi72BP9jrI96qSccPDLP3woI= Date: Fri, 29 May 2026 08:08:01 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Tianchu Chen" Message-ID: <4d4407c05835a50413fa1e974e3aa3f4abfe2d5b@linux.dev> TLS-Required: No Subject: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net Cc: wens@kernel.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org In-Reply-To: References: X-Migadu-Flow: FLOW_OUT X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= From: Tianchu Chen sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory. Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds. Discovered by Atuin - Automated Vulnerability Discovery Engine. Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: stable@vger.kernel.org Signed-off-by: Tianchu Chen --- v2: Silently clamp oversized seeds with min_t instead of returning -EINVAL (Herbert Xu). drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c index 491fcb7b8..7f6a51dd8 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c @@ -8,7 +8,7 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, struct rng_alg *alg = crypto_rng_alg(tfm); algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng); - memcpy(algt->ss->seed, seed, slen); + memcpy(algt->ss->seed, seed, min_t(unsigned int, slen, sizeof(algt->ss->seed))); return 0; }