Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp97018rdf; Thu, 2 Nov 2023 15:03:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLEDKSiIqOArBbwGHiR4EIbB19hBDcoaRTufZ3bF4XsZnhiaqo43UiQIisfnck+kFRnlMX X-Received: by 2002:a05:6a20:7da4:b0:154:4246:d63b with SMTP id v36-20020a056a207da400b001544246d63bmr20730197pzj.25.1698962600967; Thu, 02 Nov 2023 15:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698962600; cv=none; d=google.com; s=arc-20160816; b=AP239dmvkE3EK6rUZT6HEyc4txtG62up6c96yvIuHgVnDrhFg5YkIsbLtHypXmtreT f+gjiKcpCBCs5nPAcC4iYwndw1yWSxkzLvWPb2CFEQnjorjS1wlTwMUyurnKLOLOy2Uj IAybjYkARhHUj4ZFX66oMqjP27NsuYLz0tuxuYVc+2y41zceuXx3IkPkafYNHgyTSyJW ByGxOfBW/Zj2oea0EfRE6cLrPK6hvkyQSUrKwuQGhBwvUpRHorOzYgmM3YoU11n6Gw+P g8mXPQflahrjDnJatujhZ9+NEwD1gkWm38mTblRcr3is/7oVJVxT6nc+/Yq7oZgBcr7u 4vow== 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=OJIex0iBPXEPEipoAN2zQv8ZN5dF+ogwUiK0fjM1zeY=; fh=9xxR4dSvqZsRvqeZWSwHvWQ5O3ZXH+VVGFCHZW8rKgU=; b=dD/sijAIyVj4vn7tHowKFGgvmpCsgZaSjJq4rmEoc7L2gmaj6Xrk2G2ePWUOBAnbyI SqpH+xQnnDlMBM7/cfWQhc0iUOh7+N2FDdKK7p4DNdXQPox5HWUj4gUsKdPB2G2aZOzl OpRV5p+4ViFBu7rmPRyppF/ycTscBKmmWUTyUqTn7105enpdblWbhq58GkN2oTK01s/I YJxIS4AnZ4XUrAMn6hMeZqVYetfWQyIENptXY5LjI7au0uScZJvdCY8GfL5lLhJzYf1T /lg+GAPpAtdxJXCpqE5GIeLSIcY7xGAggX/F/Vty4nw4IrbAYgdJAVvBuAyG/PB1PGeF bczQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YBApA3xD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b005b837c29d22si338061pgv.177.2023.11.02.15.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YBApA3xD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id F3EA8804E838; Thu, 2 Nov 2023 15:03:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377418AbjKBWDT (ORCPT + 99 others); Thu, 2 Nov 2023 18:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbjKBWDR (ORCPT ); Thu, 2 Nov 2023 18:03:17 -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 65D0A199 for ; Thu, 2 Nov 2023 15:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698962561; 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=OJIex0iBPXEPEipoAN2zQv8ZN5dF+ogwUiK0fjM1zeY=; b=YBApA3xDF7pk0+EM/Ew6YVqP3pMtCiyhuWZp2JVyiqhs73m9GD1PdwVMDu0C5ocjjXvg0E Xc6TzgjiGnV0j6aY7IJzRxi9wz+B6RGSqAEQbAkvaYwE4AyU51HROUb51Pr+rufBJ3FFxl uMGJ0XjfLoA3/o2IdUVn+6XzLKgyY0c= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397--w_7nGCZMa2F2_oeNaL_GA-1; Thu, 02 Nov 2023 18:02:38 -0400 X-MC-Unique: -w_7nGCZMa2F2_oeNaL_GA-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5435b614a0cso194675a12.1 for ; Thu, 02 Nov 2023 15:02:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698962557; x=1699567357; 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=OJIex0iBPXEPEipoAN2zQv8ZN5dF+ogwUiK0fjM1zeY=; b=Y6VMQdpZWid2njCsBQVS9YREgVin+MapwdmypMnvP72ULibhGauh45YTkB2sZK12HV hgdwUlBJbITGGXaGh9evIhOrUPEEeGwUusa8OeC+6oEdkYR5yEzZ6XPmh5MmYT4zJRgr xdf6Rm3Z1lrIZYKOissiMHTcw1e8BQTcwPoEJNPu8fV7GECI+rWWcHr9ksrRQwFr4yOV H/n/EZrYdVSWGdrN4+YTiQm148EXlX8SbAMScTdWv705ZxK1VOJlCgtWjeQbtHCuCtf1 cKdmucn+eegvfyhN/DlqnM1srxuDd0G3Uc/z6nKsybz1CEn3YR92fSEPlU1Vs9NvCOKb UkGQ== X-Gm-Message-State: AOJu0Yz1YUrM7nEYznbXm3K0Op5IN1D+jkSQtp/HDHP8dF570ZLd3ZjB wO5l26mJz84+bhpZcoxPi5k2bqFWEJbXgooNmjY+iZPJQ4ZqLPU8P8yk8/vgp7O8Y88rB44P6B9 7LoVqgPRp1Tgq11MXjuYflWl+ X-Received: by 2002:a50:baef:0:b0:540:a181:f40b with SMTP id x102-20020a50baef000000b00540a181f40bmr14361460ede.4.1698962557140; Thu, 02 Nov 2023 15:02:37 -0700 (PDT) X-Received: by 2002:a50:baef:0:b0:540:a181:f40b with SMTP id x102-20020a50baef000000b00540a181f40bmr14361441ede.4.1698962556843; Thu, 02 Nov 2023 15:02:36 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id d26-20020a50cd5a000000b0053dab756073sm199543edj.84.2023.11.02.15.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:02:36 -0700 (PDT) Message-ID: <7a26cd1bafb22b16eab3868255706d44fa4f255d.camel@redhat.com> Subject: Re: [PATCH] drivers/net/ppp: copy userspace array safely From: Philipp Stanner To: Al Viro Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stanislav Fomichev , Greg Kroah-Hartman , Benjamin Tissoires , linux-ppp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Airlie Date: Thu, 02 Nov 2023 23:02:35 +0100 In-Reply-To: <20231102200943.GK1957730@ZenIV> References: <20231102191914.52957-2-pstanner@redhat.com> <20231102200943.GK1957730@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=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 02 Nov 2023 15:03:20 -0700 (PDT) Hallo Al, On Thu, 2023-11-02 at 20:09 +0000, Al Viro wrote: > On Thu, Nov 02, 2023 at 08:19:15PM +0100, Philipp Stanner wrote: > > In ppp_generic.c memdup_user() is utilized to copy a userspace > > array. > > This is done without an overflow check. > >=20 > > Use the new wrapper memdup_array_user() to copy the array more > > safely. >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0fprog.len =3D uprog->le= n; > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0fprog.filter =3D memdup_user= (uprog->filter, > > -=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=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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 uprog->len * sizeof(= struct > > sock_filter)); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0fprog.filter =3D memdup_arra= y_user(uprog->filter, > > +=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=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=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 uprog->len, sizeof(struct > > sock_filter)); >=20 > Far be it from me to discourage security theat^Whardening, but a bit about the background here: (tl;dr: No reason to worry, I am not one of those security fanatics. In fact, I worked for 12 months with those people with some mixed experiences ^^') (btw, note that the commit says 'safety', not 'security') We introduced those wrappers to string.h hoping they will be useful. Now that they're merged, I quickly wanted to establish them as the standard for copying user-arrays, ideally in the current merge window. Because its convenient, easy to read and, at times, safer. I just want to help out a bit in the kernel, clean up here and there; it's not yet the primary task assigned to me by my employer. Thus, I quickly prepared 13 patches today implementing the wrapper. You'll find the others on LKML. Getting to: >=20 > struct sock_fprog {=C2=A0=C2=A0=C2=A0=C2=A0 /* Required for SO_ATTACH_FIL= TER. */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned short=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 len;=C2=A0=C2=A0=C2=A0 /* Number of= filter blocks */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct sock_filter __user= *filter; > }; >=20 > struct sock_filter {=C2=A0=C2=A0=C2=A0 /* Filter block */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __u16=C2=A0=C2=A0 code;=C2=A0= =C2=A0 /* Actual filter code */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __u8=C2=A0=C2=A0=C2=A0 jt;=C2= =A0=C2=A0=C2=A0=C2=A0 /* Jump true */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __u8=C2=A0=C2=A0=C2=A0 jf;=C2= =A0=C2=A0=C2=A0=C2=A0 /* Jump false */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __u32=C2=A0=C2=A0 k;=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 /* Generic multiuse field */ > }; >=20 > so you might want to mention that overflow in question would have to > be > in multiplying an untrusted 16bit value by 8... >=20 I indeed did not even look at that. When it was obvious to me that fearing an overflow is ridiculous, I actually adjusted the commit-message, see for example here: [1] I just didn't see it in ppp. Maybe I should have looked more intensively for all 13 patches. But we'll get there, that's what v2 and v3 are for :) P. [1] https://lore.kernel.org/all/20231102192402.53721-2-pstanner@redhat.com/ PS: Security !=3D Safety