Received: by 2002:ac8:6216:0:b0:41c:c224:f26f with SMTP id ks22csp89955qtb; Thu, 2 Nov 2023 12:22:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExNt9Pl/fzXGBBOVidRSQdyN6y6QxfqVVtN21pnfq5IF9niOr5V4AmTNte8+Mlc5id8mNz X-Received: by 2002:a17:903:1248:b0:1cc:c0f:2e9b with SMTP id u8-20020a170903124800b001cc0c0f2e9bmr20336062plh.24.1698952976582; Thu, 02 Nov 2023 12:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698952976; cv=none; d=google.com; s=arc-20160816; b=aipBzNAEoKJwCPE7OLRw18U/Fvq6ixLzul/tph1PwZzpqvQTJBbX5xCukuNtuDED6d 1QA3DuQcrfwtjxAsW7zfNO/qJiX0CQ/o+Pena4NMD0Kxb96SKts/Zq9gqS1MxHEbsOyu ES3Lna6ckZd8O239UxumJlmprZIu3jwYZNP6W9ee82lsY5RPeQ8zZcH0DYafHwjLq6dd q2r54w+qJii6XRkpbmwtIXlXvcnEa+tLBBkc+eBpR7BG94TB5bY0N8TgAXWQSjNv5ANl FSxUKN7v41zZWqhxKDkJAjj46QC8eZk57X4SQBU8fhJ3Y7MtHgtE3nfSD6SV77l/E4sE 10tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gMbvaW7xFMUV0KcreKNTNoj1dffs08hfun7sVblosFo=; fh=gwMj7KKqBdLg33TLJX0Yhq5ZMkK97ngna/l7Z6dGL60=; b=pk4SWFe5Q4BRN4ABw7s1UBCD8IgyaZMf5JvBJm8yG+RZQlJJaI9U/pt0ci5iQmIngs NG+Fnm5BQ+ZH5OgF17yUHucd8b9AvLO/OW190+0iB0np4CnrfcuSgzEdDV1RN7latjAi 9Ua866/dch+yrglUU3dSw4rovG7dywoFOEtwNiI0vm4Q20G4d4fXxgSnRAvgqycNhqQg Jq9N9ZuMUUQ5IS0PH5EbRARAyXmr9JBP1IAFMR9MG/vtukLlUDWvXFssOWgErkt9w5Yz fzQYf8Z1JwyV47AnySh+ydkTChbM7fQgQTh4RV5aBk83lMDMaAtqObLxGkyC6X8AYGua 9e0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W11wx1jL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q7-20020a17090311c700b001c6069b659csi146712plh.384.2023.11.02.12.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W11wx1jL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 172338135D70; Thu, 2 Nov 2023 12:22:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345284AbjKBTWq (ORCPT + 99 others); Thu, 2 Nov 2023 15:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234296AbjKBTWq (ORCPT ); Thu, 2 Nov 2023 15:22:46 -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 23F3F18C for ; Thu, 2 Nov 2023 12:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698952922; 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; bh=gMbvaW7xFMUV0KcreKNTNoj1dffs08hfun7sVblosFo=; b=W11wx1jL8w+9uL2q8KDkPBOaGvVbXJdqMML9fEnx9VMdngtHEch9sfd+0X7OoOlG64qbjg Anzi67iIkNgrmZeXs9V2KVn/KKR8UIAfaC+BRr9JIBBhcmzjdf8EeZOsQQj7njNEvOqos9 BwrSLmjnJSpq9pEvEnvTPS+CghgQFDk= 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-664-zLzjRFtoM5KatsAlfDD-HA-1; Thu, 02 Nov 2023 15:22:00 -0400 X-MC-Unique: zLzjRFtoM5KatsAlfDD-HA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40856440f41so2739945e9.1 for ; Thu, 02 Nov 2023 12:22:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698952919; x=1699557719; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gMbvaW7xFMUV0KcreKNTNoj1dffs08hfun7sVblosFo=; b=EFyx84n5suHhEVsM1QdFSZEGlqvZoW02XFXcH90/AeNRpJXJ0I1/Bi68fD4F3Jg9I/ XhvRGSARp/xTkaqqX7//naSr/RT+ML5phb7dCsMGukPoLd/6LX3ccHP8tR6mlz2ToXs/ trvDbrfX8O8FZCeyXbafzk8YJz5tJH9QzeGebwd+iQe9TsQibdZ2smC+YmR0V+S8tJfz 3X8Unt9xUQl6vE4BtgQdhHjlIOBAVDKqfDJ0MGHDG1p2BmvKBVmNRs+GVdOT1kw8Nrh5 LVls6dODjd8Wg45sBwuuSjiDmQrdO0Ivu+WeGtgbEJr0JPbWORrskGEaGJh/d+OZJzWk V/wg== X-Gm-Message-State: AOJu0YyhDasT+fBZdeUQ5kIoHhYraq8hrGqHcxHXk+PgqshxwTxA15dL iVAc+NXxguQYMqBDU5ZBAHqe29VEXXSW6d4ZLEpebvl/8HBAHTgYBg+Ipo4ppLHYwuDAdYhq+aH HPevSEEBg87gwaR82Jl20DznK X-Received: by 2002:a5d:6b06:0:b0:32f:7648:18b6 with SMTP id v6-20020a5d6b06000000b0032f764818b6mr9906418wrw.6.1698952919689; Thu, 02 Nov 2023 12:21:59 -0700 (PDT) X-Received: by 2002:a5d:6b06:0:b0:32f:7648:18b6 with SMTP id v6-20020a5d6b06000000b0032f764818b6mr9906408wrw.6.1698952919393; Thu, 02 Nov 2023 12:21:59 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id c18-20020a5d5292000000b0032da87e32e2sm119892wrv.4.2023.11.02.12.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:21:59 -0700 (PDT) From: Philipp Stanner To: Greg Kroah-Hartman , Jiri Slaby , Philipp Stanner , Andrew Morton , Kefeng Wang , Tony Luck , Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Dave Airlie Subject: [PATCH] drivers/tty/vt: copy userspace arrays safely Date: Thu, 2 Nov 2023 20:21:35 +0100 Message-ID: <20231102192134.53301-2-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 02 Nov 2023 12:22:54 -0700 (PDT) The functions (v)memdup_user() are utilized to copy userspace arrays. This is done without overflow checks. Use the new wrappers memdup_array_user() and vmemdup_array_user() to copy the arrays more safely. Suggested-by: Dave Airlie Signed-off-by: Philipp Stanner --- drivers/tty/vt/consolemap.c | 2 +- drivers/tty/vt/keyboard.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c index f02d21e2a96e..313cef3322eb 100644 --- a/drivers/tty/vt/consolemap.c +++ b/drivers/tty/vt/consolemap.c @@ -644,7 +644,7 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) if (!ct) return 0; - unilist = vmemdup_user(list, array_size(sizeof(*unilist), ct)); + unilist = vmemdup_array_user(list, ct, sizeof(*unilist)); if (IS_ERR(unilist)) return PTR_ERR(unilist); diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 1fe6107b539b..802ceb0a5e4c 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -1773,8 +1773,8 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) if (ct) { - dia = memdup_user(a->kbdiacr, - sizeof(struct kbdiacr) * ct); + dia = memdup_array_user(a->kbdiacr, + ct, sizeof(struct kbdiacr)); if (IS_ERR(dia)) return PTR_ERR(dia); @@ -1811,8 +1811,8 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) return -EINVAL; if (ct) { - buf = memdup_user(a->kbdiacruc, - ct * sizeof(struct kbdiacruc)); + buf = memdup_array_user(a->kbdiacruc, + ct, sizeof(struct kbdiacruc)); if (IS_ERR(buf)) return PTR_ERR(buf); } -- 2.41.0