Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3584012pxb; Mon, 24 Jan 2022 12:49:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfUYOaZHH6cSEXeQfW2z/Pj0zKfuQawaP3gVvzcW613hsZEgIMIIr13RSfuy+i7WZah0tP X-Received: by 2002:a17:90a:bb0e:: with SMTP id u14mr110747pjr.149.1643057378969; Mon, 24 Jan 2022 12:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057378; cv=none; d=google.com; s=arc-20160816; b=L6+qZz+WoFmqBrFp38ZIDOTg67Qz/m11pxVOBBI73zivPCaYdVx1TILyx3pblgeTX8 pXXlD0SbAQcbHBgeAkDMIyVloq1RH+z3XzK3az/g3OcNO48Zmt8MRRJloSDAodvqKmK5 nxK0Ycp3wkA5a3P4kPZTn5esaxfvm238QoaUP8OfEOLoIyv/pUtJLrjx/Fiy7io2r0Ca 065hSs4TZ0GIRXvnxdFJbkl3wFVj6k5yB4FOE6xQYMFc6FMX1BxJQrymVDCCPVZiGymr 3hV3SLX1v1OrNGMexYGrsCZZN+yK3zuVCqHwOLsLivMl1xsduTueTLL/twoRtlOzRXIR wtTw== 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=0oGD6uFEqEPC30Oz54LZVoA8HvPxOAs9weHJ62mLYAY=; b=oDp929ncnmmIx9tUfjDcLnpL5HqOuuj2o2d+bZ1c0xkGU4PztRXy29vhqh0YATEcrz UTA+UUbsxH7MsJkdKU6HHECsLw3RmhozkfC+v9oDkzhNsBq05xtTPoD8Hj7KGBq9elha 353D6TLA8gAM4bhvQSs5G3TbXkqC2mJ+onPYxUo4PByIcLjHGS6zAl9c9IrqlphpVFeY t+lcko3knDDJXYxLpXvtshJAVnRyzDfgOp2pl9OS32XmVtYeCwWLoHRaIRG73Iws62Sp nJxVE/htu9+MuGyRSgn2H1km/8Lh1Nq6PKEIHRU4j8uXsOJlBUoezONZpYLx+JQ/dOb9 nHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kLRp1dQb; 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 w71si1345199pgd.43.2022.01.24.12.49.21; Mon, 24 Jan 2022 12:49:38 -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=kLRp1dQb; 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 S1377227AbiAXUFK (ORCPT + 99 others); Mon, 24 Jan 2022 15:05:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356808AbiAXTrX (ORCPT ); Mon, 24 Jan 2022 14:47:23 -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 23B4EC038AE9; Mon, 24 Jan 2022 11:23:06 -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 B795E60010; Mon, 24 Jan 2022 19:23:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D07EC340E7; Mon, 24 Jan 2022 19:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052185; bh=q5V/oWsy8/Any2yGd1E9n2BPhXEB4Nbics/VFJRxRGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kLRp1dQbdqFXE6iHDkMgd++kF/Kj+TyQPArv0PLjIcEYGnscjJzcbIa4up74XZ/6N 66+YPSeDJB3JHnC2atdXAvSXyUMVHaBvy71sVdrXGL24Vfe+rJ7z9521mbL+Lw7sXA 0Z586HCNPrLjqDoqiWeSN3uoQ3WxjzvkxrMTr7T8= 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.19 183/239] i2c: i801: Dont silently correct invalid transfer size Date: Mon, 24 Jan 2022 19:43:41 +0100 Message-Id: <20220124183948.918214094@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@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 efafd028c5d16..fb0ddaad87d2e 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -774,6 +774,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 */ @@ -787,16 +792,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