Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3729051pxb; Mon, 24 Jan 2022 16:31:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2yk5oZHPDnr3aAhhUb+yTX3yualGRG0Nnj3JDrAXckYqVTXzghunqp3WbGEfNC1S5nd5I X-Received: by 2002:a17:902:ea10:b0:14a:f84a:bfa0 with SMTP id s16-20020a170902ea1000b0014af84abfa0mr16473024plg.163.1643070699768; Mon, 24 Jan 2022 16:31:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643070699; cv=none; d=google.com; s=arc-20160816; b=cSxQ2KDAJVJLhOKh5NAqhb3Q+hixXmFz07vyYscIU91Qk1dJvwcJDAyD/7IWEfxSQF YoFneC7yo9976MupWsiGbU95pRbrX45Hg8eXATDvMu1LNUj8h2v4+HXZ9ORaMwBKS/Qn ihvOCkP1D5tsmXZRUneZ+vAPYTVau74xr6CpXCPZCh/AZ3gjQh4eHAKTV31TeQ2ENuoi PXE85OaWIeaJGRVBv8tfxQ7+NLb/u7324Q61vh5KAXcSISa9eeNbSh7mS9J07SP9GmbF Y2O2AvYkWULlFkrx8aIOskahSsYbP8IN1N9S0Pq8iv0iy5/FU2fRXelZmg24gKC4CG9i JG6g== 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=p/k7sl6DNGCHJIV26sPUzDtH4RdstFWSQyWevi6pPP0=; b=0Ry5iCLB8DNCf+57FyIsCdvP8X6RXBjc4mDgTlULo8UbR+77SeSsVxFWmTvww990bI fkmlpmRZJyqOnikKUjku6uf0DsBlvJxMNMkR8xmY31HvImmOELwNMRTia2vGmvlt3Yvh dXgspzwsPotL81HFKvZT3iMZ3sm5VuHxwgyZtdgbfMeUo6yWJM6sjV6IiGMi22HwlGQE vCpRzmOsLtKq3R++UnE55qo8HP7PnofqhvhA44csq5cYx5aLXiBvLxQg8IXb+pO0H3Kd faWgYusEddbTqKzQi+x7nfBG/5lPBPlM7SlGIao7vaF8w84m2v8JJ8Qg+XWRMGoHarae Dcbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wEQ6S8YQ; 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 h6si15480906pfi.262.2022.01.24.16.31.26; Mon, 24 Jan 2022 16:31:39 -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=wEQ6S8YQ; 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 S1344564AbiAYAYV (ORCPT + 99 others); Mon, 24 Jan 2022 19:24:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1578510AbiAXWDD (ORCPT ); Mon, 24 Jan 2022 17:03:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6978C0C093F; Mon, 24 Jan 2022 12:41:18 -0800 (PST) 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 727E161008; Mon, 24 Jan 2022 20:41:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 531E6C340E5; Mon, 24 Jan 2022 20:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056877; bh=3cmUl0Kng61V5pxa0ERWvC6ByxCde87qlfadGwheNM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wEQ6S8YQNfy0Pisb2KfukdubQa8Z7lQhl+wGCaJpKFm/gcK1lLmRlBTDfRDGm0wO5 92kYLZrLJcbv0g2uehF55MOcZNNPNRkDYUEJXzkN82T5QCK1DJTt5zqSFzqe836b5/ 4Sfe7IyijmOishsZowA6mxfBzHBVTuWzIDxNJ5ao= 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 5.15 629/846] i2c: i801: Dont silently correct invalid transfer size Date: Mon, 24 Jan 2022 19:42:26 +0100 Message-Id: <20220124184122.734921413@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 1f929e6c30bea..98e39a17fb830 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -763,6 +763,11 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * 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 */ @@ -776,16 +781,6 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * } } - 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