Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp200025pxb; Mon, 7 Feb 2022 09:15:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzA2fqPypcT+e9gU064ikUKhW/BVh02cltvTmispiycsO0GczB/uFhiQ1zKIqgHJfMtvHY1 X-Received: by 2002:a05:6a00:2129:: with SMTP id n9mr324432pfj.71.1644254146605; Mon, 07 Feb 2022 09:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644254146; cv=none; d=google.com; s=arc-20160816; b=h+10sGKADlEaas9gT1MUnsIqYAqRSLc+EjsBIW/nHCwIxXG6FQzmNO6VxhZ1Mn0kpS XhaGcPThInRxppoGb3r8yzMCW6ULFclW/fNj1Yp+/XehahZ+IWJ0V10WqW83rk/rL9wF 3XX1MDzBdChzvHLOT59VMZq7tugiuUuYd6OyuSd8OKw2zZe7OASnTugmjKQ4Cm/cO7GY ULHZ9uja+xOMcHdnHqlH8jwO7dFjKLhbCac0n0DDh5z2nYN7KJSy30BWHaL7jwCV67Fd wh8BT8SnPuzTVoPnZlcS7inofVo2gfYjg5gWT4jFjBWntTNh1rKPVi1S6tvevpm5qjek bqAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=sovBYQAcoAyRD+IIp48jmZd62dc3/cLT/aahzL7f+PY=; b=dbAW0VCHL1cXLMDQAxw8l6xnONp6sVviMbY4dsQxesXxOYGHu5JE0R2PrANg8u9e6c rp5MEOLOCq8dOHQ6s93hONkljRXGW4Dc/iLdrONNEhsv4zT3SGHHIC6dqvTdm0aDbuvs hsfqJYvVTJU6J+b6suja7ze0YV0AtJn7OgsXwzByagJttEn9F/3yjOdnVFwTFZmVtXwQ UxPbQdrYZBaVZSTujU7TYZJv5E+UZv8a6u/JcN1b2Kq0vxQ6vebtAiIcL0TWxJx3COx6 DYO9Ii9W+BXrnCYakh30s7HZpueuWnQwz/3W0bX7qiYE57uEaPBaxvmOHl6P/8Wk51Fg u0hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UjJ6eCdC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7si10459294pjp.108.2022.02.07.09.15.33; Mon, 07 Feb 2022 09:15:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UjJ6eCdC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344745AbiBCRLR (ORCPT + 99 others); Thu, 3 Feb 2022 12:11:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346667AbiBCRLI (ORCPT ); Thu, 3 Feb 2022 12:11:08 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C000C06173B; Thu, 3 Feb 2022 09:11:06 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id ka4so10752688ejc.11; Thu, 03 Feb 2022 09:11:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=sovBYQAcoAyRD+IIp48jmZd62dc3/cLT/aahzL7f+PY=; b=UjJ6eCdCr1s35/Zo6xyKw4ExVCZWsabyMSRJPkW67/rmaNf6eywVd5fYWuVKjzsZ1a hkEqLCHF//sbgceQvWe/DKmEw1ETKhUbrxKLa5NwHqHyzskqYVDomlaQlVp4I2u0d+tp 1Zv0nQ7fTHzczJUWhlhsUyE+skpdhD+D5Tikriz0fV1/DmZ6/SJKpNrSBM1puEVLULiV Iuy8E3nZTM0q/d98bV6q4+HXzeHVDwEjORppIh2FXwNtl3a4dLSQz98FpBa8GfsrEwFV /XHfVa4XimsgNOZqgQkeqnCAObuEufllNAee3Qx2GZLIhcibJyVaajFCD4my587rkZBz jcUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=sovBYQAcoAyRD+IIp48jmZd62dc3/cLT/aahzL7f+PY=; b=CoMTD7P1jo6myrtiRPozkSS4Hc0Ir+q7D4Acs0wJ58MEOI54uNJgRXGDyqu7wV0A+/ cckJjyhxAHufpwJ/dwbSmvEfEq4l9kK0NmRGoDRA33w4M3PnCU+kMPAO+S8ZlOQIofxr x8Rv1Ri4o7EuWpoLmOsdJREml1GNOic6hsP4N9pA3Q+oP0IRYSxlVDm9iSBWzNj8IrZc /hfDbr5E0hQV5Ua8G/YWoEqjyxP0CG5fZkPQwrXusxKFsLYLnw3PXB+lYPCkPXPZyUD/ gwmtCDr2o7tML4MHgvSSOL0hXz5ZZ/0VefuAI0km0RAl+k/C4n5If6/sUIETdV44pk7P OvCg== X-Gm-Message-State: AOAM531Oce6xEIeEnKJsvXuLQC3rpu47coCI6qcOMHCV+Ut44W4ypGKH aD5Pw/NQbddxKhLYAuHH2Jc= X-Received: by 2002:a17:907:868f:: with SMTP id qa15mr32261051ejc.518.1643908264487; Thu, 03 Feb 2022 09:11:04 -0800 (PST) Received: from ?IPV6:2003:ea:8f4d:2b00:71d8:a0a4:4bb5:bafa? (p200300ea8f4d2b0071d8a0a44bb5bafa.dip0.t-ipconnect.de. [2003:ea:8f4d:2b00:71d8:a0a4:4bb5:bafa]) by smtp.googlemail.com with ESMTPSA id u3sm17315462ejz.99.2022.02.03.09.11.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Feb 2022 09:11:03 -0800 (PST) Message-ID: <84f17973-96c3-6513-ca4f-20750c896e6b@gmail.com> Date: Thu, 3 Feb 2022 18:10:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH] eeprom: ee1004: limit i2c reads to I2C_SMBUS_BLOCK_MAX Content-Language: en-US To: Jonas Malaco , Arnd Bergmann , Greg Kroah-Hartman Cc: stable@vger.kernel.org, Wolfram Sang , linux-kernel@vger.kernel.org References: <20220203165024.47767-1-jonas@protocubo.io> From: Heiner Kallweit In-Reply-To: <20220203165024.47767-1-jonas@protocubo.io> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03.02.2022 17:49, Jonas Malaco wrote: > Commit effa453168a7 ("i2c: i801: Don't silently correct invalid transfer > size") revealed that ee1004_eeprom_read() did not properly limit how > many bytes to read at once. > > In particular, i2c_smbus_read_i2c_block_data_or_emulated() takes the > length to read as an u8. If count == 256 after taking into account the > offset and page boundary, the cast to u8 overflows. And this is common > when user space tries to read the entire EEPROM at once. > > To fix it, limit each read to I2C_SMBUS_BLOCK_MAX (32) bytes, already > the maximum length i2c_smbus_read_i2c_block_data_or_emulated() allows. > > Fixes: effa453168a7 ("i2c: i801: Don't silently correct invalid transfer size") > Cc: stable@vger.kernel.org > Signed-off-by: Jonas Malaco > --- > drivers/misc/eeprom/ee1004.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c > index bb9c4512c968..9fbfe784d710 100644 > --- a/drivers/misc/eeprom/ee1004.c > +++ b/drivers/misc/eeprom/ee1004.c > @@ -114,6 +114,9 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf, > if (offset + count > EE1004_PAGE_SIZE) > count = EE1004_PAGE_SIZE - offset; > > + if (count > I2C_SMBUS_BLOCK_MAX) > + count = I2C_SMBUS_BLOCK_MAX; > + > return i2c_smbus_read_i2c_block_data_or_emulated(client, offset, count, buf); > } > > > base-commit: 88808fbbead481aedb46640a5ace69c58287f56a Reviewed-by: Heiner Kallweit