Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3653222pxb; Mon, 24 Jan 2022 14:31:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJya+zctR1CdIRJc0hI2KEeCv5+SbImGP4xhKw0GsJ0cS/tZLR6/D8N6hF/PEnbBoG4MxLDj X-Received: by 2002:a17:90a:34cc:: with SMTP id m12mr472599pjf.24.1643063462607; Mon, 24 Jan 2022 14:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063462; cv=none; d=google.com; s=arc-20160816; b=yFYHMBV1zZ93x9XqjVxJOVCMO2RyPeOsvbmvrqg9sRRhWGDqcTB7RVgK9FGs9eJwaj hzof2VjR90iPd9nGeB/RmexbF+TahHWKJF//32mLbUicy4AT2QTrEIl+Rfem2uuZEAHu 6w4nK9qlKxzCIp76/yRWiH4nL6bAPsYD6/NitcY5pecL+SLuyMsT8GtLRfm4iNNvQo6r 7ONkcbdu0P2lQ13um/0pV5pP4ta2y5d1ga8YRLYfikXbZu/rrEl1grEsWLMXEGTPH1zY REpu9p7D7uBjdR7qvcJWgDa8qOe2wqxLCOcAxUmkQKsRcZjEXsuTHSnyhUOjuJg5dfZO CeeA== 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=4jm2cDhJLd/kTRruWjv8qXoSJSTLPHmkBTtNG/AmAmE=; b=Y2keLSuR1vtNUW1tNWnLFNIx7WL1QTy0w/Jk7dsmVPsYXNia3gsng9QIT8KdGGTbdY jMjr1wEj7aCL/hu0kz3/PRQTy/oF2yB7IdqafnV8Qe0Xo08UskMdMb2ltCpL/v4YrSrv PqjG1++v2Sf/ocT4RWoOTO58T0iUQd29OYlb8crXjm83tMgdqp5mBNtQMaomgRvokMcj fGQK1jD557lgh2O6VeEydlSXXywaAHeJNQD46GUTvefE5IxzxC7wQzAPtSNctBB2TaJ5 rLT/V1iot6YdtYYwt82nFexhtOEYygTXu4HsC4ZQGT27u5gAW1TWHOuWDAv1akK2Yuwu oufg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ee+6Edzn; 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 k70si8328487pgd.531.2022.01.24.14.30.50; Mon, 24 Jan 2022 14:31:02 -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=ee+6Edzn; 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 S1584427AbiAXWVJ (ORCPT + 99 others); Mon, 24 Jan 2022 17:21:09 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:44990 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1453413AbiAXVaI (ORCPT ); Mon, 24 Jan 2022 16:30:08 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5006BB8105C; Mon, 24 Jan 2022 21:30:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67E96C340E4; Mon, 24 Jan 2022 21:30:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059804; bh=P8uN7Qcdlnrf6K1w94rRAe6b7mk1wt3YZB943ppmnEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ee+6EdznbQGMeWMA3cysw69uuVJf6laigvy0HCqQKth3m2LJcuMrAYH1/mFG93oTc jRehgTDjv3C0SZ5FYyW1/3ayiuoExzgsIPl8WOKCMsGWKXUJYF+zyNhBmwx25N5YBP Te784DT9sNrpIWUx1FLBI9+exJ7Pv5d66p0m7mls= 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.16 0740/1039] i2c: i801: Dont silently correct invalid transfer size Date: Mon, 24 Jan 2022 19:42:09 +0100 Message-Id: <20220124184150.202022295@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 41446f9cc52da..c87ea470eba98 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -775,6 +775,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 */ @@ -788,16 +793,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