Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564215pxb; Mon, 24 Jan 2022 12:19:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwSwdoNJ5WoRQ6AmERwKsxqSFmmtasslMf7j+BxSZJuraRG98PQPEygosVSTvZWqU0mhcG X-Received: by 2002:a17:902:bcc9:b0:14b:4a74:bb1d with SMTP id o9-20020a170902bcc900b0014b4a74bb1dmr6943855pls.40.1643055435846; Mon, 24 Jan 2022 12:17:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055435; cv=none; d=google.com; s=arc-20160816; b=HNOh5kmmqYaIoVH17lmqGFF4hpTxDOyAYKlNhELK4TY3Cj3W66y6C3MqjjG132Hy1S P+bZ8fEdngZuJ1OxTKrZcuUSS278582X6H3rrH9Xr1EbjQBEim+SsgE592lE5bC+b/U0 uKSiPk/C7ftV0FK+ZLsGHPKOINrYpknpZaDmdRLGqjzdAHYt9wejKXdxLa/V+w8HIjFF mb3QqVl8DsVnTohU0v+UAfLeSHASp4lnQLB6EZX7BHbJDvPHn1w+RV8u7q2u0vY/J5zm UQ7EdF6UW7IJ7h7LxZaHCyIrLngFJpbv02ZAgZJOrMrb5EzrXp+3Xbw3g4bprXalaJ50 mGwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XjNnOfRpkkZJuXYGaJDFt+3SnoRcy+pMKM0V6xk0NFs=; b=ZOOSSL4vpjA9qad41CG3Du/Bf5QBIKcdfhoiFUf74IArYkCp2vzjMAeAMvLPL11xpF Gbs1VKfJjskeCfEber7caGsKeQkZ1wGQXfKYSm6o9WUsGsVa3xXUgHMr/5l/wffP4VRV 3tUgs7vpMSdKduG/4RqTXsFJwLw7h+gf0SLJwMhxstfHIUcKBKrDu2zAHcZff6uy1Kcm VsAnDiB/CdZ0fEDrJU2y4H6CF3s54CG9Z4/QdtLBTNW1S1/e27pSmQLjt8mOWMlRZRhv ZwicQcNA0Lbd+uE78NoX2fCtvbE3Mx5ZPgb5ZT19JnqaIRF756KCB+H9cBB3gZVDKp/P Ns6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GUL0Rb1H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 138si14660517pgc.498.2022.01.24.12.17.03; Mon, 24 Jan 2022 12:17:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GUL0Rb1H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243010AbiAXTTP (ORCPT + 99 others); Mon, 24 Jan 2022 14:19:15 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:35354 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346740AbiAXTJ1 (ORCPT ); Mon, 24 Jan 2022 14:09:27 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 69B1D60917; Mon, 24 Jan 2022 19:09:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FE0EC340E5; Mon, 24 Jan 2022 19:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051365; bh=yNneMOoQvQQmJG7O7bWEOtcq/cm7Q7vMIAyMICcbcwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GUL0Rb1HHBhFrYHWRlwEjnDu1/H5qD+jxgSTDiBJbjBQhFbLqsnYvKedfvK93TpZR pr6uu9oO/hScMJYg6fE3WiTpT6aa2W4EaTHhl/QMg0vz90pZIj8bKi7nsLc6rC6SQM xGHfj8lDEzMfeyM3aj42dB+MvjxAjwZBgcxU8lsU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heiner Kallweit , Jean Delvare , Wolfram Sang , Sasha Levin Subject: [PATCH 4.14 137/186] i2c: i801: Dont silently correct invalid transfer size Date: Mon, 24 Jan 2022 19:43:32 +0100 Message-Id: <20220124183941.512341856@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiner Kallweit [ Upstream commit effa453168a7eeb8a562ff4edc1dbf9067360a61 ] If an invalid block size is provided, reject it instead of silently changing it to a supported value. Especially critical I see the case of a write transfer with block length 0. In this case we have no guarantee that the byte we would write is valid. When silently reducing a read to 32 bytes then we don't return an error and the caller may falsely assume that we returned the full requested data. If this change should break any (broken) caller, then I think we should fix the caller. Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-i801.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 7b1654b0fb6db..c817e3d4b52b8 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -769,6 +769,11 @@ static int i801_block_transaction(struct i801_priv *priv, int result = 0; unsigned char hostc; + if (read_write == I2C_SMBUS_READ && command == I2C_SMBUS_BLOCK_DATA) + data->block[0] = I2C_SMBUS_BLOCK_MAX; + else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX) + return -EPROTO; + if (command == I2C_SMBUS_I2C_BLOCK_DATA) { if (read_write == I2C_SMBUS_WRITE) { /* set I2C_EN bit in configuration register */ @@ -782,16 +787,6 @@ static int i801_block_transaction(struct i801_priv *priv, } } - if (read_write == I2C_SMBUS_WRITE - || command == I2C_SMBUS_I2C_BLOCK_DATA) { - if (data->block[0] < 1) - data->block[0] = 1; - if (data->block[0] > I2C_SMBUS_BLOCK_MAX) - data->block[0] = I2C_SMBUS_BLOCK_MAX; - } else { - data->block[0] = 32; /* max for SMBus block reads */ - } - /* Experience has shown that the block buffer can only be used for SMBus (not I2C) block transactions, even though the datasheet doesn't mention this limitation. */ -- 2.34.1