From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3292ECE59D for ; Tue, 15 Oct 2019 23:08:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD6B92064A for ; Tue, 15 Oct 2019 23:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727832AbfJOXIv (ORCPT ); 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: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@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