From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452881; b=Hk6hUaHzb3c3UJTJGAO7IC0lSogDZLAXzm+JRDeCCXsOGK3fBjh7eKgfuMemM8ujk7sd 0WaAtHrN7Tt2SOtccZbkH3sb2Mp+U3/sf3AqgcklBfikTLltBbc/nRUOD8K1svYyxphgu cr/kXSs8Q5JtTShPPIxWVXLBuVtznWxpQ043u3fhbfLOYeXZUvm77QokEAj1k0wzhb62i q+5WXwDDxLpUCr5yKllrNvVXyJ8QzQvepHZqlY61HLB0GBkHpvpUjAclf22pEJxkb+NqA IIx6iDhXF2/l41yZX5MRFluykGWNhzMlmV/9yqZuoAdhEK6TyXuNp9iCQFBdsy9o8kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452881; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=wedbvPIYYO+Jv+VWCwHE2QR3bOpV5KI3O2vuZKIJqeg=; b=2GnVhMuywMQ6ttQZAR/ZBnl6ZgSp493HqHJSpTdCPWjgUo9/wUbLdxvAgeJejrFIg7Zr 0KRU8Wm0AUhyrcmmTlZkbRKi8XHG8E2tk5i/4RVasUW9iB77A8cvb0LIRd1U5hpzKHWKw F0RgN/obPMuOlGcxLseAvhHUNfB0lcVme2hWumn5V+Bj/Jl7l/0hA4BH4Ti9zEkuBkDgG 53dklKidQEcbinc6LNPqBVJStAEJNw4B63nsYIhoPIHljT8UF4IXfD4K34PPdrKjmPecC UCRx0hlgQaC90NFPa40hIaKpDf/t7WD5GauKm/Suc28i2101bjx30UTecUel1aJmThA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kozkOmKR; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32FB8606A330 for ; Sat, 5 Dec 2026 06:41:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32FB8606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kozkOmKR Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-38190551625so2016123eec.1 for ; Fri, 04 Dec 2026 22:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452880; x=1797057680; 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:content-type; bh=wedbvPIYYO+Jv+VWCwHE2QR3bOpV5KI3O2vuZKIJqeg=; b=kozkOmKRgcXMnm/2tYOjkpeZsvN8hS9ChcWQexCI5YZRZpeei4GGBbklDCMggcORWO nQyH5T7wItm0tusRxtA1hwN4XKwq1Qcyd1X0NFVzqZbytvuk7j5uPeCxR7niBADIurZu MUWV0dqKoUwlrEDFSGAxKdaly77w+azjJX9HpL+mcDK9k95WD+l60eBo6HdRaNHCbhxw lDO6XsZOGjOvbpZzbt5lK80UFSDu4e47+bxMJhF5aDMv4aWfBD4pNN4fgAlF8Qep7V7E 1C1c8U0mNBbU36fJv0a7PeK2qqNdmilcKy96f2BMK417S+hPVK409hCVk6t4wLdzuI/q zm6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452880; x=1797057680; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wedbvPIYYO+Jv+VWCwHE2QR3bOpV5KI3O2vuZKIJqeg=; b=wUO4K0bmabJ6C+a8U4nmXWA5f2/llhqqR71CNc+55gTe9A4q7nN8+0jq3GibMTtmBQ tZmMAJ/YxQS0smWZP1xbONmfaRgKWuBa+gIXL1aIDEy99G3XKYjjcc+nVYdo1dDJPV1m XQHunA1UDQkUgHUGlnYnIuCAQ7pPRxRGqnk/70CrDaniawpv2ijnCA+r6UJwnHb7T+bC jVEdd18Ss/6JBwYaAqFrAFKiLd4xFfLxB7AsZsqBA+RkXGCKp5BrdedxVXN9gju6aLA1 ocLAl8A3sAIBmX6B1+azsi2yOhIg+CC6BxOQZc2L05nLFReVJUJT68Uh3n7JF4AvhGzV L37w== X-Forwarded-Encrypted: i=1; AL+hErH1zhXaXcqFhbZLJcET5bZjpqsgCuAR4k1D4NSu2Kit9YKE4ausuB75NiLG+RPOsrK+Y3AGfeb8cVBiZK4=@vger.kernel.org X-Gm-Message-State: AB4q+uHAJdrxDLGN1FPvBA5bCeaVZGn3wcpZahgGmxWzBp5thBU23IpO PNiUVwYf/ZjieaDZjzfQt5NZiP9n/xAJC8QKN8Pz3XKrC7vzHi5Ebt3Y X-Gm-Gg: AZFdTZfneT1+x8L0cqesHwbW7wChtGE8WjmrfWY6h39e5NgGMQGnD5teyvE0lmBrEZG /LifWlXxCR44hngHbQQBnN064YdJTKaRiXRm5LttZRIOQ44IMR1T3uINARHCMMxFgoHm+xqFOGR Lq23AE1uNDckmdEL6Qwc88P1GMceVw5+utvMFpCR8hL9xIQjWzZ5QjeERt6YHL8qxahiSF8+VvA 0CAIi80ibT2f4o2+L7tTH++2piTbXzlrPsbgHIjynaFSPAIz66nO5fJWj5GLI7ZDceOnDa0uX3w KqFGyzzRP1MqCXw9JzSDEr81ns7oerWdFsKnEdNwaCUCyDZHtWyiJYILkNZsg+wgRsOX+rkPvUW dbjVI2OJTkTofwNL/j5aQ/PJRrY/28P8IE4LqpFK6RCAE6gvTf6ncvgSKaJkyge7T+LphJ+A/Qa tZaW98VVdkPNV8b8R11Lzw2MTWjv4dqTLIispPBMBD+ZOAblS8Cs13exPq4exW4zke/gp9QHmAq kyib9CzMfDwI6lkxbcPYOkhpehshTkQf8CI4N4JooMVldfnmfUKJeLg8yah+PCehZ44W2lCNlag EGyRU8gkA8vGNU3YegAFMiP/2/osAHiX6hfJ0yZu9RQBSLRjB9+eMQVFemDm2qVDXPlgmz4gflp yct2tzRx04OYr X-Received: by 2002:a05:7301:1402:b0:36e:b3e6:ebe7 with SMTP id 5a478bee46e88-387521c9ec2mr4275772eec.26.1796452880132; Fri, 04 Dec 2026 22:41:20 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875224895asm15246876eec.27.2026.12.04.22.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:41:19 -0800 (PST) From: Praneeth Balasubramanian To: Herbert Xu , "David S. Miller" Cc: Praneeth Balasubramanian , stable@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: bcm - Reject requests with too many fragments Date: Fri, 4 Dec 2026 22:41:09 -0800 Message-Id: <20261205064109.2526623-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The skcipher, ahash and aead request handlers count the mailbox scatterlist entries in u8 variables. They add the number of entries in the request scatterlists to these counts. A request with 255 or more entries makes a count wrap. The sg create helpers then allocate a short mailbox scatterlist from the wrapped count. spu_msg_sg_add() still adds one entry per request entry and writes past the end of the allocation. Such requests are easy to make. A large AEAD request with one entry per page, or an AF_ALG request built with splice from many small pieces, has enough entries. Count the fragments in u32 variables and fail requests with -EINVAL when a count does not fit the u8 parameter of the sg create helpers. A request with a wrapped count never worked, so no working request is rejected. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Fixes: 9d12ba86f818 ("crypto: brcm - Add Broadcom SPU driver") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64 allmodconfig), clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no reproducer. I do not have this hardware. drivers/crypto/bcm/cipher.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/bcm/cipher.c b/drivers/crypto/bcm/cipher.c index 8c3e9525c134..6a811a93a31f 100644 --- a/drivers/crypto/bcm/cipher.c +++ b/drivers/crypto/bcm/cipher.c @@ -315,8 +315,8 @@ static int handle_skcipher_req(struct iproc_reqctx_s *rctx) struct brcm_message *mssg; /* mailbox message */ /* number of entries in src and dst sg in mailbox message. */ - u8 rx_frag_num = 2; /* response header and STATUS */ - u8 tx_frag_num = 1; /* request header */ + u32 rx_frag_num = 2; /* response header and STATUS */ + u32 tx_frag_num = 1; /* request header */ flow_log("%s\n", __func__); @@ -435,6 +435,10 @@ static int handle_skcipher_req(struct iproc_reqctx_s *rctx) spu->spu_xts_tweak_in_payload()) rx_frag_num++; /* extra sg to insert tweak */ + /* The sg create helpers take the fragment counts as a u8 */ + if (rx_frag_num > U8_MAX) + return -EINVAL; + err = spu_skcipher_rx_sg_create(mssg, rctx, rx_frag_num, chunksize, stat_pad_len); if (err) @@ -449,6 +453,9 @@ static int handle_skcipher_req(struct iproc_reqctx_s *rctx) spu->spu_xts_tweak_in_payload()) tx_frag_num++; /* extra sg to insert tweak */ + if (tx_frag_num > U8_MAX) + return -EINVAL; + err = spu_skcipher_tx_sg_create(mssg, rctx, tx_frag_num, chunksize, pad_len); if (err) @@ -686,7 +693,7 @@ static int handle_ahash_req(struct iproc_reqctx_s *rctx) * rx always includes a buffer to catch digest and STATUS. */ u8 rx_frag_num = 3; - u8 tx_frag_num = 1; + u32 tx_frag_num = 1; flow_log("total_todo %u, total_sent %u\n", rctx->total_todo, rctx->total_sent); @@ -868,6 +875,9 @@ static int handle_ahash_req(struct iproc_reqctx_s *rctx) tx_frag_num += rctx->src_nents; if (spu->spu_tx_status_len()) tx_frag_num++; + /* The sg create helper takes the fragment count as a u8 */ + if (tx_frag_num > U8_MAX) + return -EINVAL; err = spu_ahash_tx_sg_create(mssg, rctx, tx_frag_num, spu_hdr_len, local_nbuf, new_data_len, pad_len); if (err) @@ -1275,8 +1285,8 @@ static int handle_aead_req(struct iproc_reqctx_s *rctx) /* number of entries in src and dst sg. Always includes SPU msg header. */ - u8 rx_frag_num = 2; /* and STATUS */ - u8 tx_frag_num = 1; + u32 rx_frag_num = 2; /* and STATUS */ + u32 tx_frag_num = 1; /* doing the whole thing at once */ chunksize = rctx->total_todo; @@ -1486,6 +1496,9 @@ static int handle_aead_req(struct iproc_reqctx_s *rctx) rx_frag_num -= rctx->dst_nents; } + /* The sg create helpers take the fragment counts as a u8 */ + if (rx_frag_num > U8_MAX) + return -EINVAL; err = spu_aead_rx_sg_create(mssg, req, rctx, rx_frag_num, aead_parms.assoc_size, aead_parms.ret_iv_len, resp_len, digestsize, @@ -1502,6 +1515,8 @@ static int handle_aead_req(struct iproc_reqctx_s *rctx) tx_frag_num++; if (spu->spu_tx_status_len()) tx_frag_num++; + if (tx_frag_num > U8_MAX) + return -EINVAL; err = spu_aead_tx_sg_create(mssg, rctx, tx_frag_num, spu_hdr_len, rctx->assoc, aead_parms.assoc_size, assoc_nents, aead_parms.iv_len, chunksize, base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9 -- 2.25.1