Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp100721rdf; Thu, 2 Nov 2023 15:09:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/RF/zieYZ+mko7nsevP3KovmTVVCzh9Im+nqx9fsYvOJfaFW4qyQY7Ar3oiNxKKhJtEeE X-Received: by 2002:a17:902:f0d1:b0:1cc:32df:40e7 with SMTP id v17-20020a170902f0d100b001cc32df40e7mr9496807pla.66.1698962942714; Thu, 02 Nov 2023 15:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698962942; cv=none; d=google.com; s=arc-20160816; b=GT4w4TPcNREs6qyCqm8eka2rXPilkQ10ug906lkthu/TqXYm6tOtgkSlLPLjPkCl0m wdxcIdDJ1PxJuK0ItAp+rB6jNvDotahHYZTJZEa4Vdlsyb/86keobFuMd0KgP7HC4ZPE Iq+QZzcKuXY0U4sgKIIinrHap7ND8fLmWL116Dx0L2auRbxepol10mXXdOOVnYvPKfrh yJ9guLE290QxV8mles7G+9lfn904AFTiURrhP9xOFs6lGjodioHNDsRTuW5FCAQ2lALL 75CIBSyA/Vn1+JvDKWTiYHv3uDrw/Q/gl8K2g9a5/VRifCT47iH0ESHmEuVoc8ueWeY2 Lu4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=IkWJVPJFaRtARApP/xOT73zf0/RfYFWCBPOHT7K33GA=; fh=nsMEcp8kQHlZLWkEO0EASl/0C2MCR5TOK1H8bPqzuiA=; b=ssajmn2n7Dwc67XqUns0hSGGVM6pc88WX/Pt4GRSEF4gjQ7zAilKB0IvTJgtSonsuu TptFvdWyvGr5GpIvoFqBBt9YzK3/217t1+sSmbhff7RpJfo2KCEqXvoQtghHlLZEVX0Z At3dApdGGXpBkApjUMdfqmD7wATVyV+gB0vheugR7JT40xi0sX2tfA1utCtDsheYRbmn KuEagQy+HuwgeBUsgaildmbi5pE7g7U6SW3qOYPmSzbylf6ImGcGIz7Q6NG2bGbdLPxb 29cER8cP7mgfTUXfxaaSMhc+hmAaCeuaDkv21t0QdxRgdfFcbMUB2uH7cNCcZwMuGTaG 2nYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XD+U+zkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id lg8-20020a170902fb8800b001ca7308e42fsi308785plb.631.2023.11.02.15.09.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:09:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XD+U+zkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 24BD88116B31; Thu, 2 Nov 2023 15:08:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229741AbjKBWIt (ORCPT + 99 others); Thu, 2 Nov 2023 18:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjKBWIs (ORCPT ); Thu, 2 Nov 2023 18:08:48 -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 05AB8192 for ; Thu, 2 Nov 2023 15:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698962876; 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=IkWJVPJFaRtARApP/xOT73zf0/RfYFWCBPOHT7K33GA=; b=XD+U+zkhV4h3DGLK1fL77d5s6gnL6PmXhEWqix4a0FegLE/AnCZyiVif1/k6eM5OddMA1I XUB8ke6jOrDnBBfXfmEX0VXB08eMKTCphIyQna0t1HVSy27pkG48gs6vcxt9d7iKyERCrM Yw67XPzZPy6dt4seKUcerUJsMf5Q/Hw= 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-118-9OOaCS8BM1O3GmQE0wWWag-1; Thu, 02 Nov 2023 18:07:54 -0400 X-MC-Unique: 9OOaCS8BM1O3GmQE0wWWag-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-534838150afso228393a12.0 for ; Thu, 02 Nov 2023 15:07:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698962873; x=1699567673; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IkWJVPJFaRtARApP/xOT73zf0/RfYFWCBPOHT7K33GA=; b=wjjgPIuDVxzg5jELi4gVZulazPo4dJV2QdLQkn7LXosht4OgQUNauG5p5pggKrnybx t1RF07z3pArKAFaXqkbdWbpANyhM09tc2YXJJX+YWSGkFm9mR+95AUBgUKf9FgkSgVf1 BMAt39Rv1/V9eONG6wBfVFpz7s69OVjKNRMPJAGYY7QTAD3hXwh0T+PCc/HMZOy7OkUE BmqnkogSQwZPhICde8ajW2Fpg6SzwrAeczwrxpFvatKQKhqsIUsAP03RYd08uI8osguJ wgciDTZ8nZ6m2zKvoIopCWfb0mlRYGfu/RXs5damm/MleF654uYXJVmdWmzuDo4AXQZD 7ogg== X-Gm-Message-State: AOJu0YwfI6KjvWDmAtSzntOC0TfwsmxLVbIimlgipNk+8QWe+OlpfSul oiLHv/Em6MWcPKQ5vWMeTwse8gm+uRLcsm+WMOVOKoJ9AIHKWhy2JyipQ8m4ft58gENsFKZbJeM G9xARdeChicUJiKgibiCVaz3f X-Received: by 2002:a50:c05b:0:b0:543:83a3:f39 with SMTP id u27-20020a50c05b000000b0054383a30f39mr6383129edd.4.1698962873044; Thu, 02 Nov 2023 15:07:53 -0700 (PDT) X-Received: by 2002:a50:c05b:0:b0:543:83a3:f39 with SMTP id u27-20020a50c05b000000b0054383a30f39mr6383110edd.4.1698962872750; Thu, 02 Nov 2023 15:07:52 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id u14-20020a50c04e000000b005412c0ba2f9sm212636edd.13.2023.11.02.15.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:07:52 -0700 (PDT) Message-ID: <37ab45c67d630b4832912cb8403ce8235f52d9c0.camel@redhat.com> Subject: Re: [PATCH] drivers/tty/vt: copy userspace arrays safely From: Philipp Stanner To: Al Viro , David Airlie Cc: Greg Kroah-Hartman , Jiri Slaby , Andrew Morton , Kefeng Wang , Tony Luck , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Date: Thu, 02 Nov 2023 23:07:51 +0100 In-Reply-To: <20231102204903.GM1957730@ZenIV> References: <20231102192134.53301-2-pstanner@redhat.com> <20231102201424.GL1957730@ZenIV> <20231102204903.GM1957730@ZenIV> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 02 Nov 2023 15:08:57 -0700 (PDT) On Thu, 2023-11-02 at 20:49 +0000, Al Viro wrote: > On Fri, Nov 03, 2023 at 06:24:09AM +1000, David Airlie wrote: > > On Fri, Nov 3, 2023 at 6:14=E2=80=AFAM Al Viro > > wrote: > > >=20 > > > On Thu, Nov 02, 2023 at 08:21:35PM +0100, Philipp Stanner wrote: > > > > The functions (v)memdup_user() are utilized to copy userspace > > > > arrays. > > > > This is done without overflow checks. > > > >=20 > > > > Use the new wrappers memdup_array_user() and > > > > vmemdup_array_user() to > > > > copy the arrays more safely. > > >=20 > > > > @@ -644,7 +644,7 @@ int con_set_unimap(struct vc_data *vc, > > > > ushort ct, struct unipair __user *list) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!ct) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 return 0; > > >=20 > > > > -=C2=A0=C2=A0=C2=A0=C2=A0 unilist =3D vmemdup_user(list, array_size= (sizeof(*unilist), > > > > ct)); > > > > +=C2=A0=C2=A0=C2=A0=C2=A0 unilist =3D vmemdup_array_user(list, ct, = sizeof(*unilist)); > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (IS_ERR(unilist)) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 return PTR_ERR(unilist); > > >=20 > > > a 16bit value times sizeof(something). > >=20 > > So since it's already using array_size here, moving it to a new > > helper > > for consistency just makes things clearer, and so you are fine with > > the patch? >=20 > Sigh...=C2=A0 OK, if you want it spelled out, there we go.=C2=A0 I have n= o > objections > to the contents of patches; e.g. in case of ppp ioctl it saves the > reader > a grep in search of structure definitions, which is a good thing.=C2=A0 > The one > and only suggestion I have for those patches is that such patches > might be > better off with explicit "in this case the overflow is avoided due to > , but use of this helper makes it obviously safe" - or, in > case > of real bugs, "the overflow is, indeed, possible here", in which case > Fixes: ... and Cc: stable might be in order. >=20 So if you agree the content is improving things a little bit then it seems the only critical thing is the commit message :) So let's get that fixed, shifting the focus from security to readability and general usefulness. Do you have a proposal for a good wording? Personally, I would have gone with something minimalistic like here in my other commit, where the irrelevance of the overflow-aspect was more obvious for me to see [1] I can also add a sentence clarifying that it's about improving readability or sth if you think that's better Kind regards, P. [1] https://lore.kernel.org/all/20231102192402.53721-2-pstanner@redhat.com/