Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp747184rdb; Sun, 18 Feb 2024 09:47:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX6aYc1ZPgHBobSyyvMVKZANe4HArfJpg4tJOSWTP6s7z60+bEOc9Zq4F1aQKhzXckxi9GPa1yJtVIGUOetWYebj/PTSeaHDh2oV9mCwA== X-Google-Smtp-Source: AGHT+IFEXA/A7LEJHLqJ4oI98mLcygAB0LsRW93vCFGRQ5aVqwIF0t4InXJe1cQIvnkx0l7PuE47 X-Received: by 2002:a05:6a20:c907:b0:19e:b9ab:189e with SMTP id gx7-20020a056a20c90700b0019eb9ab189emr12706621pzb.60.1708278433386; Sun, 18 Feb 2024 09:47:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708278433; cv=pass; d=google.com; s=arc-20160816; b=b+z/QQMHuPUPGWxrfJJbmtvSByjQ/3NBXOL2NeMBZleO8+jtBBJYwjcRuwrVvuCvq7 +E1D/aT5C470Oy+Wkb13D8t2G8WRBI1rJfEYMIObV+vPIaAnp9DAlPBsxwXANJIvmcAh 6Z2Z4mYhlXgWHRKeCHUIKsFFh2o8MP+dpvqXKh4D9+emnj6lJWVCxg2VbbyFoXUNBQLO AKeOrpTuYAVRZVnwu73o0w86kscwUi+XJ5NJuYfow+Z08I9SyeVjmQTK6hsiyE/2UcFN LzfGlzW6pYAPAId/XjEJd03eBsRdmQYuZhhmCrjMra2qB5V+BubDzwqGHIlZjzgyXMqx 0q2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=y2+kKbrWEFY2/pmLK9szqs3+euOSxAcesJDdReAip00=; fh=ygYG+FZ7S+UcmpM265p8aiazood6sG0uLiuAEUUoOCo=; b=CufNXoMrDbRylzNCTo98BLR0NNz+t555K47bClGNe06pE4DTFXluWBdrJArDKQ35id SkYEhEoXuUJKpCJFRIynJMWmBtfA+hLngfH1RbAgnJdehyjZKv44GktDHgQEBaxzeo8L y1ywgh/HrmZIh1tMhZH8LWV+x4Ej5hcjnZ4yZC3KYGPjrQmOhTQI1w0PXXWF3R/2v9BX /L9hmrBZE7N8+kOEDSfMKro8gDrIij0uoIgglj1OSzzsFors4jCJnYr6JnBeDWHhcsaf yx96nX0Y0TM8kVd5KxErhVWuD7+rxXT55fBeuFPoYsftu6hMAxImcFDszpq0J2hdle1V CRIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=SD9wlefO; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-70465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w30-20020a63af1e000000b005d8e1dc1df8si3143087pge.705.2024.02.18.09.47.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 09:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=SD9wlefO; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-70465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1DEEF28160C for ; Sun, 18 Feb 2024 17:47:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC7B66F067; Sun, 18 Feb 2024 17:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="SD9wlefO" Received: from smtp.smtpout.orange.fr (smtp-19.smtpout.orange.fr [80.12.242.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47C5B6E2C3 for ; Sun, 18 Feb 2024 17:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708278428; cv=none; b=VJD0lVhhk5tcvhCsWYJ0jz/ej0+iStok+n8iEGd6zWyx0MfIU9dKG0pb85KpwHcP5kd0xsdRlHr0Dk67vpucue4R7R5JhE/7H3XP+t+2qDxTl8OoF1yUy9N0fDxXKx9LnZZhwNBJwAaoD+LgzSusUr70Z2056TV0Ayf9UXxWPnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708278428; c=relaxed/simple; bh=72fk0PVXRZ8Q4JWxUxUYDfHppG9f2BAjRRu5pbDdVro=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iiM6+p3ffeFXxnU8XQFXg3d2bgfouig1T3x5A13/OyvxD43KMGjramhIdLvBkHPFV/I4uqjS9RqXPLGf6oFt88gMie6hQ1WsVb1FG1w6ZM5LHSz5kBgW+mnysvq268zCO2CuF4zELyksTKBRQMXGl4mDS0FzVqhhzpPcoOQwWXs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=SD9wlefO; arc=none smtp.client-ip=80.12.242.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from fedora.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id blFbr8qYHiCLsblFer7StJ; Sun, 18 Feb 2024 18:46:57 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1708278417; bh=y2+kKbrWEFY2/pmLK9szqs3+euOSxAcesJDdReAip00=; h=From:To:Cc:Subject:Date; b=SD9wlefOwXg6avVhwSrVQdg+pRLNLNGc+ZUkn8lC/1XFjrHZc30uIj2jPvkEWP5cb wiHSjYsY5V2op+Ln67qbUlLXw/7k3gDzmSapsEgNjU2FE7ZQFZeRAuDAkPHNJi0+9i 3O0ClCSTsfy7DletOKheud1v1mlIm1LkH2827FumbJLNPbd7ozcZdiM34zTIQM6eIp iFy+zsBoGPfT58YXmqfV0/faepuFDWLu0whT+sljy78xCEZdC8SGTXALv3bim/xS+r z6Hjxmm8jvIpbKthLpg3OcdQEbqDKstm8BPQdu3EnvoPuV1rqWapIbUpBqLWwioruD Hs+GmnM6RYFgQ== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 18 Feb 2024 18:46:57 +0100 X-ME-IP: 92.140.202.140 From: Christophe JAILLET To: gustavo@embeddedor.com, keescook@chromium.org, Gerd Hoffmann , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH v2] udmabuf: Fix a potential (and unlikely) access to unallocated memory Date: Sun, 18 Feb 2024 18:46:44 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If 'list_limit' is set to a very high value, 'lsize' computation could overflow if 'head.count' is big enough. In such a case, udmabuf_create() would access to memory beyond 'list'. Use memdup_array_user() which checks for overflow. While at it, include . Fixes: fbb0de795078 ("Add udmabuf misc device") Signed-off-by: Christophe JAILLET --- v2: - Use memdup_array_user() [Kees Cook] - Use sizeof(*list) [Gustavo A. R. Silva] - Add include v1: https://lore.kernel.org/all/3e37f05c7593f1016f0a46de188b3357cbbd0c0b.1695060389.git.christophe.jaillet@wanadoo.fr/ Signed-off-by: Christophe JAILLET --- drivers/dma-buf/udmabuf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index c40645999648..5728948ea6f2 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -314,14 +315,13 @@ static long udmabuf_ioctl_create_list(struct file *filp, unsigned long arg) struct udmabuf_create_list head; struct udmabuf_create_item *list; int ret = -EINVAL; - u32 lsize; if (copy_from_user(&head, (void __user *)arg, sizeof(head))) return -EFAULT; if (head.count > list_limit) return -EINVAL; - lsize = sizeof(struct udmabuf_create_item) * head.count; - list = memdup_user((void __user *)(arg + sizeof(head)), lsize); + list = memdup_array_user((void __user *)(arg + sizeof(head)), + sizeof(*list), head.count); if (IS_ERR(list)) return PTR_ERR(list); -- 2.43.2