Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3805133yba; Tue, 7 May 2019 07:22:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqy453CCPeG+1nS1UZ93uFnojl459SXDMOPR0eBKwi67RMq7auVK4w7XLdNAI8aT/5Jn52sf X-Received: by 2002:a63:560d:: with SMTP id k13mr39626140pgb.124.1557238942659; Tue, 07 May 2019 07:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557238942; cv=none; d=google.com; s=arc-20160816; b=rW3gr9HoJchsuhGHC6qccmVcz1GOsgSNx0bEEvfJfCw/VEnPe+We/UNzJ60CFWEPac ESinK7Lm8Rdr7Jo6PsUbhBkx9VakEwVB/+Ak5oBapD0CpEmv22bshcmhde2P7wS5vRCj b1SRTziqPzpxQ8nYSvX/p+JPIRBoDvnyTscwvoDoJCfDhLJr1zYs+PVGgpEjE6BpmfGN liisgfa6xc2jeuJxGDslqzc8vMGekkGEzQUVPtyxS0vcwxQ/sbkCqVLu5U8p+VOtynu7 DYDwZ89IOhO6pR4zOc/z1o6mKCMZUe6GS5mtLk0XzDNi6WK/26z7NmluJe29lfz+E7D0 uYKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=9qk4ccp4B5blv5RczwvVmso3g5hH37JCzEDyvSmEY8Y=; b=lOTs/ceOfENzV32iaGTOr+yjY72ugOJADeTCiDnQjlXJBYnMM6xTxOcTAv2RgyMXJx 7KDMbv0A6+mR+Cn179EOzTXDYDk+2YfKgSvUgWc04ZRGWohK0sfGmqKNMNbNLRM/w9qp WnZWdR4WS4eYEMdMg4TkZ6FRb+ovyjyqu+/jeEsq/G/7LPRaiwJBYcYjtG92LtrBq7rq dyqC2U75sPNuahaHjsqcb3MLom3sKJLTA7DjiyrkMFvx4Lg+q9wi6n3IrzL0kExDnVUH kWvYqHSVJ+USrtDI9Do3+seiQHQ5GeNO6tVPXQDcW9zqtTTT5DaJqCxFhVq6lof0uC6h TxaQ== ARC-Authentication-Results: i=1; mx.google.com; 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 m86si19464815pfi.235.2019.05.07.07.22.06; Tue, 07 May 2019 07:22:22 -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; 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 S1726713AbfEGOVL (ORCPT + 99 others); Tue, 7 May 2019 10:21:11 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:16877 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726454AbfEGOVL (ORCPT ); Tue, 7 May 2019 10:21:11 -0400 X-UUID: 754959646c76419f84b050e67e5730c5-20190507 X-UUID: 754959646c76419f84b050e67e5730c5-20190507 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1623362754; Tue, 07 May 2019 22:21:05 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 7 May 2019 22:20:57 +0800 Received: from mtksdaap41.mediatek.inc (172.21.77.4) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 7 May 2019 22:20:57 +0800 From: Yingjoe Chen To: Wolfram Sang , Jean Delvare CC: , , , , , Yingjoe Chen Subject: [PATCH] i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr Date: Tue, 7 May 2019 22:20:32 +0800 Message-ID: <1557238832-10723-1-git-send-email-yingjoe.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 82EDD77E36B98B06E0D48449A43857A9C339EBD6B0843B3FFEA6EE130FBF90972000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If I2C_M_RECV_LEN check failed, msgs[i].buf allocated by memdup_user will not be freed. Pump index up so it will be freed. Fixes: 838bfa6049fb ("i2c-dev: Add support for I2C_M_RECV_LEN") Signed-off-by: Yingjoe Chen --- Only check arm64 defconfig build pass. I haven't test it since it just fix memleak for error cases. --- drivers/i2c/i2c-dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 3f7b9af..776f366 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -283,6 +283,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client, msgs[i].len < 1 || msgs[i].buf[0] < 1 || msgs[i].len < msgs[i].buf[0] + I2C_SMBUS_BLOCK_MAX) { + i++; res = -EINVAL; break; } -- 1.9.1