Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1616581imm; Wed, 16 May 2018 00:03:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqDYsk9pI/fpqf0XcBopj6CYcjxnbtsyMVY5hsgkvCSRG6Hx1Yq2PzWpaHQB14p6pHcpw7E X-Received: by 2002:a62:ea1a:: with SMTP id t26-v6mr18730537pfh.117.1526454199069; Wed, 16 May 2018 00:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526454199; cv=none; d=google.com; s=arc-20160816; b=b3lUpe9VVT4vkzBbstNq8bPYYWK5O67//WpknRpWJZK4YNTnX/55yhbv8e/zqwIQiE gryLQJXbU/7EeD4qQRdzCH54Wnh763AY+0UCyEvcAgOz9GJDsDa5qXDUTS4h4m8fRiI4 NzBQzHpwtSRLm1j0a4R4H7GqdkhXT3z+hMMo6SnzseFwgp1wyntHvEuDaMGtsZoBYT7o 7SD/6o2ml4uuJpSedaLbQClcmIvE3zbOKyaVAkTIspw+erGKetC6vP+ic3aE5cB9Crb+ sL4y/C2HG/rJRVdT4z64xxOL2+MrUP+JVCxuqBKCfLHuuo7l5in/RUuhaXqEVZ2dX0aJ Q/Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=S470/0nQlB6DEgPiBwVPQAb1IOYF+artCcN5xslRfBg=; b=x2egRtyqslZcJQVWWcv2IXVONCs/habJuZO/NE5ktsDNyLRDH4z3+5oofyHHkIWuUL /MkE59Xz+Tl3YtIiPUCPtS9vEK+HnqL7GNdZ8sP/MTDxe8xqJasJpu0ufLjv7kbvREBk Zxk6BB11sGG3BUMJ5fLGHKYlWpT9FbjkrQ8cV8shu0q9yqlGJxwDT0IRbKJ68xNzRqtZ 2yt7XX54sKL8XP/fgJpQCPJFfa2domBkqqvY+ckO1/i65vWfb2X8BBMJbxl0s+hKXsa6 Dky6BXxGd6ke1WP25KnEeqwzNa1+dSgbkyyto6QiWX/TgrMsQBOkRewjmIdqzSaZp8Qg B4iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=lTVbMmYY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15-v6si1628464pgu.455.2018.05.16.00.03.05; Wed, 16 May 2018 00:03:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=lTVbMmYY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752604AbeEPHBW (ORCPT + 99 others); Wed, 16 May 2018 03:01:22 -0400 Received: from mail-bl2nam02on0063.outbound.protection.outlook.com ([104.47.38.63]:34273 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752215AbeEPHAj (ORCPT ); Wed, 16 May 2018 03:00:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S470/0nQlB6DEgPiBwVPQAb1IOYF+artCcN5xslRfBg=; b=lTVbMmYYFmwUS+HbJNCUXJzYbWmHs9rhRA1bnYtO7IRFF1jrunIwQO8KnouaOPyQNQW6JzNcChd+NULnYkC3D6+7aqcl0jsG+9kRNKwCtHLf092OOqzHKy5UFoK9jB8jW+hoRbnRCSo2v/2jpGQw0r7fyyxkscs/6mhQ8vC6icA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=George.Cherian@cavium.com; Received: from sbr2s-28.caveonetworks.com (50.233.148.156) by SN6PR07MB4926.namprd07.prod.outlook.com (2603:10b6:805:a5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.755.16; Wed, 16 May 2018 07:00:35 +0000 From: George Cherian To: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: wsa@the-dreams.de, jglauber@cavium.com, kamlakant.patel@cavium.com, mchehab+samsung@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, akpm@linux-foundation.org, linus.walleij@linaro.org, rdunlap@infradead.org, george.cherian@cavium.com, Jayachandran C Subject: [PATCH 3/4] i2c: xlp9xx: Make sure the transfer size is not more than I2C_SMBUS_BLOCK_SIZE Date: Wed, 16 May 2018 00:00:18 -0700 Message-Id: <1526454019-32714-4-git-send-email-george.cherian@cavium.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526454019-32714-1-git-send-email-george.cherian@cavium.com> References: <1526454019-32714-1-git-send-email-george.cherian@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: BYAPR01CA0033.prod.exchangelabs.com (2603:10b6:a02:80::46) To SN6PR07MB4926.namprd07.prod.outlook.com (2603:10b6:805:a5::27) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:SN6PR07MB4926; X-Microsoft-Exchange-Diagnostics: 1;SN6PR07MB4926;3:sX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yxvMEoLOJyrXDV7EwNGMAV8UDkYeNM/scRbxMhUK/pgZW9NcBvcaJqQXbd7yT1ATpOUaMTJKfUKadrQiivRJZ6oWcWiIbJfd+MgOYSaTGSOkOYLKHFSKLTdSOhopBTokBDg/HxbGj9c2BR0QAlRd71rawFiy+705yUvVoCiZpR9+FLjghoBsJr4E3tTji58SLp9sqh8OLqd+3DNazTM/7tvdXxK2BLZmyYotnBPt3SsVQFbdLuJy1COYX1dS5Wk1zQNVjhkUYeqleZ1bzC4zSzgu2RZ18NSGoXdtwOBrqV/mI9chdg6LnxBVfe8Wz30PR4DPOeNSdwdOsh8eZAmgQshM41;4:DhW610k2L6J7sWLs2OIGK6rtOzjhilcDa+rvmxuraUxsIfNNnEFzydS5o6D4fIuDSGtp4qTTJ1jos5EahYhFpsbFEUcqunm64DzhxoLZQ4TEurHzCpjSlGckxsk7/xcQ9ChBxZS7jW1Bqmtu+O3Dlk3ysEX4FhueGcguL6Gz6vxeKXVBCQKgBIiMbfM/wHQcuBJ93SIY+4rRAg5+hDf6uXvI9QUU/onwwuSLVr04GKdSSnTLclhlq8OMd+meP/KwQIcFiJaN5AV4TAKqzP6WXQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:SN6PR07MB4926;BCL:0;PCL:0;RULEID:;SRVR:SN6PR07MB4926; X-Forefront-PRVS: 0674DC6DD3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(376002)(39860400002)(396003)(366004)(39380400002)(189003)(199004)(44832011)(50226002)(7736002)(50466002)(105586002)(486006)(53416004)(36756003)(8936002)(106356001)(5660300001)(186003)(48376002)(316002)(6486002)(25786009)(16526019)(16586007)(305945005)(4720700003)(68736007)(446003)(6666003)(72206003)(478600001)(476003)(2616005)(3846002)(6116002)(956004)(11346002)(97736004)(4326008)(59450400001)(52116002)(51416003)(76176011)(2906002)(26005)(66066001)(47776003)(6512007)(81166006)(81156014)(6506007)(386003)(15760500003)(69596002)(53936002)(86362001)(107886003)(8676002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN6PR07MB4926;H:sbr2s-28.caveonetworks.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN6PR07MB4926;23:PtK7pkNP7x2pT0f5XCc5aKuwjW62nwupqQEfH/fBM?= =?us-ascii?Q?8iQ0CeLLgeo6N/AShT38b1wPplrt57YVPHOPPwHYLSljp3JYXqH5X6A1hkUo?= =?us-ascii?Q?h7Xjgt/q+sFYaqzupEMZQVr1BCsY4ehLT247F/oTp+K4/Pd8vfurv7ITC208?= =?us-ascii?Q?wkjUDRQDbt3D2ZMDhu4TIUOYC8hxcXErnON2D6JRKvjIFR9TwAshOhbHbl8N?= =?us-ascii?Q?NqptlvZua7U3Iu9MuUs/wojqBdrmejtEbqxubdpcE7SUKfAAO5zn5MM3aJIt?= =?us-ascii?Q?IIqWj7bcauj2/DBX02aLcL/xhaSn0T4pUO3BhdgL5uwG5OC8kwvEmnTzB2/l?= =?us-ascii?Q?izb14MpqeeOqN+83y/Z+a11wW21/n9mxV1oEB5kdk3oScN2o043h0JsIBC0Y?= =?us-ascii?Q?xeK/xQJFaXBdlUDO/B/d3JliT2kxNHNC56ceavp7SAkF2KxXpnariymRQn6a?= =?us-ascii?Q?DLLDFbdRGLSKIBliJNYem/NhJaSAwD9UwBgQTdC/pZB/4eI68TMhqj9CKoGk?= =?us-ascii?Q?E1h1fBsPaRdjgW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0W8frCwdVPfCRrbk5qsTOz05SdnOEm26GNsG7JVXjDzKELHd4kueGD0LONMrP4/Gzr6TS4t8J4TPetKzmyUBODP9/ojN2q0EeHvalLesUXNKztqeMhL8kqIka/xG4EL0xTv8VzAs295fxlMJPM+SQVNgxNpYYxcU2/BFcy7MhLssCx3U4W6Q6jA75ja5ZIKDG4iZj5TQhsMiuNesqBmvT64V/bUm2kTROkGmK8a8 X-MS-Office365-Filtering-Correlation-Id: b6b4a8db-15c4-48bb-02dd-08d5bafab986 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2018 07:00:35.4527 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6b4a8db-15c4-48bb-02dd-08d5bafab986 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4926 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For SMBus transactions the max permissible transfer size is I2C_SMBUS_BLOCK_SIZE. It is possible that some clients might not follow it strictly occasionally. This would lead to stack corruption if the driver copies more than I2C_SMBUS_BLOCK_SIZE bytes. Add a check to avoid such conditions. Signed-off-by: Jayachandran C Signed-off-by: George Cherian --- drivers/i2c/busses/i2c-xlp9xx.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c index c268fde..1f41a4f 100644 --- a/drivers/i2c/busses/i2c-xlp9xx.c +++ b/drivers/i2c/busses/i2c-xlp9xx.c @@ -172,6 +172,8 @@ static void xlp9xx_i2c_update_rlen(struct xlp9xx_i2c_dev *priv) len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & XLP9XX_I2C_FIFO_WCNT_MASK; len = max_t(u32, priv->msg_len, len + 4); + if (len >= I2C_SMBUS_BLOCK_MAX + 2) + return; val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); @@ -189,14 +191,20 @@ static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) if (priv->len_recv) { /* read length byte */ rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); - *buf++ = rlen; - if (priv->client_pec) - ++rlen; - /* update remaining bytes and message length */ - priv->msg_buf_remaining = rlen; - priv->msg_len = rlen + 1; - priv->len_recv = false; + if (rlen > I2C_SMBUS_BLOCK_MAX || rlen == 0) { + rlen = 0; /*abort transfer */ + priv->msg_buf_remaining = 0; + priv->msg_len = 0; + } else { + *buf++ = rlen; + if (priv->client_pec) + ++rlen; /* account for error check byte */ + /* update remaining bytes and message length */ + priv->msg_buf_remaining = rlen; + priv->msg_len = rlen + 1; + } xlp9xx_i2c_update_rlen(priv); + priv->len_recv = false; } else { len = min(priv->msg_buf_remaining, len); for (i = 0; i < len; i++, buf++) @@ -315,10 +323,6 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg, xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MFIFOCTRL, XLP9XX_I2C_MFIFOCTRL_RST); - /* set FIFO threshold if reading */ - if (priv->msg_read) - xlp9xx_i2c_update_rx_fifo_thres(priv); - /* set slave addr */ xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_SLAVEADDR, (msg->addr << XLP9XX_I2C_SLAVEADDR_ADDR_SHIFT) | @@ -337,9 +341,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg, val &= ~XLP9XX_I2C_CTRL_ADDMODE; priv->len_recv = msg->flags & I2C_M_RECV_LEN; - len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len; + len = priv->len_recv ? I2C_SMBUS_BLOCK_MAX + 2 : msg->len; priv->client_pec = msg->flags & I2C_CLIENT_PEC; + /* set FIFO threshold if reading */ + if (priv->msg_read) + xlp9xx_i2c_update_rx_fifo_thres(priv); + /* set data length to be transferred */ val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); @@ -393,8 +401,11 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg, } /* update msg->len with actual received length */ - if (msg->flags & I2C_M_RECV_LEN) + if (msg->flags & I2C_M_RECV_LEN) { + if (!priv->msg_len) + return -EPROTO; msg->len = priv->msg_len; + } return 0; } -- 1.8.3.1