Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2915660pxb; Tue, 24 Aug 2021 10:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrRlimynZ6OglJ7yKE4pHRhzKSoVaaLvirvGFW/BI+UmCKl8H+AAhY6l9tiIwInm0OZD5r X-Received: by 2002:a92:440c:: with SMTP id r12mr27184572ila.174.1629826235201; Tue, 24 Aug 2021 10:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826235; cv=none; d=google.com; s=arc-20160816; b=KtD279rHOfP61LNOTs8TcK/TpVW/IYutTJKGC6UGz4a30iKMUa6JRj78BcPzO2YP85 +I7cE0KyAs2526Ei9SzVxenZm4ZKNkBJq9W54928WlbZK+bJ+DUYkWq/jnfaroUtkSwO sO/a6RAzdn04R27hxuXwowHT18ytCohLwHo4j7A5I06sAM3MISk4k5TfK4cr8eAvMkmJ ZWX7ybHo1vgP1O6WWP+GggGHhOMpjYht7ht1f641RvlzBFOHcG+MU3yEQYysrAxymYxK kv9UI8+6UojeYUljVnyhRAVprsCbhxSE3Hz281dCiGeAURawnaPV7FfkUNe4yO0dU/sD SSzw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NnO7oN0ezu11/EXEEGQJAa8S0VKRWHk9HHvkU2O1roU=; b=cpDmP/H6BFl+yhTAUjQ5NsB1j1y1jBG8m+fdlO4bzFUN2bL+j3pOAvI1Vy/8JIIVcF sUwfloMtrri4yMO1W6xGogErYaQGroZYe64JG7raU+HR5E/+ihrOrU7i/655PHCKBvLU Q/lsFAXEmi1kWelEp3uck+BkC8WbIMSTU/6q67d3U8ZRcnBswisboqoABCElAXxPru5N OmxNGdGi+bv8fZKWvQzVvRlxACpDTSY6A1ye8ZDpm9cqDNJO/hK5c9GdAp+JFCH6/5He 41Am4BVNrD/otQHlY/LALrC5qdl2ZbjEyjrExSFL0QhVBV3i/v/TNOxHLvzEdb9RPD+F 3Glg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ooziw80O; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si18746412ilq.160.2021.08.24.10.30.23; Tue, 24 Aug 2021 10:30:35 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=Ooziw80O; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240835AbhHXR2x (ORCPT + 99 others); Tue, 24 Aug 2021 13:28:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:35536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240965AbhHXR0n (ORCPT ); Tue, 24 Aug 2021 13:26:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 63BFF61B06; Tue, 24 Aug 2021 17:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824703; bh=0BXYytsHqL57dABFPq1BzeYB5KBeLfhmgHgEJMUMEzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ooziw80OOKYvHD6tMtO4nHIQld9cgSBrsbmHZi5hC9qKcBtPvXahoSQvNoa1wbHEl ozHKvPwbrHR+mjupxMdZcwCeJ1g1I0Q38tmGIGUHLq6bDnRAqGa8bDDZRFzPTWPU5j IBLXfdrt1LTILsYA61FRoXwcJsFXOEnMzuADXd069+XOS62ZSBmiXhsZMNezYp2qoQ SdcO1L7eACxq2AE4heN/JvA+vZoklniMc17IoAckRCm4wHcBHtk+JSBJBsigEjczsQ D+Uocv/AJ4a+thRocsZYJWRjWdjn6ut2xVLFa+a8hS52eOtLoz+2taKqbY3Kp49IHf S/QXJjqfLTLXw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Eric Dumazet , Wolfram Sang Subject: [PATCH 4.14 04/64] i2c: dev: zero out array used for i2c reads from userspace Date: Tue, 24 Aug 2021 13:03:57 -0400 Message-Id: <20210824170457.710623-5-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170457.710623-1-sashal@kernel.org> References: <20210824170457.710623-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.245-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.245-rc1 X-KernelTest-Deadline: 2021-08-26T17:04+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman commit 86ff25ed6cd8240d18df58930bd8848b19fce308 upstream. If an i2c driver happens to not provide the full amount of data that a user asks for, it is possible that some uninitialized data could be sent to userspace. While all in-kernel drivers look to be safe, just be sure by initializing the buffer to zero before it is passed to the i2c driver so that any future drivers will not have this issue. Also properly copy the amount of data recvieved to the userspace buffer, as pointed out by Dan Carpenter. Reported-by: Eric Dumazet Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-dev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index c4066276eb7b..b7f9fb00f695 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -148,7 +148,7 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count, if (count > 8192) count = 8192; - tmp = kmalloc(count, GFP_KERNEL); + tmp = kzalloc(count, GFP_KERNEL); if (tmp == NULL) return -ENOMEM; @@ -157,7 +157,8 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count, ret = i2c_master_recv(client, tmp, count); if (ret >= 0) - ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret; + if (copy_to_user(buf, tmp, ret)) + ret = -EFAULT; kfree(tmp); return ret; } -- 2.30.2