From patchwork Fri Sep 8 19:59:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13377791 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 56719EEB566 for ; Fri, 8 Sep 2023 20:03:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245064AbjIHUD5 (ORCPT ); Fri, 8 Sep 2023 16:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232883AbjIHUD4 (ORCPT ); Fri, 8 Sep 2023 16:03:56 -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 C021CE46 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4V6bm459ozDimu1heDZpH+ZMi6MrCIxlIoO52rIEKGg=; b=BQBkhuZ9PfiOe6bAp4ii50nJSvvprmCN0nxVwUHdHNj8vDjT1em2vA1MhJOwsedmCLrqtB hc7g5BoP2Ko9ERPWVqUT4NTzBU7oVdmr+/ZG2Qmu8reKmvuv1BfEc2vwoKKFHrtw1KLPsJ jeqaPkz2cxswM2VrR7b1AtrWytEL9yk= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-0PLk8I5bP2yYb5D3ZNf4aQ-1; Fri, 08 Sep 2023 16:02:52 -0400 X-MC-Unique: 0PLk8I5bP2yYb5D3ZNf4aQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4121a931b1fso3336101cf.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=XzgRAmtvt7ms5SPpYIegrs5q3yDGMPTOKD5UN2uq3maoEss8lib6IDNWQvJRjh8y1R u/maDfHCBT/G9+9fqTrS/CYQKNiV84fB30LgS9erujDmohgPIWa9SsotVsdCw5zI1BOH D1MLIUtxdt1K6tPumYR0PBVJVg178F4BlA7N9yUqV+hEixfew/Z/TaKr2JMuilDzGAYf W1gbRVZxPgzDqWrKPQEoBYLYqk8gfV891tyZnaOmTrSKuUWC6J6zWz7RIFjWeczx61ju N9g7wznonXFTqNfWeYfdt8UTGP7ZPgWQtnzZ4Vk/5xwbugYV/LOP+2F/41Zll4kLtdOe QQhQ== X-Gm-Message-State: AOJu0YxdXPyk7fHfE6y1vaV/bYQLkuZIF8LZDvwva1i6TNuLnmWdP0dP stocJ3KgVr7FnAKvoDb2j0T+60acxAiXH9wvS5kLyBI04JW+fierQHDKU1NfQB/MwxaPuRrTwp4 k0hLEaKWOmmAQV8zoifYQ2+qAbcUr X-Received: by 2002:a05:622a:1997:b0:40f:da40:88a with SMTP id u23-20020a05622a199700b0040fda40088amr3927393qtc.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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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 --- 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 @@ -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 (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, size_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 */ From patchwork Fri Sep 8 19:59:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13377792 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 A471AEEB566 for ; Fri, 8 Sep 2023 20:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344477AbjIHUEG (ORCPT ); Fri, 8 Sep 2023 16:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344479AbjIHUEF (ORCPT ); Fri, 8 Sep 2023 16:04:05 -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 1E3051B0 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJlM81Ad0uqQunhdFKofh1JwhP2kaFm8hxSxz8OfTMk=; b=bzizTypi9G7KWH9+PtT265OdytWC2oMLvDmw/JF+v8zLtKgzPnt08nWgNQnUu/Gr1R3yd0 L3ylLkMq8CQN7RApJ8t2ny5mifzEXa2uK67ibPgBjHnX5XDnApTl7XCd5M+s/TD2xkXKrX q1amT77gWvHci9kD+vDtBtAzr62wh5M= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-oAHmtuwLPLmOP3MEQjNZJw-1; Fri, 08 Sep 2023 16:03:02 -0400 X-MC-Unique: oAHmtuwLPLmOP3MEQjNZJw-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-64a4269ca98so6043416d6.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=TMcvSPpRpwRC7blFGJ08X11AUcLgYS7NYBu8uSPHQ1+rKwciZqLaqwcUVlYNWHxzd8 tcDd0uatxWfIfrDi18W4kU3Xdw79RYucHhjdsDGyxVkFPp3KyRDjYuworLLwIPW7YUaP NY+SOswbbc1crepjy1xHjG7hoC61HUsYXkQCxleLvtOKN/qvh61xFgJY3qfLNQqw1Qzx FSIVqJsQPwQ3xnzJ1+qzSpnHQ/8YMkXDaAyz+fIPeJ9s/+mcAp2x3OOgsfmhhfs21kTV hx+c2ckYorFDbc9VFpVGBRChC2FmH4HrhrEXjZucP92LliZtHNtMQgyK6/doesi3X2lN jHWQ== X-Gm-Message-State: AOJu0YyFEVEHKKTM4nFUSvlBy5sTyoZ1pVx7lPCXQy6n/Aj3NMXSw7el vByPsfNlfC89OZI1okd9aNI0D0BH4bN3tlnD8+HRPdoFtkrKlWsDgyKfIju/Q6PEeVMyVueQDEs 6akWBlrcF6FQjGi6m4bP6p+n176X0 X-Received: by 2002:a05:6214:234b:b0:649:5f43:245c with SMTP id hu11-20020a056214234b00b006495f43245cmr3403719qvb.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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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 --- 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 Fri Sep 8 19:59:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13377793 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 D4815EEB566 for ; Fri, 8 Sep 2023 20:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235478AbjIHUEN (ORCPT ); Fri, 8 Sep 2023 16:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239679AbjIHUEM (ORCPT ); Fri, 8 Sep 2023 16:04:12 -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 806C2186 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R2kuY7QrN77OjYcmiIgmsp8RgTy5tijHIGRui0VqTUY=; b=KCRLv7MUEt6Q0udobb7lP1jekmzhVia2f/RZ4M5uqfLqVYA+7MDEupYLccbWaAQXwetsyj e/7eDyGSGd1KvoRizwWL7CWOjdvkKMET2uf4cNXM5VlrvtVaN/7SyS8+DTbR5uOwlRd7pY vuv4sljZSwe5mYLb4yOe9+xlBkMFP6g= 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-633-MyeEWRL8OryOgDGm23HhbA-1; Fri, 08 Sep 2023 16:03:11 -0400 X-MC-Unique: MyeEWRL8OryOgDGm23HhbA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-76f191e26f5so58808585a.0 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=d0XhTcnPdOgp4agu2Lm8ZQ/EP6k61LfcMdGPUwvWqlBzMXACn6lTvzfLOR+txpwTis af1gYLcSoXzEbaIjHmLLD0wTjV9dMVa/jAQ1mL5CLttur3X5jBcQtVvid92c8Uj3glRZ sUSbfzpkSWGiSNx61vMnZ6vGYZZL4IEqeOTbCMCSv4vaj9/fRlzorYkaD34FCbEMPvaf DK7mIGvpmrHJFGtJ6rNNNliaY9Xtl393FZbrzBsHxirEuahfLmOnwqfk5dZg7HfREseH SVXO+MVIhzAfJky9myI25vXRBfNiHi7srLo/RxqINBOOEOwsUf4WcwSYSoaJ/jjPZVZ0 HW/g== X-Gm-Message-State: AOJu0Yy1b1lbsgQU7IIDWUbBpXoZ+3Yd5sGQH90La6lMoos4iS6fsaMf In6+2O8WMJZaRyEZMv4w5N/Q1aOPduTKpqAwc/Tk46dcvY/ztQmrA61Le+YyjfCY573sLUndyT4 Z/A5xyGui+8ooCILcXV1H0MkTs96U X-Received: by 2002:a05:620a:46a6:b0:75b:23a1:69ee with SMTP id bq38-20020a05620a46a600b0075b23a169eemr3480485qkb.5.1694203391485; 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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 Fri Sep 8 19:59:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13377794 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 62C3AEEB569 for ; Fri, 8 Sep 2023 20:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344483AbjIHUEU (ORCPT ); Fri, 8 Sep 2023 16:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235377AbjIHUER (ORCPT ); Fri, 8 Sep 2023 16:04:17 -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 C30448E for ; Fri, 8 Sep 2023 13:03:22 -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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UOJpuwbwTVfs+j95sEE93OpkqtbclA96WzipEC/nM14=; b=erlHO7hbw1szw2sDthqNrRren8EIUJBQBZDEb1so9d2UwIJKUsDsRAw46vChsz9Euv/NW4 w3oKxm3+OfcFWl9j/LR89hmWMvfk5NhsRas7Q85XPBGk8bPAPS4au+1b7OdVEM7P78sk6X DXUtfiFORk5hCn/FgwIuzAVI4lX9phg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-xwx28b8JOg2d0tmicZlUYQ-1; Fri, 08 Sep 2023 16:03:21 -0400 X-MC-Unique: xwx28b8JOg2d0tmicZlUYQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-40559875dd1so4945761cf.1 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=v41iUWslGIwf7BgY1aie88UHSxOxHx6CT9GnuvicGaxqSyec5rELYOPbfIesGgfDja 7am4ZBPdw5RtA4Fu4wNaKvoRRybmgRb/6Q/IeQYxVvtLVuTeAfYXa4xVVouagUim9OOu fdbjY4VvwIMyc6zT1kEujp6KocMtViZyR6T9wLRBtyuHxdJ3ZCUkcAOTMyUxMdf4Pnhx vgswje3ncmpytBjOf5cQj1AMVZD7rTc/Pj1zQyRG5KSvcuvd6gGbkthsVlpdC7nj+FEM 05gsLKJ4ni33e5XbUoRsj44L4q8HhPtTXFWjNFF3Qb91CgiHkPvNJbOO8BdyOZKk7XMl OrxA== X-Gm-Message-State: AOJu0YwEnPJ4P5eDXmm5BkUMNoNj17SqSnkBuCg+jEa30wxBSpZXDSl+ XVfULqB3rrPTKP6PYLgpUbS1NN9REKf4oxj90KJSiqHhwpRO1xtoYT0sArii5xLPrNj07QwR0CU d+HxPpfWX7Xd7zPw6xcoJnoCkFmD2 X-Received: by 2002:ac8:7e94:0:b0:412:12e8:8538 with SMTP id w20-20020ac87e94000000b0041212e88538mr3683934qtj.1.1694203399546; 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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 Fri Sep 8 19:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13377795 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 4FE56EEB56B for ; Fri, 8 Sep 2023 20:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344482AbjIHUEW (ORCPT ); Fri, 8 Sep 2023 16:04:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344510AbjIHUEV (ORCPT ); Fri, 8 Sep 2023 16:04:21 -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 C6B3CCF2 for ; Fri, 8 Sep 2023 13:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694203412; 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=c3h7XPFbBHsHy20pb8A3s365xSIrpDGHGQciJWa3bskMFGRnfvKGufr+/ulkkc+tay8S2q eVxu1st2JmHOf7wMMzLfeoUdKIdHVFJfc9HPiuEm2EQxj9D7b0SN/5jnTgt46BGETjkl3a kIRcVzIeyNNw+cvbbzkXwmSF1Wberu8= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-oL7M8f36Pa2h0gd9_D5O1Q-1; Fri, 08 Sep 2023 16:03:29 -0400 X-MC-Unique: oL7M8f36Pa2h0gd9_D5O1Q-1 Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-5711c85f02bso414322eaf.0 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=lzAxyGlwxD9eFuRelHv3VIfecM6HKCrmAfAHQxSffOBFvdPD6s+hVPTG8cs9718ALB ydys3n055UxOzns2VpaEE1+jMuQdEwD9ZgzncdtYjBodK2QFaV5ialVYDyNV6jUzEt/t t7MdB8w5iOdU6I8+U6HOyUaxPrZKmQoL+5aEwMNoX1QzQQXtkeqGD+FwRTkDdJL9O5Bb WBgM7N44Y6x4EOF3zqJ8sCFpCefDTyR1ESL1cHvw+CVLMhD3pwJVfTtu0DHhJ6ExwjVO 5zuZ2EFNu9jCQ24//wfNrykyLy+vOVyaYaAQ+UjhP0atSvcIZJzrdamYkhyEG+yhSPn0 DIcQ== X-Gm-Message-State: AOJu0YxJQYG+uEqbhSYwM9Vg+X1CZC/W81xCO7Y/A1mnVmh+7EcIuNGg WP/xjMD3DE8PXrGKKIo4yx9DdtSNURTpQWymEIWqZHGG5AeIIR+muQMPoXbLT820dUzXShGyz1m AJVqYG/mQinhL7pI9wpQutrlQZkk/ X-Received: by 2002:a05:6358:e9c:b0:134:c407:681f with SMTP id 28-20020a0563580e9c00b00134c407681fmr2557578rwg.1.1694203408125; 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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;