From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796322818; b=FhEnu/dZAI5TUwRzt+oexwA9TohyU5VQMpsqg3AiEYX+5UmlqcKl4wE1VmLFy931Sm94 vAIrgCymBLR5Rz7Q5TO0Iab1gwJ1krue3ky4X7THmg7g8tfDZlYA4hjkbmYJiDUzrQDoT yEalID0e0GQSnnwT/oW2AKWF6ueCIQq1q78L794ct76IwxPC9Ye0dDZ+HYGDEgislH5sF i8Fh+ckejb8dLjNznfMW60oarHZ6Dgv4trtHSE6ELwac0MI4bOXChYiF+BffbZm+O2A9e ndL0YH2BmVwbdGOBmrJxqAwVJxvihf4N+KkQz1gYyVliyacrxrpdQwImDrDWKHSSE/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796322818; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=W/dHxZeSET0F/31tFlLklxBvJ4MGcwWFIhn0Pd0byAk=; b=y4lM3j1DH0yH32rUTB3TmgmWJ9HOOD5rv8UqKQhS5gCLT2MDhC9E5eZbMTZAzjSWug0x Z0GVQDjwGioh9qvGD0dv8F8MtjEYs5IOy/5diHHEv1Adt5UzJttQbJqTJr8yeWEiLpSah 6PhkQz2iiAjhxPiT9uGxuTw5FAfhwEf0aNltX2mqJIuqUqo5pYX0SMcYoRaRYNx+3geIm a3n5UPv48MHVuw5zxwO/yjwIKDFAKp/fL9+CIyZNW+OWQ0YWU+uZZA8Mm7ik/Fn6sTAuK /wYoZdlNOwJjvVOnEIWATQVBR4zA7IsmPCztz9mg3HPMLul1lpLKmwmAVhlsQBZT4OA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U1aQ9t3e; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FC08606A322; Thu, 3 Dec 2026 18:33:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U1aQ9t3e Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF7301F0089A; Thu, 3 Dec 2026 18:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796322818; bh=W/dHxZeSET0F/31tFlLklxBvJ4MGcwWFIhn0Pd0byAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U1aQ9t3eDU3vpeyvliVgsaJ8ap/BLSe0sQnUIyBF1rUXaIOvfSRZavRmYRoeR8zhE JyVIeP4QTH+Mj/LI/7e86uRYfNqULDxagqZOOXfy85ghAPrkeQ3pko0nLYX7Mjo1tT nAyFWZoPJM9Uc8dC+nZa89AHsKcAL1pctf/cJm+s5llxFKyjJUxfk3coqvI8MyQKnt 6XDceBWfUnVJEfzku6Lo2w4gGhvtkqqdqEttR405FgMHG/bAnjvEY4y/FTFEAYR2eS 1Z1cIg0Z3dmz0Vc7spYwepQMdgGBrYog3OUppx1FfJt8JFmim7BYM7XpM3KUbpZC2I 39/0XmiJwqJMg== From: Lee Jones To: lee@kernel.org, Khalil Blaiech , Asmaa Mnebhi , Andi Shyti , Vadim Pasternak , Wolfram Sang , linux-i2c@vger.kernel.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 09/10] i2c: mlxbf: Reject zero-length SMBus reads to prevent stack overflow Date: Thu, 3 Dec 2026 18:31:13 +0000 Message-ID: <20261203183214.1939736-10-lee@kernel.org> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261203183214.1939736-1-lee@kernel.org> References: <20261203183214.1939736-1-lee@kernel.org> 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 For I2C_SMBUS_QUICK with read set, mlxbf_i2c_smbus_quick_command() sets operation->length to 0 and leaves operation->buffer NULL while setting MLXBF_I2C_F_READ. In mlxbf_i2c_smbus_start_transaction(), subtracting 1 from the 8-bit length underflows read_len to 255, overflowing the 128-byte data_desc stack buffer and dereferencing NULL in memcpy(). Reject I2C_SMBUS_QUICK reads with -EOPNOTSUPP in mlxbf_i2c_smbus_xfer() and validate operation->length and operation->buffer in mlxbf_i2c_smbus_start_transaction() before computing read_len. Fixes: b5b5b32081cd ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC") Closes: https://sashiko.dev/#/bug/linux-9d901144-2e2e-4106-9c52-4e02d97fca08 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- drivers/i2c/busses/i2c-mlxbf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/i2c/busses/i2c-mlxbf.c b/drivers/i2c/busses/i2c-mlxbf.c index 432d9588f32d..e85345906c76 100644 --- a/drivers/i2c/busses/i2c-mlxbf.c +++ b/drivers/i2c/busses/i2c-mlxbf.c @@ -772,6 +772,12 @@ mlxbf_i2c_smbus_start_transaction(struct mlxbf_i2c_priv *priv, * than once? */ if (flags & MLXBF_I2C_F_READ) { + if (!operation->length || + operation->length > MLXBF_I2C_MASTER_DATA_DESC_SIZE || + !operation->buffer) { + ret = -EINVAL; + goto out_unlock; + } read_en = 1; /* Subtract 1 as required by HW. */ read_len = operation->length - 1; @@ -2038,6 +2044,8 @@ static s32 mlxbf_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, switch (size) { case I2C_SMBUS_QUICK: + if (read) + return -EOPNOTSUPP; mlxbf_i2c_smbus_quick_command(&request, read); dev_dbg(&adap->dev, "smbus quick, slave 0x%02x\n", addr); break; -- 2.56.1.911.g883d8bcb20-goog