From patchwork Wed Sep 20 12:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13392623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30B72CE79CF for ; Wed, 20 Sep 2023 12:36:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FFF410E4A1; Wed, 20 Sep 2023 12:36:49 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A68210E49F for ; Wed, 20 Sep 2023 12:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695213406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OJRnSvDMQADh3Wr31msjxxHMdDRAXuX2nElLtMGFtqc=; b=O8hwweB/dpy+qu7PiJQ0FPoKbA1n4iR1HSUIcHb9O/jXQTWqqwNNu2GuBbRUWciRZXbLXH tf4QCM3CHeER2D/L6RMfBjjNlkm2vSPS+gMz5mN5HH3N0AhJRqfXw58RVQv1DEDSfBqnVl KODu+tb2EdHXe3LB+lJHPXFcXKrsteQ= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-otuqMiLUM2-470CQ33MicA-1; Wed, 20 Sep 2023 08:36:42 -0400 X-MC-Unique: otuqMiLUM2-470CQ33MicA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9ade76f4a44so68122866b.0 for ; Wed, 20 Sep 2023 05:36:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695213401; x=1695818201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OJRnSvDMQADh3Wr31msjxxHMdDRAXuX2nElLtMGFtqc=; b=WqKer9s3vtCfTRZ+BgTx85DzjGOC4Vgnb5NwdD7KD/4iNUCTtY8iGxpIYd/hrnQV3V g+XL09oLY/ibTILSVr6B4N1tFgJPY9Re2PAzsdeim1yAHuV4QnMAEH5nQ9+znK86K2Al nEjeu/4Q6XC/eoIFeS2wOTcQFQ/JJMm8m0zLS0M59Ir+I+ZgibN+Cu6nDqWtj0/gLvbi o6nVBc/YcJJMgwgEoDj3087r/yASB2nDHsHp9tFG2Ag2JkQK7LSTpbV8mKq5HDkJBTfZ +tAKtb5JjMo+QpRi6XZ8nU7zY93mt42ZYpKizkR3qKm5R3pCssMYZsfM85Ai/1iYwVEJ Pydw== X-Gm-Message-State: AOJu0YxaCUZMBZAbmb78lB8cuxXoSR4OxXIuJRNSb/sC/i7o/h0udhTs uZaY2NFGJQkh8BvFpg54OxLoyku0hcq9tOKSbvEq/FUDUmk1ZPOHgSquyfkIWEXwxuH4dJOKSXU 1h34UVV6eo81S3ySLITuC+CMQO06d X-Received: by 2002:a17:906:196:b0:9a5:9f3c:961f with SMTP id 22-20020a170906019600b009a59f3c961fmr1815583ejb.3.1695213401709; Wed, 20 Sep 2023 05:36:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERwQ2SjAJQSsC9ZRe6AiF2nzMLomaRThlvgCuHfKcv/TAIMXpcfLWGpl0wj1aEZwFhaqVjcw== X-Received: by 2002:a17:906:196:b0:9a5:9f3c:961f with SMTP id 22-20020a170906019600b009a59f3c961fmr1815563ejb.3.1695213401348; Wed, 20 Sep 2023 05:36:41 -0700 (PDT) Received: from fedorinator.. ([2a01:599:906:7772:a505:d891:dcff:9565]) by smtp.gmail.com with ESMTPSA id a18-20020a170906191200b0098e42bef736sm9348305eje.176.2023.09.20.05.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:36:37 -0700 (PDT) From: Philipp Stanner To: Kees Cook , Andy Shevchenko , Eric Biederman , Christian Brauner , David Disseldorp , Luis Chamberlain , Siddh Raman Pant , Nick Alcock , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Zack Rusin Subject: [PATCH v3 1/5] string.h: add array-wrappers for (v)memdup_user() Date: Wed, 20 Sep 2023 14:36:09 +0200 Message-ID: <20230920123612.16914-3-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920123612.16914-2-pstanner@redhat.com> References: <20230920123612.16914-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philipp Stanner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Andy Shevchenko , VMware Graphics Reviewers , linux-hardening@vger.kernel.org, David Airlie Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, user array duplications are sometimes done without an overflow check. Sometimes the checks are done manually; sometimes the array size is calculated with array_size() and sometimes by calculating n * size directly in code. Introduce wrappers for arrays for memdup_user() and vmemdup_user() to provide a standardized and safe way for duplicating user arrays. This is both for new code as well as replacing usage of (v)memdup_user() in existing code that uses, e.g., n * size to calculate array sizes. Suggested-by: David Airlie Signed-off-by: Philipp Stanner Reviewed-by: Andy Shevchenko Reviewed-by: Kees Cook Reviewed-by: Zack Rusin --- include/linux/string.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index dbfc66400050..debf4ef1098f 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -5,7 +5,9 @@ #include /* for inline */ #include /* for size_t */ #include /* for NULL */ +#include /* for ERR_PTR() */ #include /* for E2BIG */ +#include /* for check_mul_overflow() */ #include #include @@ -14,6 +16,44 @@ extern void *memdup_user(const void __user *, size_t); extern void *vmemdup_user(const void __user *, size_t); extern void *memdup_user_nul(const void __user *, size_t); +/** + * memdup_array_user - duplicate array from user space + * @src: source address in user space + * @n: number of array members to copy + * @size: size of one array member + * + * Return: an ERR_PTR() on failure. Result is physically + * contiguous, to be freed by kfree(). + */ +static inline void *memdup_array_user(const void __user *src, size_t n, size_t size) +{ + size_t nbytes; + + if (check_mul_overflow(n, size, &nbytes)) + return ERR_PTR(-EOVERFLOW); + + return memdup_user(src, nbytes); +} + +/** + * vmemdup_array_user - duplicate array from user space + * @src: source address in user space + * @n: number of array members to copy + * @size: size of one array member + * + * Return: an ERR_PTR() on failure. Result may be not + * physically contiguous. Use kvfree() to free. + */ +static inline void *vmemdup_array_user(const void __user *src, size_t n, size_t size) +{ + size_t nbytes; + + if (check_mul_overflow(n, size, &nbytes)) + return ERR_PTR(-EOVERFLOW); + + return vmemdup_user(src, nbytes); +} + /* * Include machine specific inline routines */ From patchwork Wed Sep 20 12:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13392624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24B08CE79D0 for ; Wed, 20 Sep 2023 12:36:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 775FA10E4A7; Wed, 20 Sep 2023 12:36:56 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id A248410E4A5 for ; Wed, 20 Sep 2023 12:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695213413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=48G0tj5zzQRFiALYPkyRPndfaCR4k/8e83lXW3c50mA=; b=W9LiAbU/WPMGWNpDS7mM34mkZuYanEqenFjLNaYDdjp3Ei1464khBpLShp/QXQyCflIb+7 wCX8yCwV5k8YxWuKv7Iec1zBVY0lxXjCsiYie+tn5nfwhpLQXJePxIG9CEosV3sdpk+N7r LI5eVSZgNjCD+2sdr+h49YrWocQNQY8= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-cAWPahN2MT6Pl3yslyaztA-1; Wed, 20 Sep 2023 08:36:50 -0400 X-MC-Unique: cAWPahN2MT6Pl3yslyaztA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9aa1e8d983aso156322066b.0 for ; Wed, 20 Sep 2023 05:36:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695213409; x=1695818209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=48G0tj5zzQRFiALYPkyRPndfaCR4k/8e83lXW3c50mA=; b=KdioGlkqAMB7M92fAV0QuOtFPL+lXbVuJUEy04riTeWpXwakkmdiqxTkX/amXlKG5/ qNCSd8qARp1jdPO8mB8+NiwkgLw4aWLy4VdaiJ/OkCCKVlRoxfseJ3lUqUyqMeG5qJ5H WQDMEv4/AvcYBsbSAMaVhhpJi48tXmK5dtgWiQgBmb4ZVKLs50VNhcTJjhjwOo3zfdUb 9cCboxLROuF1bG+5x45jnl2SK+31CuEzX2Z7DOTmTxp8+FFN+4HAzLaQ6Adrb0Fl+KHe 3TNAfjAQ7rxjyQcA0F4CIbxrDt0a735uMe7qgWWZVzPkBtbS3scQleoA3aeRSe+TvWAP YBdw== X-Gm-Message-State: AOJu0YxeGiv3nyYnTYJiP2s/oUuRKfKcTHG0l9hVMPqYaDSML8LPcWqO LBJ/8aCxp/9lk0Si9MTVJY+TM7sKXs6/zNJZGh9xNZ8IS72B3ntOCnBOcVX7lgqmUt8hhAXv7ES kDC+gA6v/9XqlPO32aG/x+BdExO+N X-Received: by 2002:a17:907:9512:b0:9ae:4492:df34 with SMTP id ew18-20020a170907951200b009ae4492df34mr1444634ejc.6.1695213409776; Wed, 20 Sep 2023 05:36:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmJTym5YvZ4MH52qjmmgnlm70HGxEIyE84IZpdWdDkioxeqQ+sBFeg2a5b+qpjuhd9RNuOjA== X-Received: by 2002:a17:907:9512:b0:9ae:4492:df34 with SMTP id ew18-20020a170907951200b009ae4492df34mr1444608ejc.6.1695213409547; Wed, 20 Sep 2023 05:36:49 -0700 (PDT) Received: from fedorinator.. ([2a01:599:906:7772:a505:d891:dcff:9565]) by smtp.gmail.com with ESMTPSA id u17-20020a1709064ad100b0098ce63e36e9sm9447247ejt.16.2023.09.20.05.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:36:47 -0700 (PDT) From: Philipp Stanner To: Kees Cook , Andy Shevchenko , Eric Biederman , Christian Brauner , David Disseldorp , Luis Chamberlain , Siddh Raman Pant , Nick Alcock , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Zack Rusin Subject: [PATCH v3 2/5] kernel: kexec: copy user-array safely Date: Wed, 20 Sep 2023 14:36:10 +0200 Message-ID: <20230920123612.16914-4-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920123612.16914-2-pstanner@redhat.com> References: <20230920123612.16914-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Baoquan He , Philipp Stanner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, VMware Graphics Reviewers , linux-hardening@vger.kernel.org, David Airlie Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, there is no overflow-check with memdup_user(). Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely. Suggested-by: David Airlie Signed-off-by: Philipp Stanner Acked-by: Baoquan He Reviewed-by: Kees Cook Reviewed-by: Zack Rusin --- kernel/kexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/kexec.c b/kernel/kexec.c index 107f355eac10..8f35a5a42af8 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -247,7 +247,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT)) return -EINVAL; - ksegments = memdup_user(segments, nr_segments * sizeof(ksegments[0])); + ksegments = memdup_array_user(segments, nr_segments, sizeof(ksegments[0])); if (IS_ERR(ksegments)) return PTR_ERR(ksegments); From patchwork Wed Sep 20 12:36:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13392625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B6B9CE79CE for ; Wed, 20 Sep 2023 12:37:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 11BF210E4A4; Wed, 20 Sep 2023 12:37:05 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3CF0710E4A0 for ; Wed, 20 Sep 2023 12:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695213421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CkUiTYo02brbH9rdldgLT7YiM95DCTjC6m+zHLs+f1Y=; b=amz9ztIh2WqHpki1KC6uHy1zXJICfGQXzAcYtXaOGfsQ53TsLMaIIVqvhYhkteyhuo4xI6 ifibXytfMIFe7uzk1/l4yUWaB+fGA9Mb5OgL5NGm2g4sLOFs+2fnfoEMY6BK0numYkYExK e+tuj6x+yXS8ocL84bgtMPWWlVESyhU= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-lgN8HLBkPUq69FKtUhSnAQ-1; Wed, 20 Sep 2023 08:37:00 -0400 X-MC-Unique: lgN8HLBkPUq69FKtUhSnAQ-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2b6fdb8d0acso15768631fa.0 for ; Wed, 20 Sep 2023 05:36:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695213418; x=1695818218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CkUiTYo02brbH9rdldgLT7YiM95DCTjC6m+zHLs+f1Y=; b=Cz//LIqbkdKqHKjbOI2m/NQsARPjv/ojUwJCjQmhBEnuASoYiviq63S5i4yPR9zs57 uHTX/yV/Y6uRCXkdLtmuJJpF9rw96VVmQ1iWjF8EBDuhJa0d98feOLCcvZfdxeXswE4/ J/W5hNafxadDr47SlcW6p5QgRv63wN+PRcrsa8IOVRt9cdsluHTK09227OcWR6FrCwiD 43zndTCt/nQgZ1y5u67wt0hv3XMKQ7WUNfx3ZffT8SixwPRnJ0fVehUxrVvdP/jdS4Ub 9FFXXNZOQ6hWWSHQXr6PjYqylrLG49AzINndDya+kBYiV8Likw9pzAFsLFxRKp5gNjw7 tylA== X-Gm-Message-State: AOJu0YzOz2M31sMPFz4fs73ukbUGjmmm95ZN6AJFWqE0pl7FegvO1rmw UNwixeLN4ntuTy/IxyNGe0eASaF4BW1wKcEn8c76JMgoAcfoa+9rt0rszPso+hJ/fopm/TKPIRB EvCrFnpn42v/sj2njqJfeuGo4MIUc X-Received: by 2002:a05:651c:1693:b0:2c0:196c:e38f with SMTP id bd19-20020a05651c169300b002c0196ce38fmr1921140ljb.1.1695213418530; Wed, 20 Sep 2023 05:36:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGtYN79a4/Uyeq8meM3+9mCAQ2LGvBXOKnKduArpSa1zP3qsVYH9Wh1PFHrd4S88GImDITZQ== X-Received: by 2002:a05:651c:1693:b0:2c0:196c:e38f with SMTP id bd19-20020a05651c169300b002c0196ce38fmr1921120ljb.1.1695213418185; Wed, 20 Sep 2023 05:36:58 -0700 (PDT) Received: from fedorinator.. ([2a01:599:906:7772:a505:d891:dcff:9565]) by smtp.gmail.com with ESMTPSA id op15-20020a170906bcef00b009ae4ead6c01sm660073ejb.163.2023.09.20.05.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:36:55 -0700 (PDT) From: Philipp Stanner To: Kees Cook , Andy Shevchenko , Eric Biederman , Christian Brauner , David Disseldorp , Luis Chamberlain , Siddh Raman Pant , Nick Alcock , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Zack Rusin Subject: [PATCH v3 3/5] kernel: watch_queue: copy user-array safely Date: Wed, 20 Sep 2023 14:36:11 +0200 Message-ID: <20230920123612.16914-5-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920123612.16914-2-pstanner@redhat.com> References: <20230920123612.16914-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philipp Stanner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, VMware Graphics Reviewers , linux-hardening@vger.kernel.org, David Airlie Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, there is no overflow-check with memdup_user(). Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely. Suggested-by: David Airlie Signed-off-by: Philipp Stanner Reviewed-by: Kees Cook Reviewed-by: Zack Rusin --- kernel/watch_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index d0b6b390ee42..778b4056700f 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -331,7 +331,7 @@ long watch_queue_set_filter(struct pipe_inode_info *pipe, filter.__reserved != 0) return -EINVAL; - tf = memdup_user(_filter->filters, filter.nr_filters * sizeof(*tf)); + tf = memdup_array_user(_filter->filters, filter.nr_filters, sizeof(*tf)); if (IS_ERR(tf)) return PTR_ERR(tf); From patchwork Wed Sep 20 12:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13392626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD8EECE79D0 for ; Wed, 20 Sep 2023 12:37:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED7A010E4A0; Wed, 20 Sep 2023 12:37:14 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id CE02F10E4A0 for ; Wed, 20 Sep 2023 12:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695213432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7KRPqkETTBVBC/zv1aXEUiiiXJ1Cft936yka0iGNazc=; b=GDssDO8BIGhK6TKMZh04cGJJnpoaaAjR4Dkx9sAIlFD1POzPVWi4Zot2wniwcVPb+TQMwX VkZNBuiV2wuvq60oXW+bmakbfa8VIYK3nwbn7CJfPH9+rGZKxxBbIbrAwkZTZ4dXlC5CPi n6nDeuOtyyiclJLWf7fxdpy5lAxOiB8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-yx_31ZEgMM-B6ghO52NY_w-1; Wed, 20 Sep 2023 08:37:10 -0400 X-MC-Unique: yx_31ZEgMM-B6ghO52NY_w-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-404daa4f5a7so15032565e9.1 for ; Wed, 20 Sep 2023 05:37:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695213429; x=1695818229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7KRPqkETTBVBC/zv1aXEUiiiXJ1Cft936yka0iGNazc=; b=cpnBF9zxIhNXpXisO9Qxv+JJMv7vyE6VkyKJmwNAZIybA31/o4lPRbzG8Q8wBDaDv5 OV4/5EGJb2bDig5jputUNSFzWa7EKyJ6HBm14EIFVts6KLkDolPWPeXKMMAJgz462h++ rsT2lr/i8VyaoEqof2kWP5eFDU38EUiI8bLIVziZtDlT/TcLHhz3G86uRSwaoqyz/FZY rj35axZqp2kIS4dZMAZMpXFP8uylak4x53OKFL1vdXS1drK2SFr5oY8MpnoYww97zDhb TJUr8ixFjg+voJUwt9J6DvRFlzjxpzaXpoydEslAvDEcL9j/EpytAkT7vlGVGfuCLIqC XJuQ== X-Gm-Message-State: AOJu0YzVuWVmaERtNJXfp+e0eisGs4SB9sn1cGMiD2hmCbUIcQILE4NM PW0qDqGSHUrnIsr0WKPhuAmitvuAhS2XY58C0TBQGCq96CzTzKn4ijALuyRck1QE7JdDtTD/aIG Mve8kx+Y1b7rbJgASyt7X9GQYhX0j X-Received: by 2002:adf:ec48:0:b0:317:630d:1e8e with SMTP id w8-20020adfec48000000b00317630d1e8emr2031495wrn.2.1695213429447; Wed, 20 Sep 2023 05:37:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGorWXFxi2CZ+i0Bq4z7I+sy7K13wS44rMjIuskory3+gtAyjUda2GeiUfH2k5vq773C10/rA== X-Received: by 2002:adf:ec48:0:b0:317:630d:1e8e with SMTP id w8-20020adfec48000000b00317630d1e8emr2031462wrn.2.1695213429120; Wed, 20 Sep 2023 05:37:09 -0700 (PDT) Received: from fedorinator.. ([2a01:599:906:7772:a505:d891:dcff:9565]) by smtp.gmail.com with ESMTPSA id lg13-20020a170906f88d00b009ad88839665sm9297787ejb.70.2023.09.20.05.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:37:03 -0700 (PDT) From: Philipp Stanner To: Kees Cook , Andy Shevchenko , Eric Biederman , Christian Brauner , David Disseldorp , Luis Chamberlain , Siddh Raman Pant , Nick Alcock , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Zack Rusin Subject: [PATCH v3 4/5] drm_lease.c: copy user-array safely Date: Wed, 20 Sep 2023 14:36:12 +0200 Message-ID: <20230920123612.16914-6-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920123612.16914-2-pstanner@redhat.com> References: <20230920123612.16914-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philipp Stanner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, VMware Graphics Reviewers , linux-hardening@vger.kernel.org, David Airlie Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, there is no overflow-check with memdup_user(). Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely. Suggested-by: David Airlie Signed-off-by: Philipp Stanner Reviewed-by: Kees Cook Reviewed-by: Zack Rusin --- drivers/gpu/drm/drm_lease.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c index 150fe1555068..94375c6a5425 100644 --- a/drivers/gpu/drm/drm_lease.c +++ b/drivers/gpu/drm/drm_lease.c @@ -510,8 +510,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, /* Handle leased objects, if any */ idr_init(&leases); if (object_count != 0) { - object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), - array_size(object_count, sizeof(__u32))); + object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids), + object_count, sizeof(__u32)); if (IS_ERR(object_ids)) { ret = PTR_ERR(object_ids); idr_destroy(&leases); From patchwork Wed Sep 20 12:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13392627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 391D5CE79CF for ; Wed, 20 Sep 2023 12:37:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 54A4810E4A9; Wed, 20 Sep 2023 12:37:31 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9922610E045 for ; Wed, 20 Sep 2023 12:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695213447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/re3vPWoYJ/6xHLpunyVTZgfJ3oWhQoot3M15Xf93m8=; b=E2OP29vLDk4eh5/V7/D5SKXxSO5RoM5HB41hLgMOPlLhV8MOamYL82/noDOQ7QinN7z01b GJcmkR+B6Sdzp6HxJmm0yzG10cMMkjbDidnawKuLvMTyzjWPGYySM5RSLhZOun+lFRxBVY qZv07IqsnoFNJY3/U6zMZfFo1j+IOgw= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-411-4QXxlugCMV6ZTWx0XNIWmA-1; Wed, 20 Sep 2023 08:37:25 -0400 X-MC-Unique: 4QXxlugCMV6ZTWx0XNIWmA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9a9cd336c9cso154954566b.1 for ; Wed, 20 Sep 2023 05:37:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695213444; x=1695818244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/re3vPWoYJ/6xHLpunyVTZgfJ3oWhQoot3M15Xf93m8=; b=vvg/RD1IN0ygcp6hXWxojJhjGbXMBcFjYy4FModbBPOTLIYcvazdHwuPsFi0qZIeXN T5N7W0FHygZwfVVw+cKedZghmFBiD+ms/fEeLsZVUC8ozg2nI5VIRbdKRnCnuSCshfZD 8uCu4RDxUKpzl9a0sEIZaBaR9U3rwv7RTW1vG4KgK9QPBSROh14gzmWtzSNvc9J6mwDZ 75/+C1wcfAwWnAB46DlLsj2kxEeiAkRJHYnflwiY0DUPp+q5+pZCBEvTkgxLu8SfsA/s /7FRQY5UJVqzNgUibcMt/za9uS5bUlKp7nZRBW2m3lDiZRm+oIM53uMMyRF9ydrQMqbk pb1Q== X-Gm-Message-State: AOJu0YyT/uhkn61s6MqJVPEmUxilBxCVYuyAL1YheCV4KsnCmfUaysC2 Sj4ZqSUvKJ3yZwK3W0PZZX0jxVhh5ASEtUk0hdFFdsBQfaZ2snPxe5hsdyt7Kgmebj9L/SyeaLu GlJPkVjvGzBPUJeE4CT0IwaHfSyAS X-Received: by 2002:a17:906:1d4:b0:9ad:f4d9:f6f2 with SMTP id 20-20020a17090601d400b009adf4d9f6f2mr1978103ejj.5.1695213444580; Wed, 20 Sep 2023 05:37:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhjndQs4UNSwfullLxNR+tIZdKn1iy3aRr+eKNx4dO54tFLsdtNfZQxNfsH7DoGs3jy6KzlA== X-Received: by 2002:a17:906:1d4:b0:9ad:f4d9:f6f2 with SMTP id 20-20020a17090601d400b009adf4d9f6f2mr1978090ejj.5.1695213444350; Wed, 20 Sep 2023 05:37:24 -0700 (PDT) Received: from fedorinator.. ([2a01:599:906:7772:a505:d891:dcff:9565]) by smtp.gmail.com with ESMTPSA id h11-20020a170906854b00b0099ccee57ac2sm9233184ejy.194.2023.09.20.05.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:37:19 -0700 (PDT) From: Philipp Stanner To: Kees Cook , Andy Shevchenko , Eric Biederman , Christian Brauner , David Disseldorp , Luis Chamberlain , Siddh Raman Pant , Nick Alcock , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Zack Rusin Subject: [PATCH v3 5/5] drm: vmgfx_surface.c: copy user-array safely Date: Wed, 20 Sep 2023 14:36:13 +0200 Message-ID: <20230920123612.16914-7-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920123612.16914-2-pstanner@redhat.com> References: <20230920123612.16914-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philipp Stanner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, VMware Graphics Reviewers , linux-hardening@vger.kernel.org, David Airlie Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, there is no overflow-check with memdup_user(). Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely. Suggested-by: David Airlie Signed-off-by: Philipp Stanner Reviewed-by: Kees Cook Reviewed-by: Zack Rusin --- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c index 5db403ee8261..9be185b094cb 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -777,9 +777,9 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, sizeof(metadata->mip_levels)); metadata->num_sizes = num_sizes; metadata->sizes = - memdup_user((struct drm_vmw_size __user *)(unsigned long) + memdup_array_user((struct drm_vmw_size __user *)(unsigned long) req->size_addr, - sizeof(*metadata->sizes) * metadata->num_sizes); + metadata->num_sizes, sizeof(*metadata->sizes)); if (IS_ERR(metadata->sizes)) { ret = PTR_ERR(metadata->sizes); goto out_no_sizes;