From patchwork Wed Aug 30 13:45:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13370270 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 0DD53C6FA8F for ; Wed, 30 Aug 2023 13:46:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21A1210E51F; Wed, 30 Aug 2023 13:46:32 +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 A443F10E51F for ; Wed, 30 Aug 2023 13:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693403189; 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=YTYt2BSQEZut8ffX05oFQAoT2Tz1O17bKncsR4XeBIs=; b=BfS0DuiV8z5gwUJjXvvmr7wSZZ9lI5xfyijCCeVaHwT+acQmf8bwBfG9bAhOqBmHhNvNUH zxe9/WIYiPwxfHU4dRBWVoYjzUwPm7jOyFmmv5Mx1QLmVT+HyMF15wtsIIX22YGO9zGha/ nx6eNSaUHnAfAWJC/f5HSFP81lmKtI4= 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-208-NSx-lp4rO_WoxIc1S4JtEw-1; Wed, 30 Aug 2023 09:46:26 -0400 X-MC-Unique: NSx-lp4rO_WoxIc1S4JtEw-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9a5c5f0364dso53522866b.0 for ; Wed, 30 Aug 2023 06:46:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693403185; x=1694007985; 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=YTYt2BSQEZut8ffX05oFQAoT2Tz1O17bKncsR4XeBIs=; b=Z+Y2oUXwtlCiKwZ/kUOVAWs53DmzQ2iCY1QLNoEll9Q6ff1TKBeAqm1NsfdIhqVsmm XC00OEkrcMBS1rFsMMlJ3kseaQ09BFoYV7E+8q1dMMIftKRZBH4Ytmns0pv9qW27mVnw ztIZ6Xd/Uadhy4VonTEnUH6wDbFDrMHTZeG2fz0dv23MehmoehoI4+Xh0RB7pVX00WFZ Cm5mvs6VOpahAH1bV8C2SQyfGZCGROYa6Sv8NvgXFEojPTcQPUqw9m6Z1yOpNiM1LXW3 +bH+E1X+lbMm/kE+AwtdCwJtdD4HdD7PK6iERhc/cngw6GW4i1/u+fKyH22nX6myQVeu Cz1A== X-Gm-Message-State: AOJu0YzYv4F1OgucE/s3tk87Cv5DXcjOjIMysrUHxcJ3z2hnMcjXZHwU w0t7WEqc6hXkQ0oc99v2BXKzdkKm4eh84ew+ju9p8fy1MY+eH+MGGPYoY7xbH7RLB4uZEA2dXMC mznVi7BiuY5z3X4mwmhvF2pTbMv3IC0klt9GS+gI= X-Received: by 2002:a17:906:74cb:b0:9a1:eb67:c0d3 with SMTP id z11-20020a17090674cb00b009a1eb67c0d3mr1497346ejl.4.1693403185527; Wed, 30 Aug 2023 06:46:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFs3XWD3GCd0nxchFLVqW0usUrIz+VOttxkboYOB/XHHWAwTxGY9Rlu6B7+6AhH9DbE4wdw7w== X-Received: by 2002:a17:906:74cb:b0:9a1:eb67:c0d3 with SMTP id z11-20020a17090674cb00b009a1eb67c0d3mr1497324ejl.4.1693403185198; Wed, 30 Aug 2023 06:46:25 -0700 (PDT) Received: from fedorinator.fritz.box ([2001:9e8:32e4:1500:aa40:e745:b6c9:7081]) by smtp.gmail.com with ESMTPSA id t26-20020a1709063e5a00b009829dc0f2a0sm7174419eji.111.2023.08.30.06.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:46:24 -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 1/5] string.h: add array-wrappers for (v)memdup_user() Date: Wed, 30 Aug 2023 15:45:52 +0200 Message-ID: <46f667e154393a930a97d2218d8e90286d93a062.1693386602.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: 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, 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 --- include/linux/string.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index dbfc66400050..0e8e7a40bae7 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -6,6 +6,8 @@ #include /* for size_t */ #include /* for NULL */ #include /* for E2BIG */ +#include /* for check_mul_overflow() */ +#include /* for ERR_PTR() */ #include #include @@ -14,6 +16,46 @@ 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 (unlikely(check_mul_overflow(n, size, &nbytes))) + return ERR_PTR(-EINVAL); + + 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 (unlikely(check_mul_overflow(n, size, &nbytes))) + return ERR_PTR(-EINVAL); + + return vmemdup_user(src, nbytes); +} + /* * Include machine specific inline routines */ From patchwork Wed Aug 30 13:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13370271 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 68F8DC6FA8F for ; Wed, 30 Aug 2023 13:46:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ACED010E525; Wed, 30 Aug 2023 13:46:37 +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 356E410E524 for ; Wed, 30 Aug 2023 13:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693403191; 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=uG5M2Lwpie6cChdlBf2i1g6i8ozHuD8iPPR+2gMyfYc=; b=BY7VJof0QjqigpStiZgPE008ec1Pwqd9JQBEpTmWasug6HnaNMxnmp2zpkQJfXw+kSJEfy mQWmwsuxYvZpW0cqozp8NxQjQC1vn3B1r1k1Gbl6oeF8oRIyRbIQPsdzVoW6NICsktgtTt iRn1r2aMXZcX3f4PQdUOQP+2jfVuMt8= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-psNAjZ-vNIKZUoEbwj-f5A-1; Wed, 30 Aug 2023 09:46:30 -0400 X-MC-Unique: psNAjZ-vNIKZUoEbwj-f5A-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5219df4e8c4so757492a12.1 for ; Wed, 30 Aug 2023 06:46:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693403189; x=1694007989; 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=uG5M2Lwpie6cChdlBf2i1g6i8ozHuD8iPPR+2gMyfYc=; b=b+4RQhmuRTZIGVRwBN1CALszv4HSNspP3FyiVj0e+p9lY4lx/jC5kdOZT6wJhVvVOw D2c2aingvdFVjoh3vjkgEv8rQADL0iR2t7bEDdeiw9XLJVHsd+N0Cc+saA5SEZSCbZkz pGutj5IPv1vVYZ0aoDQbxtLoEel9e9+wyhiMF55ZppRnsqdDEneLrELetcO0PIU36G9L SP4Lbzn6emOu77IJGZnOwVWnt88/XVwx+3CWJBAyhFSKLH7uHwL9iDY9oTv4gjOaa2cP imSzjopjwQMeWRSsgT+pg4wdBDBzb7KYRCR1L89sEzxaRBzIiJnQXwYh+vCu02r8gEph bBsg== X-Gm-Message-State: AOJu0YxmfqsFe4jGmVitwxvEtgYVtoPfHM1k6rEIVl7TMYdurhpJGKhN YLz9dS8lyR/aPkebiMXxQKXmcEXRr5FzilHYDjWAk8oS4aocN3ERIfVqjXgCFYAXuDBHtXQXKsf rPJspzvOV45tVUsx57YvdAB67qBMH X-Received: by 2002:a05:6402:50cf:b0:522:e6b0:8056 with SMTP id h15-20020a05640250cf00b00522e6b08056mr1964352edb.4.1693403189066; Wed, 30 Aug 2023 06:46:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpKYbKxrilyWwmvyGSQuR3YdE5ziBNReJitKpOxi4O0anKghb3+MxxX32nil6cbORrhxRuFQ== X-Received: by 2002:a05:6402:50cf:b0:522:e6b0:8056 with SMTP id h15-20020a05640250cf00b00522e6b08056mr1964344edb.4.1693403188914; Wed, 30 Aug 2023 06:46:28 -0700 (PDT) Received: from fedorinator.fritz.box ([2001:9e8:32e4:1500:aa40:e745:b6c9:7081]) by smtp.gmail.com with ESMTPSA id w23-20020aa7d297000000b0052595b17fd4sm6683260edq.26.2023.08.30.06.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:46:28 -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 2/5] kernel: kexec: copy user-array safely Date: Wed, 30 Aug 2023 15:45:53 +0200 Message-ID: <0a3f1bca273792edbdc41b64c454a6f7f499c9a8.1693386602.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: 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 --- kernel/kexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/kexec.c b/kernel/kexec.c index 92d301f98776..f6067c1bb089 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -242,7 +242,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 Aug 30 13:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13370272 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 A545DC83F01 for ; Wed, 30 Aug 2023 13:46:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8C1110E144; Wed, 30 Aug 2023 13:46:41 +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 6C8E510E524 for ; Wed, 30 Aug 2023 13:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693403196; 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=R2kuY7QrN77OjYcmiIgmsp8RgTy5tijHIGRui0VqTUY=; b=VBafd5+o1BPasgg3fepmn+pHFg9tfaRqiRoKKiE9l9T2E7RMw1qv4xHyTPt0ekn0jCi9/N 7XWEFXW7pjfnYufLxmnG7EKyeEZC9KJy7i36g9LajCQJMNCMuW0EPiDU1AXC9uaLhL6vd7 97T94ul4akjY5DV4rSGaDoc7zb+Kt/A= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-KleB5WiJPhG_7knE9IacEQ-1; Wed, 30 Aug 2023 09:46:34 -0400 X-MC-Unique: KleB5WiJPhG_7knE9IacEQ-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-52c0134dfcdso114652a12.1 for ; Wed, 30 Aug 2023 06:46:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693403193; x=1694007993; 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=R2kuY7QrN77OjYcmiIgmsp8RgTy5tijHIGRui0VqTUY=; b=DrY7fV2OSqjbaL03ncIqYvQSkjT573LgIyuVrM7b/oRPUYzGtyjqGCiGKfjQgrI2AE vvWbmroTpzDl71kUXdUif8lDF6fVWmH/vE/7s1swFBnJZDMFZl5/MtQck1yjSq33T24c BPOPW8b8MOp6cSvw5s2IggBbldbLq+rfCxLoWZOezXhk1L9WeMhpRmpwcam6oeSbPIf3 R4J2slLYIkQYxtLC+3ISkj43n3ImM10KdVVQae1wDCBdHxgyL2T3KL/IWmZcjmWNXH19 aazCrlY0KbXHBNzcUgQEdl6Wwxk8ldMbcBksv2hVfvK6QPn5j7ofL5tw+RuSFPXH5gDf YE6w== X-Gm-Message-State: AOJu0YzQaAoK4sseBUTG2q2yEPtHR4tNuX7yilmjnlkEHsQjnTl5XMLZ 6BgqdYhtX0jdLDz8L3X91wabAuF9Gj8HnnJe4tPQSTvDZjk0AMIE1pPhbWQbh7kpf2Oi8GHu38X nL/6sG3i+9p1PEKCAerLzbsxNAcpT X-Received: by 2002:a05:6402:51c8:b0:522:3f32:52f1 with SMTP id r8-20020a05640251c800b005223f3252f1mr1737286edd.3.1693403193058; Wed, 30 Aug 2023 06:46:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGf9jsdBfXtDK6B3l1XAhb6uC/SE7H2eq+xyXHHwbpGSepkZ7/eGDvrY6bR1kwu2ebD+wsHwg== X-Received: by 2002:a05:6402:51c8:b0:522:3f32:52f1 with SMTP id r8-20020a05640251c800b005223f3252f1mr1737265edd.3.1693403192770; Wed, 30 Aug 2023 06:46:32 -0700 (PDT) Received: from fedorinator.fritz.box ([2001:9e8:32e4:1500:aa40:e745:b6c9:7081]) by smtp.gmail.com with ESMTPSA id t7-20020aa7d4c7000000b00529fa63ef6fsm6811782edr.57.2023.08.30.06.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:46:32 -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 3/5] kernel: watch_queue: copy user-array safely Date: Wed, 30 Aug 2023 15:45:54 +0200 Message-ID: <4168bc2d9313d5d1a1a2b9ca0b9fc2990d499506.1693386602.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: 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 --- 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 Aug 30 13:45:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13370273 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 AE0C2C83F19 for ; Wed, 30 Aug 2023 13:46:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7BBCE10E528; Wed, 30 Aug 2023 13:46:43 +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 3C50E10E144 for ; Wed, 30 Aug 2023 13:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693403199; 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=UOJpuwbwTVfs+j95sEE93OpkqtbclA96WzipEC/nM14=; b=M2J2AOzajbWxpOSlsTFsRiEYVhKK2zgfd14zlINFE9jhrRj0GKtWG4NxtPTI3Z6VJ3ioPn zHVYB+tdXs7gHK3ew+iH0TwicSodRc6z1earMnab8o9nLhRj3erHw5U0FY5KcwzJcRXZCc Yzhugu6EgC3zekLIfIVYbhl9ZeBAStg= 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-624-LfQ9GFDXPaOOYT6LYoHj_g-1; Wed, 30 Aug 2023 09:46:38 -0400 X-MC-Unique: LfQ9GFDXPaOOYT6LYoHj_g-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2b6fdb8d0acso19452211fa.0 for ; Wed, 30 Aug 2023 06:46:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693403197; x=1694007997; 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=UOJpuwbwTVfs+j95sEE93OpkqtbclA96WzipEC/nM14=; b=UCbYQmiJkVcAU3S7VK9huwWA0eODfYrN4xl6yeoDU1p6+RGLuCgnOAw/LlU6TVxTYc o6x5hz1+vTJlLZ8p/YF+olyu7XFjoCv5AQ+i4ZLYwdE/5lTHuQdQXemPeYuvFXg+tVef UlkK/yPEZ9yQnVazebcm4IGCCsqK4Fp0nRnOjEDHXUEf8y53dmDjCHXVnK1e+dwUjN6/ 6Y4iA0dxe6932qYQcgmqkYAEpnDxpgOo0zlCHwszJeeP4GvhLPYSdG252yR633E65LIn 9f8+Sk3w2zkrEzo5Ms+bQ5O+Bqz5ONHdnOLrCa5WjK0kBXyrBBl29rgB2FcRi+f51FRR jpIg== X-Gm-Message-State: AOJu0YxOfV6C/h19lkMTwc0I1ch+Q0acq2ivYsDwCX6J8Z1JDkzRXR3Q ouoJvZYQcGbvsC4OIowu8ordgcAK6Kp90GV3/nHNFpg0/aN+izy1Z18A7rh/5aPlxFONFWfqXgi +InswsWjgwpOT8FpGRYqi0N87aGjv X-Received: by 2002:a05:651c:1182:b0:2bc:fc2e:766c with SMTP id w2-20020a05651c118200b002bcfc2e766cmr1857333ljo.3.1693403196827; Wed, 30 Aug 2023 06:46:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNBSsy/iFndvURQgQS9ZCnlQ9lW+9HBjOb1QIZNMn1l3Gt7cB24Ma8x0ITyx+CEVBlGHtj+A== X-Received: by 2002:a05:651c:1182:b0:2bc:fc2e:766c with SMTP id w2-20020a05651c118200b002bcfc2e766cmr1857319ljo.3.1693403196642; Wed, 30 Aug 2023 06:46:36 -0700 (PDT) Received: from fedorinator.fritz.box ([2001:9e8:32e4:1500:aa40:e745:b6c9:7081]) by smtp.gmail.com with ESMTPSA id li22-20020a170906f99600b009a198078c53sm7167678ejb.214.2023.08.30.06.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:46:36 -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 4/5] drm_lease.c: copy user-array safely Date: Wed, 30 Aug 2023 15:45:55 +0200 Message-ID: <34e14523c9cea13e2f63afabf2938c89d2e84776.1693386602.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: 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 --- 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 Aug 30 13:45:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13370274 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 D813FC6FA8F for ; Wed, 30 Aug 2023 13:46:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FE1D10E52A; Wed, 30 Aug 2023 13:46:53 +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 7415810E524 for ; Wed, 30 Aug 2023 13:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693403202; 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=w7XXAxDLUmZdx81fESQwCFLbPlVQDp3wBmzbmeWO24M=; b=OE5ECJrGM24DknbMl8BDqzUVlOCcJaJBNR/KILwZGxOcYr01HdpI6VJdrifdL6V86Y5v18 Mp4Glq8+2pTE0ZpPoaFo5OQMLEuISOr7yTwc1oZxuMTuFrosIR1lkcHq6zE/nI64MertCD GNl8vZ3RMPx3aotlnrVz95m5v2yKuWw= 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-67-9N7VVQerMf-XxJ-wc9O_5w-1; Wed, 30 Aug 2023 09:46:41 -0400 X-MC-Unique: 9N7VVQerMf-XxJ-wc9O_5w-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-94a342f1703so87948966b.0 for ; Wed, 30 Aug 2023 06:46:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693403200; x=1694008000; 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=w7XXAxDLUmZdx81fESQwCFLbPlVQDp3wBmzbmeWO24M=; b=GaZtZCaq5Ofw7vdYzv1hx8QLCzO/5jsPiZkv5ylaR1sZLdW8EbSSvrQ821CQlTevYr BOHYWN/Pj2wzQ49nRHMb7LQ7yHBdWiciJg8oKiJxsekIvqu9WPBqMzUvNzEQnd3UhcFA bzFGI6y+akuVVEbukzocrWkN35hKRAXm1fksXPtw9T654eSaSmqXcqJaKXKIRNOaWSOH nhwOFQ25FhOHWljDpsg45zGyzkarn7bWPC6yyHUEGQOkcTudujAp7xCbXAIoUnKOy9Zq WZBFqCu4v/Flamjrd/MbnSWLTffz6T1lGK9sVg+8uaA4eGbkqjcwfrstwSdXMGZM61c2 aNoQ== X-Gm-Message-State: AOJu0Yxkzi1vXj6cTq1EUmJiMcHJk1v/cBSssATBclqYpaAYl63OSEnJ eBPqLFF2G5VgaSd/maigtuiJflZhjof9bu5bKyNz8xMjDNnjvnaneFIx1rIcpqWmPmqyYpCnGrO 9n5IJcQfwbYG2Cpf4aa05iHwT9al5 X-Received: by 2002:a17:906:1011:b0:9a1:aea8:cb5a with SMTP id 17-20020a170906101100b009a1aea8cb5amr1574499ejm.1.1693403200683; Wed, 30 Aug 2023 06:46:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFovveJ1gRkNa/hbpuOdO660EpmuFNfSfZvj7MduSJ07LTCEG5M6k7oeDfsA0MPBedrGa9vw== X-Received: by 2002:a17:906:1011:b0:9a1:aea8:cb5a with SMTP id 17-20020a170906101100b009a1aea8cb5amr1574480ejm.1.1693403200487; Wed, 30 Aug 2023 06:46:40 -0700 (PDT) Received: from fedorinator.fritz.box ([2001:9e8:32e4:1500:aa40:e745:b6c9:7081]) by smtp.gmail.com with ESMTPSA id gy25-20020a170906f25900b0098951bb4dc3sm7218566ejb.184.2023.08.30.06.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:46:40 -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 5/5] drm: vmgfx_surface.c: copy user-array safely Date: Wed, 30 Aug 2023 15:45:56 +0200 Message-ID: <6f9397d6af919b7e8325c2945385c13aaa3dc5f1.1693386602.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: 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 --- 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;