From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452881; b=qvyeBEScn/eqlrl7Sn2HZebAoldI8YCGCbkTUPYV4RUgKHC/PtRyyjoa3sB9wO7zfB5u Vdau+CKuzTE5lMf522mAMkjoPAgfp54n8c4L9NRudaBC72Oc8g3P74HPVH0DHYUPE3fYR b8j2+AShbPvoLQB56gxWAVQkq3ycsB1L7DkxfrTNJJCdZvbj3dJbISJgAZGhwnKxcPTbH 4yAt8UbtXsDX1SgD/d/7BMNx1UPNFainJOZA11w72SyMCPe7nu8QhUxZkL911jrpEQMTA 8OyH2gk0o//hJDLHAxYzMSHC005fsJHbhqkL+NoH1Ra2YGCyVJcBNtVzqAbH3q5BTkg== 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=t18XUTrUXHkWp3Iph15AYPfnD0IZW7KVQi5767yHOm7HZ3ohFEYdS5PPKLX6RDKaMVV+ FgUBKZomO1LWAVhwFFAPylsLYhd6VlgT0YRp2mWohYHn+kkS1b4x/4A+62aTovHU1KEzm nvgwMMhorLoim47OV3elyNuOQjS13uXPOXM32cSLLQ+OpilJCm+ZXznkarymGV45pd+91 FCGz5Qjl8rYdj/kB8CmXNPMqwrPQCTCKQU2ef3UTEFHsZMpgXQNy6iTqjbusKP0QCra6U lsIRDmE/lhJWpOfp+7jQrkmCQ2fz/kr6bTWhniluDSzZbXa1MqaOdEDBaJzVkwFda2g== 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.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 1F0CA606A32F for ; Sat, 5 Dec 2026 06:41:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1F0CA606A32F 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-f177.google.com with SMTP id 5a478bee46e88-387486ad5abso2653092eec.0 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=nyp2IUUHqWRghsh78+veNb7WR5QbWQiLIo1itTJghF3IwhFR9OC6ykuMkRD/QGRZQh rkgwBicK9V/FxlnnetDYKk4doNE+SRrZG8BsUMAytNwNo1XMOcFncRn5+cyLrqGrsonF PH/4M/JIYP41aSY8WS/KZA+SwLqaC5ttflCbdiaAHHxvT+Da8+W4/lJqNFUIYffemLxU lAh72aXEy2Vf61tHpDEWsMLYuUbmGLvF15vEQBpwZ9nt4vpcRTDUfHKACx1AiLQRZ+4E km80FR1A7xQ0II2bV8jYOMRXYR9NeHPkDCGd2Rq7TYz2Li4M2zVlirlDs0knVSC2F37q MW8w== X-Forwarded-Encrypted: i=1; AL+hErEQKb+p2b/u0J/vELUGGTfPjZsJ8YNiVDBfQ5ewL1LKeWkmAtWVgo35UMfj/pkaAG/hsVhTUjo=@vger.kernel.org X-Gm-Message-State: AB4q+uEUzmEdcnqYDObDvHY3z7tvKLDZZJ/xEIffqlmluQ6zC9HIlt0X TuzhNU0f+9ct3DOaQA8uoGT4zoVtVAUTLctj2SFgkNBBau5no5f8DSn2wxlYG24c X-Gm-Gg: AZFdTZddXOpo0G1e+Uin3eWID/cGB70RvyhLphBM5pH1RB74NselGNw0IG+G1Aki2YS WWdQJRNfWPnBE2omP45kDdiPoFpaKXddaSz1bNk54r/YGE+TrZAM7wAlDA9yv70l9ctVkEh+RoY A16nPl2Nw1H3eR+A3HDmPt+cugy8Oakd/ot5kD+tKrRyEGdglcvYrMPWUBWlBaw7nVZaCLr/dQa MAzZSY5iVqdjQCVwfuO0eN6mHqfW4r94+tdOc8cjfhUsxU4gx73ihOXyIRzQsTy13lwAGL3Dfma 71Xepz3amjCg0Poiwon9bBgsFGucZOJ79vrJxsub11rpbnFQazL6wKlRTNrM7B998zKPOHa9ATn 1vovYbVNog2+fD9NX5V8XFF3yA4Oy/4bmx27UyUjePpeSFcBmEQuu7sdpYBwaNYn+FL+xocOEqw zZBXmkSXEGfb6wiigadz6HCMxRcSufndxMl8rb1y5ukYMGQjAgMJC+eq+KnIgPwKfJljYr6pnMw 8W4/mF0xKp1T+ovsPcTZoXe1h8hUnqFOEyq4+hXD1ALoi9rwiTORivmy1ydoHbb0DVoU/w6zfnv pmXk933DYLDKD6WanCzlNSZqTnVoLBQi9meyF41aqBfHKr47CP2HjAEUCUeJdXFJiC7vSMXcBI6 mRfzo7glmDm/Z 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: stable@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