Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6917852ybp; Wed, 16 Oct 2019 00:37:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqy72cboMfq8tNQ+BF6l12yVk3Z8lIhdhAGwWYKrPkynljPP+hTarDq78QfJkMn6Hygcga1V X-Received: by 2002:a17:906:3f87:: with SMTP id b7mr37865945ejj.107.1571211421087; Wed, 16 Oct 2019 00:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211421; cv=none; d=google.com; s=arc-20160816; b=Lr9JWK7po43MYu7VYk46vlncQPlKDNfY1qlc59M4BH4uQGWaXcQMiIGYPNkExPTmz/ wnor1/S/MLqLva/AomfsaDmCOssVc43TCSrfIJ7/QZ8HU5sJeSaAu5cj7l6OwCTZ40Kd mAZjIeRmlRJA2dKZAJv0Vb28VEwPDJyhybANCFQ6jOkMQ1BM+vb2sypdu8K6Y19zgpZ6 eZnE9praZNGHrdARL16wM0din0CHRoIOAqElcaEH+5o73jRect6jYvXzeyIT3b4hJdy3 78jr45Aaz/LxmTJCdFPqpRhTWZFexWjIJa/QWHWbQFKyDOAYl0uoboDUTm+yeuUZ+vbN uD2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:cc:to:from:subject:date :in-reply-to:content-transfer-encoding; bh=DoHzPsNfWWv2WV1/OPZS81O5a3p9Nwyj444bV4p5bcY=; b=xJ9sVXiMEJ5FUAMeMfK9Iti3dPrBwTIuaJcIsX4rj+d9+xF010Ib+HEt0OUn8FL7OS DB1QCGQ0D4NK34dByRY7gvMvwC9CvD/QVVULMTLnWxotYnGyXDCnPbp3tJmkTCRyGImx uVR1qGxpjsDP3zW1bgLouVNVR9HQeG+AwmdSvFYL2BxKX8Mjqp2Ad7gHHWsKtZ4PiONp AZ737N8fwEl81j3cZo2H007knhATaPf6OxuhlNvcxN8eSwp0NJdZ+EluWPSeKh5oq76k aGL13M3s15fLCjHr4V+Zlbx2B3MLGQ509Lut/9ziuLpsYD2O0NRY3OKf+MEPHghQlwqU AyGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q35si18206369eda.122.2019.10.16.00.36.37; Wed, 16 Oct 2019 00:37:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390193AbfJOXIv (ORCPT + 99 others); Tue, 15 Oct 2019 19:08:51 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:52043 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726689AbfJOXIv (ORCPT ); Tue, 15 Oct 2019 19:08:51 -0400 Received: from [213.220.153.21] (helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iKVvr-0000Jx-9u; Tue, 15 Oct 2019 23:08:47 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 In-Reply-To: Date: Wed, 16 Oct 2019 01:08:46 +0200 Subject: Re: [PATCH 0/3] bpf: switch to new usercopy helpers From: "Christian Brauner" To: "Alexei Starovoitov" Cc: "Alexei Starovoitov" , "Daniel Borkmann" , "bpf" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Network Development" , "LKML" Message-Id: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue Oct 15, 2019 at 4:02 PM Alexei Starovoitov wrote: > On Tue, Oct 15, 2019 at 3:55 PM Christian Brauner > wrote: > > > > On Tue, Oct 15, 2019 at 03:45:54PM -0700, Alexei Starovoitov wrote: > > > On Thu, Oct 10, 2019 at 2:26 AM Christian Brauner > > > wrote: > > > > > > > > On Wed, Oct 09, 2019 at 04:06:18PM -0700, Alexei Starovoitov wrote: > > > > > On Wed, Oct 9, 2019 at 9:09 AM Christian Brauner > > > > > wrote: > > > > > > > > > > > > Hey everyone, > > > > > > > > > > > > In v5.4-rc2 we added two new helpers check_zeroed_user() and > > > > > > copy_struct_from_user() including selftests (cf. [1]). It is a = generic > > > > > > interface designed to copy a struct from userspace. The helpers= will be > > > > > > especially useful for structs versioned by size of which we hav= e quite a > > > > > > few. > > > > > > > > > > > > The most obvious benefit is that this helper lets us get rid of > > > > > > duplicate code. We've already switched over sched_setattr(), pe= rf_event_open(), > > > > > > and clone3(). More importantly it will also help to ensure that= users > > > > > > implementing versioning-by-size end up with the same core seman= tics. > > > > > > > > > > > > This point is especially crucial since we have at least one cas= e where > > > > > > versioning-by-size is used but with slighly different semantics= : > > > > > > sched_setattr(), perf_event_open(), and clone3() all do do simi= lar > > > > > > checks to copy_struct_from_user() while rt_sigprocmask(2) alway= s rejects > > > > > > differently-sized struct arguments. > > > > > > > > > > > > This little series switches over bpf codepaths that have hand-r= olled > > > > > > implementations of these helpers. > > > > > > > > > > check_zeroed_user() is not in bpf-next. > > > > > we will let this set sit in patchworks for some time until bpf-ne= xt > > > > > is merged back into net-next and we fast forward it. > > > > > Then we can apply it (assuming no conflicts). > > > > > > > > Sounds good to me. Just ping me when you need me to resend rebase o= nto > > > > bpf-next. > > > > > > -rc1 is now in bpf-next. > > > I took a look at patches and they look good overall. > > > > > > In patches 2 and 3 the zero init via "=3D {};" > > > should be unnecessary anymore due to > > > copy_struct_from_user() logic, right? > > > > Right, I can remove them. > > > > > > > > Could you also convert all other case in kernel/bpf/, > > > so bpf_check_uarg_tail_zero() can be removed ? > > > Otherwise the half-way conversion will look odd. > > > > Hm, I thought I did that and concluded that bpf_check_uarg_tail_zero() > > can't be removed because sometimes it is called to verify whether a > > given struct is zeroed but nothing is actually copied from userspace bu= t > > rather to userspace. See for example > > v5.4-rc3:kernel/bpf/syscall.c:bpf_map_get_info_by_fd() > > All call sites where something is actually copied from userspace I've > > switched to copy_struct_from_user(). >=20 > I see. You're right. > Could you update the comment in bpf_check_uarg_tail_zero() > to clarify that copy_struct_from_user() should be used whenever > possible instead ? Yup, can do. Christian