From nobody Sat Feb 7 13:00:29 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD69AEEB56B for ; Fri, 8 Sep 2023 20:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344471AbjIHUD7 (ORCPT ); Fri, 8 Sep 2023 16:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344458AbjIHUD5 (ORCPT ); Fri, 8 Sep 2023 16:03:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B47CB1B1 for ; Fri, 8 Sep 2023 13:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694203374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4V6bm459ozDimu1heDZpH+ZMi6MrCIxlIoO52rIEKGg=; b=EyPYY9Nf+VsSKq+x0nZagV//r6Gg45xFBWo1dW1udqEyiibSG/Z5GkaCRDR+h/CyAWk/mx OqpngClcXI/a7jTebBGFaM8D7czKhzR2d8SMJ22DIsMIouGlMhSNM52m8re0Jkzn7AoyCw rSk4PfgaItberM0gG7F62LC9e0T2Sh8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-hf-upcDMPLm8sPpn-AIaew-1; Fri, 08 Sep 2023 16:02:52 -0400 X-MC-Unique: hf-upcDMPLm8sPpn-AIaew-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4121a931b1fso3336161cf.1 for ; Fri, 08 Sep 2023 13:02:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694203372; x=1694808172; 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=4V6bm459ozDimu1heDZpH+ZMi6MrCIxlIoO52rIEKGg=; b=l1AURkn2dbDsdFSB6YNqjx8OFxyY1mjlGdx5IkMzWzij1o3Zidsy0FLuX4AduWK0QP Y4Uxv8KRHp8+ULZLK31pOhDgw3+9B4sQ7EZWL1mbcD+evcG0QDPvqeFQ/viFPyaJu1/3 pGhcZ/j5yw5k0Z5JcRH3ZmpZyVNrwc4GbgJewnU28+TIQfHHPpNZYWyOS460inweRzXG 98fBcWho19AV3PAt3iE7CqbNdP9kl/Y+x1z3wHOFBX3L8KIOJqwjsnmlug/J0ZaBfXHe TqcmSn8YWURUTTr0ngYKVnq99Q5tmbEN93sVZF3swyJi0n6JSumq5Pmeucigakm79r3P xQAA== X-Gm-Message-State: AOJu0YzWDRbS2dUJdhgsCVtYKHhw7qJFUGqpW4mqiyTHoZ89yHbxYt8J OKJRRnEDlAm4RQ8LZKK5nekxJctLmWOrgyq5XeYBPxl122nhMlecP1lOoiNK3hL8n8Njz5cFN3t uL4+/NrTS0Csxf9uwTnPcmu4K X-Received: by 2002:a05:622a:1997:b0:40f:da40:88a with SMTP id u23-20020a05622a199700b0040fda40088amr3927398qtc.4.1694203372365; Fri, 08 Sep 2023 13:02:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUR/6fW5sKr+U41wFGsfMKmuUv8vxb4fBBYTs7l3DnJhhPgBBiRmpLahG272yCMwIEUruJgg== X-Received: by 2002:a05:622a:1997:b0:40f:da40:88a with SMTP id u23-20020a05622a199700b0040fda40088amr3927365qtc.4.1694203372058; Fri, 08 Sep 2023 13:02:52 -0700 (PDT) Received: from fedorinator.redhat.com ([2001:9e8:32da:e500:513e:fbe9:e455:ae67]) by smtp.gmail.com with ESMTPSA id x19-20020ac85393000000b0041511b21a7csm262984qtp.40.2023.09.08.13.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 13:02:51 -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 Cc: VMware Graphics Reviewers , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-hardening@vger.kernel.org, Philipp Stanner , David Airlie Subject: [PATCH v2 1/5] string.h: add array-wrappers for (v)memdup_user() Date: Fri, 8 Sep 2023 21:59:40 +0200 Message-ID: <93001a9f3f101be0f374080090f9c32df73ca773.1694202430.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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..8c9fc76c7154 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 =20 @@ -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); =20 +/** + * 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, si= ze_t size) +{ + size_t nbytes; + + if (unlikely(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, s= ize_t size) +{ + size_t nbytes; + + if (unlikely(check_mul_overflow(n, size, &nbytes))) + return ERR_PTR(-EOVERFLOW); + + return vmemdup_user(src, nbytes); +} + /* * Include machine specific inline routines */ --=20 2.41.0 From nobody Sat Feb 7 13:00:29 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A990EEB569 for ; Fri, 8 Sep 2023 20:04:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344499AbjIHUEI (ORCPT ); Fri, 8 Sep 2023 16:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344480AbjIHUEG (ORCPT ); Fri, 8 Sep 2023 16:04:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F150170F for ; Fri, 8 Sep 2023 13:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694203385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJlM81Ad0uqQunhdFKofh1JwhP2kaFm8hxSxz8OfTMk=; b=ePZJUstpqLUGNvY10VuB9AYfCD4dvj3m10nybqw9kdfteIuEWQp7ZfSbtnImd5Q6jibuww vwdegGnb5VzcUFbCV+UTQtJuVikxOvp+1P9Kxf6WcC2JmUIXQKGn3ZL/q3NrM3BcrRCibj /LmX2ESKlCFyCQyMKuiwhK+tK16ZXnM= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-458-N7lXP_I2PAGVZeGgOExc8w-1; Fri, 08 Sep 2023 16:03:02 -0400 X-MC-Unique: N7lXP_I2PAGVZeGgOExc8w-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-64a4269ca98so6043486d6.0 for ; Fri, 08 Sep 2023 13:03:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694203382; x=1694808182; 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=qJlM81Ad0uqQunhdFKofh1JwhP2kaFm8hxSxz8OfTMk=; b=MczSR9pi2q5pqIkuq/22nTF5u75JZfOjfAKHUhT+iMGZcAP1wCbHTkzvjiL/Y8wfkP 6/mjtZDtmgGKMlkO1yDY0dV1gJfNHzrCS2P6CrflqWizdOXzlHbJGr+yKVtiAc6+1Nkj 51dJY4Fw8ttvalsRWyhCDgUbXv4lujE+IGUrNizO6utqV9gqQTLVN6C7gY+J2qIBncp6 9dkyWA5us751gHkwl/f5NcyJZ0kPX0cLD9tlwimCBLBWchQqAyYUBNKnQmODxIBeOJfD XpRS5aPE3JcGDQz8BSAy4Hau5ILpcqH2XvF7rIVk08aE/0SQP2OFn/eHI2leQvMdvDeN pVRA== X-Gm-Message-State: AOJu0YxLggkJN1nwvGyu/Sfy1HnuRUXRr6FPZaIbo4tohgKEPHLixmi8 WRQwavCl7xxUEM6GD4kkt7YWDaLSzDLo4Tu4ioX5xmfvbAoc+tTMqmBdwXTz6uKc77vaCGXKkmG cNG501NBxqii5AuHpHD8SSzWL X-Received: by 2002:a05:6214:234b:b0:649:5f43:245c with SMTP id hu11-20020a056214234b00b006495f43245cmr3403718qvb.4.1694203382304; Fri, 08 Sep 2023 13:03:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkpjEpC3M4jl16uIjnS3PMQJTudw+DmAKJXO1LGuAkwNI/2h/IQUepIX3UGSH4cUrAf1SALA== X-Received: by 2002:a05:6214:234b:b0:649:5f43:245c with SMTP id hu11-20020a056214234b00b006495f43245cmr3403702qvb.4.1694203382095; Fri, 08 Sep 2023 13:03:02 -0700 (PDT) Received: from fedorinator.redhat.com ([2001:9e8:32da:e500:513e:fbe9:e455:ae67]) by smtp.gmail.com with ESMTPSA id r19-20020a0ccc13000000b0064f523836fdsm959242qvk.123.2023.09.08.13.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 13:03:01 -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 Cc: VMware Graphics Reviewers , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-hardening@vger.kernel.org, Philipp Stanner , David Airlie Subject: [PATCH v2 2/5] kernel: kexec: copy user-array safely Date: Fri, 8 Sep 2023 21:59:41 +0200 Message-ID: <31313a8a1dd1baf9dd3c21fbe8dd46b9e111f20c.1694202430.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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, unsig= ned long, nr_segments, ((flags & KEXEC_ARCH_MASK) !=3D KEXEC_ARCH_DEFAULT)) return -EINVAL; =20 - ksegments =3D memdup_user(segments, nr_segments * sizeof(ksegments[0])); + ksegments =3D memdup_array_user(segments, nr_segments, sizeof(ksegments[0= ])); if (IS_ERR(ksegments)) return PTR_ERR(ksegments); =20 --=20 2.41.0 From nobody Sat Feb 7 13:00:29 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77DDCEEB566 for ; Fri, 8 Sep 2023 20:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344480AbjIHUEP (ORCPT ); Fri, 8 Sep 2023 16:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344482AbjIHUEN (ORCPT ); Fri, 8 Sep 2023 16:04:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4844D10CF for ; Fri, 8 Sep 2023 13:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694203393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R2kuY7QrN77OjYcmiIgmsp8RgTy5tijHIGRui0VqTUY=; b=FVtUIV6tsX+mNwu0dPRU6/krl9z5hF9660WzUhQAK5v5pfb1taPidTii67cjZRQlB36Opz N+VKXKxTwg38ubSiFAI1yy6hyWdSyAD3Z7LrfcGoLSuQKA4NOSmveGTGWAGYLY8TfIMfNB qIVcvn0Vo93t4/92WiM7XdHw3ws5SLQ= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-235-5Ue3-Wm7Nv-F8iB9xFRzZQ-1; Fri, 08 Sep 2023 16:03:11 -0400 X-MC-Unique: 5Ue3-Wm7Nv-F8iB9xFRzZQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-76f1cc68e65so58231985a.1 for ; Fri, 08 Sep 2023 13:03:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694203391; x=1694808191; 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=xCB3WEIkUMV0O43N0o/F6lHYOcZDVxHt9vFNmc9RK62SMyd4OL4XJzg2/IBL7xJayq ID0qgJQ5HJrRS4Rzl1S+quNQCXKi7b0cRmOk6n81fg/CfYYLeP/ktZQ+3qERJRu0tfKo VXfuOc2Ysh6ngJmYsAWIG/D1XedwFc2P/D5114wv8GKK/e3fgMgxrXmzaiMNlnRu1/0+ r7zUrWlZ4TrPiqIMdh25axxNoFdRzvzVu7Qw99swcg5/dXh8SF2KwlgrTv8phtVTG/VI 4QM4A7Oo9U1EAXwsr2HWLk983vEOZK7rSyENVTHxwk7D22IBoA6jKr0+VSEZylPv7L7m 9S3Q== X-Gm-Message-State: AOJu0YxzojJqkikR9Kks/8+XJ/J8dHwJIghtGk1HLkduUk78/HIDLOK6 F+jbR6pYCDFBshfIhKdRVpnpAmKYHAm7eWwYSk1CzUELNvZSUbUhWZE/Ar1Z0LIh7qtKu0DV58x Y22QgmjSjS7e8XXZcvOZwa7On X-Received: by 2002:a05:620a:46a6:b0:75b:23a1:69ee with SMTP id bq38-20020a05620a46a600b0075b23a169eemr3480476qkb.5.1694203391480; Fri, 08 Sep 2023 13:03:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuCpViWH7IrGzpUqlTBi1h+iY/5ABj5ubmz/i5MJtwSQDaqOps3aQUe1r5isWfpnPKjPasBg== X-Received: by 2002:a05:620a:46a6:b0:75b:23a1:69ee with SMTP id bq38-20020a05620a46a600b0075b23a169eemr3480460qkb.5.1694203391259; Fri, 08 Sep 2023 13:03:11 -0700 (PDT) Received: from fedorinator.redhat.com ([2001:9e8:32da:e500:513e:fbe9:e455:ae67]) by smtp.gmail.com with ESMTPSA id c17-20020ae9e211000000b0076f15f2918fsm825920qkc.63.2023.09.08.13.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 13:03:10 -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 Cc: VMware Graphics Reviewers , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-hardening@vger.kernel.org, Philipp Stanner , David Airlie Subject: [PATCH v2 3/5] kernel: watch_queue: copy user-array safely Date: Fri, 8 Sep 2023 21:59:42 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 *pip= e, filter.__reserved !=3D 0) return -EINVAL; =20 - tf =3D memdup_user(_filter->filters, filter.nr_filters * sizeof(*tf)); + tf =3D memdup_array_user(_filter->filters, filter.nr_filters, sizeof(*tf)= ); if (IS_ERR(tf)) return PTR_ERR(tf); =20 --=20 2.41.0 From nobody Sat Feb 7 13:00:29 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD7E3EEB56D for ; Fri, 8 Sep 2023 20:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234966AbjIHUEX (ORCPT ); Fri, 8 Sep 2023 16:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344522AbjIHUET (ORCPT ); Fri, 8 Sep 2023 16:04:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7971704 for ; Fri, 8 Sep 2023 13:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694203402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UOJpuwbwTVfs+j95sEE93OpkqtbclA96WzipEC/nM14=; b=B5Xj9Ttc+s+aZQxg2A3jQbfa8yOwnks3IUTh3RJHo7yUvJyDP16+zr0pbXdQJGzZ2QKyOM /FMh94mhge3/pdvosTE+WUPmnH2gljxTFxIiU0hk8G/oBDLk4if3OGV5NxLQYXtMrY2H8m Jvw4Lgy9Ll3TePAjZwnXltt+hPxTNdw= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-FsduL-wZOmyv3k3rPoEeaw-1; Fri, 08 Sep 2023 16:03:20 -0400 X-MC-Unique: FsduL-wZOmyv3k3rPoEeaw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4122119722eso4981691cf.0 for ; Fri, 08 Sep 2023 13:03:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694203399; x=1694808199; 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=arOwL+XefdaFkxnwiHKBWtwmj8n6BBQtiz+CRawE1RMANw1cPEcqwUTziu2ezwmpcE bpOIJHU4ppahw/mlHwVhoTBrUiDINnr/eKlbRdt3ZZKxncWBXvejYqaj4r9cXmKKB0Vc hfDWvSbA+wKAxY8NGtrC04DHtmwO7NcBKsiwXOn6IphamA0Jfh4Zt6mQvH1XyJjxqGQn DoGRgwNTlnMqvvoPt1SCJMVarSfv8w1aJXx4plIi1LcLD3+7FWgEp9+3HtFLOmxgT8gD PMBYpThCId79fZBL4RbtTyKF2vqnbsuG/6+fcBtzSVytWtcIlFiK1GOzGofhPJW7z9X0 rlSg== X-Gm-Message-State: AOJu0YynWZXjRcK4ib8SzLvPlw/0or4uAzOzDQtLXx8AteLzk8KkGhCR MjSu6ifj6leMY+FsplhYEQyHKYxzyl10+ugiejhkHju1+wBLkUZSPrn6UG5XMiiioiTVVyyOXtn I08PLqXJw2zKN6Kshk5pp0LN8 X-Received: by 2002:ac8:7e94:0:b0:412:12e8:8538 with SMTP id w20-20020ac87e94000000b0041212e88538mr3683927qtj.1.1694203399530; Fri, 08 Sep 2023 13:03:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAKN1YnAkZtTcGtA674mV4f8NT9irZONaAKXTHG61Fqfz6xPH+/e15CARdB3FRUjLa10PQWg== X-Received: by 2002:ac8:7e94:0:b0:412:12e8:8538 with SMTP id w20-20020ac87e94000000b0041212e88538mr3683913qtj.1.1694203399274; Fri, 08 Sep 2023 13:03:19 -0700 (PDT) Received: from fedorinator.redhat.com ([2001:9e8:32da:e500:513e:fbe9:e455:ae67]) by smtp.gmail.com with ESMTPSA id bb37-20020a05622a1b2500b004116b082feesm843284qtb.75.2023.09.08.13.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 13:03: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 Cc: VMware Graphics Reviewers , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-hardening@vger.kernel.org, Philipp Stanner , David Airlie Subject: [PATCH v2 4/5] drm_lease.c: copy user-array safely Date: Fri, 8 Sep 2023 21:59:43 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 !=3D 0) { - object_ids =3D memdup_user(u64_to_user_ptr(cl->object_ids), - array_size(object_count, sizeof(__u32))); + object_ids =3D memdup_array_user(u64_to_user_ptr(cl->object_ids), + object_count, sizeof(__u32)); if (IS_ERR(object_ids)) { ret =3D PTR_ERR(object_ids); idr_destroy(&leases); --=20 2.41.0 From nobody Sat Feb 7 13:00:29 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99AD6EEB566 for ; Fri, 8 Sep 2023 20:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343873AbjIHUE1 (ORCPT ); Fri, 8 Sep 2023 16:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344500AbjIHUE0 (ORCPT ); Fri, 8 Sep 2023 16:04:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1E29A7 for ; Fri, 8 Sep 2023 13:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694203410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w7XXAxDLUmZdx81fESQwCFLbPlVQDp3wBmzbmeWO24M=; b=Wi3YQZG9+8h61fsmy4+H8jrCBRIqJKjHBWUm5F2HNx0mOXStoNAsydgeGwUarjw3X57jid UhkAO0BO/wq06mICiGkpTYscttkNS/Rvqp3bb/n3gW+I6iDUWboNuT08PAEDsfeSUJAT5b p7CzfbnW+IeFg67U3r6isEdk6L9fpdo= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-zHgt2d54O3S7l6sxEWokPQ-1; Fri, 08 Sep 2023 16:03:28 -0400 X-MC-Unique: zHgt2d54O3S7l6sxEWokPQ-1 Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-5733de62ca4so409757eaf.1 for ; Fri, 08 Sep 2023 13:03:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694203408; x=1694808208; 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=D5N9QZ7B28jphbzV2QjYcCqvYyv8IVk+/iMxnc24dx28GC8dK5UK7MUoHcwO897xWl k6Pwu2UMPoLi69VRtar14toCPkLCFiZMJaG3ZhOvk7aEfbmaMZDufdsApE1MEElOhE1x rClHWpTyTRumhif0WXDA5gBoBfkHRkZWm9GTf0rGFHDRS1K/TMwxyHRe1XOOitivIxVm lqcW+rSWvE0K37BD94tdn44ROxyCHXWlbJCmDW7FmOeKNn0V7TO05GvC16sdknLIfKD3 ASIC4eR6WboVBT3ZGG9vumJQIDZHhkUVnYKVP7ugHxTKZqdlPO3aik0NUAVGzs4XN60F LuBw== X-Gm-Message-State: AOJu0YyICJ1txaEh1AmL2IkpZww3vQjWwqcYKYvzoUf3W6sAa4um/AcE MPnMvzw0BCDwOjASlAuDMUN4Fi/9p9fwtA+/gh90bYsjTLP88VgnC/j2NnDeclvXPPH7nulvQ2C vDwmSgoJKU/birk+WRmRGN81S X-Received: by 2002:a05:6358:e9c:b0:134:c407:681f with SMTP id 28-20020a0563580e9c00b00134c407681fmr2557595rwg.1.1694203408128; Fri, 08 Sep 2023 13:03:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4gCAzKUix7oIOcBNdjPHJEb7aCyOwwUAu2PzcC43CT3hwK4BjknICUG8MLI4Ii5zItWgaJg== X-Received: by 2002:a05:6358:e9c:b0:134:c407:681f with SMTP id 28-20020a0563580e9c00b00134c407681fmr2557556rwg.1.1694203407699; Fri, 08 Sep 2023 13:03:27 -0700 (PDT) Received: from fedorinator.redhat.com ([2001:9e8:32da:e500:513e:fbe9:e455:ae67]) by smtp.gmail.com with ESMTPSA id x29-20020a0cb21d000000b0064f53943626sm971150qvd.89.2023.09.08.13.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 13:03:27 -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 Cc: VMware Graphics Reviewers , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-hardening@vger.kernel.org, Philipp Stanner , David Airlie Subject: [PATCH v2 5/5] drm: vmgfx_surface.c: copy user-array safely Date: Fri, 8 Sep 2023 21:59:44 +0200 Message-ID: <3d2b36a2cf7bbff1b036f474eb805e19be3c57f5.1694202430.git.pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/vmwg= fx/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, vo= id *data, sizeof(metadata->mip_levels)); metadata->num_sizes =3D num_sizes; metadata->sizes =3D - 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 =3D PTR_ERR(metadata->sizes); goto out_no_sizes; --=20 2.41.0