Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3552599pxb; Mon, 24 Jan 2022 12:03:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrQaKA6ZKTleXDa0ujEoQBkanKdzkf0uQzJS75M7MTN3SD4erXbmSBwy6JlocAEVxJvIJq X-Received: by 2002:a65:6a8c:: with SMTP id q12mr13066168pgu.314.1643054635328; Mon, 24 Jan 2022 12:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054635; cv=none; d=google.com; s=arc-20160816; b=NE420BDQxRcqFgaNrKec/P5+ROWfPTmMICQaNmgODDFosSahbJrtv3E0MDR6z7fpS2 Ikj6SW/Q1Yo1bo6H8E+TluqXnYAakZTu6/cbtpyW4qRDwCcHgKNfZmRDwS9nXtAIOKQK ZrcIEYd4JViIA278u18xeddaKOyJDcYFpdFsm5rDv/zuYlcOJ36+dYBtsFafQiDxj7cL L2oD4E5U7PrbZmnu3UwkG5PlznxGIVq0tCyOGAmTU4maRs60cUryEDYUN/whZe4B7JWi 217BFPeu+Ajdmu3gi35rp8Bid1JwYcR/xcGGGLm4RReYHixleKIAbfr9Vn9xd6xKeGCy QJnA== 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=sEqvy9AdPmmVRwIMWxYng6f7doYjl6v0gCYC2xuaOfs=; b=BZ0csrBmpwnZhvHDj+XLxPtoekDYCg6u/lnGyiLhxYmo9yGjyVn7PXZjOei7RKtHET ZZ6GpDpuThp4f4Dq59WSEtEF/WyJcUQAylFuh0Jxss+tpiIOSBtBkB0BdFFk/SDGfI/i +q6hLRSy6jzaBo4ncSwqF86N9KSh3OZCRhpR/hYEqBu2RTfL/zMx6zXiuaxEHNnxm4Bl agBoq6UEXBcwllw2QENXe1MFL3yR5pG/AX6UpkgmlkIfjB2TADVbMtmLPdyt9+XjgyOX IfPEKSruMF1DR5otDt2UFP3LT612NDL94cwrGhi25DsdSphl7g2uxO0VfQhwl4N9xnUA 8q0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JpN2lQH1; 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 lx10si305788pjb.162.2022.01.24.12.03.42; Mon, 24 Jan 2022 12:03:55 -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=JpN2lQH1; 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 S1344507AbiAXTDu (ORCPT + 99 others); Mon, 24 Jan 2022 14:03:50 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:57212 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344997AbiAXS7o (ORCPT ); Mon, 24 Jan 2022 13:59:44 -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 E1830B81215; Mon, 24 Jan 2022 18:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01E89C340E5; Mon, 24 Jan 2022 18:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050781; bh=Nnp6w8GL4hiQozY8T/6HlO69LhX6+pjDvbt3rnlGots=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JpN2lQH1L0GC35MmICwqcFQCpWOO2W37sGPbuNkzpnLwYi7FmGhSd59WYdC4B7Yqr yKuShdZRPrkASHIURUAE1hX9jxshFXaHsAQbHNi4LWGH+RAEyuIHt5ezNT36JpCByL xIa765JWGnn9M2bd5iFQYrIoLf2L75iEHpTyZKsg= 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.9 109/157] i2c: i801: Dont silently correct invalid transfer size Date: Mon, 24 Jan 2022 19:43:19 +0100 Message-Id: <20220124183936.231220313@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@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 0e04b27e3158d..b577c64f3b3ec 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -762,6 +762,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 */ @@ -775,16 +780,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