Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6918933ybp; Wed, 16 Oct 2019 00:38:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8FYRSPUFQ2reLqC+uG+GW+Mu81APj1KLOwKClYqk4TFcIJn0LwT/NTAhD87q//54hmy9Y X-Received: by 2002:aa7:db43:: with SMTP id n3mr37815980edt.176.1571211496849; Wed, 16 Oct 2019 00:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211496; cv=none; d=google.com; s=arc-20160816; b=eZskqPfY78LinFTda/yrN9h4Wu8lX0L3qTR8ReFyXuJ9ihoDv63L9RU94ZHXQW1yWc gEiuyVcHjBj5BFu89Bgx7rlrsZuOnSRhM87gTEh/X+uoyS2ITgmmchK4VOvkqKc2LFDP ybGIBPA2b5dmYwDkCv52Qjo2Vlj+rSZ9okKKL+jdVRqWDQL8zRq+y1XKlJqgk9Jv8BXL 9Cmn9KEjyToUek8CG3Y965pszMVCf90Biwghj2aWmGrBjuKH8AlfbaGKgSVW12nNTNBp rmAACqzXETfuSX/B51Z8vqxLecJcjbpuxuvE2WL7ErMM2RY0iry0DsLrd4kZxQ4NMPnN b5Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=j0EOUYOD4okmKjT7OAHgb6kZmmcoiRLzoTdP7dzKoWQ=; b=04Q+Rs0IeAqbV/HEK8BCjperD+ETIAuKz777Pn0kNPo/M2qS5RvU+vHiMDRbIoX3G0 RSMKEiwwE2P0XYJ/za1e4+n+cqqDcMdv+d2NH3eoAf+nyE71Lviw9WqzCZkHTsvFy7HA 0XIKACIUon1MwfrNP9uPv5+xrmVZZwNwjuzQCGJ2L+wCHtu6Ec1d0qI5ni8+6B7CZv69 x1QZ3I0cNa2DPzKifZNNp3hi+VpgKlFEpK68S0ruUteyqI38A689lwX5+69+pizyDAFR tt7jD7cAynPWjJc0kxi21d8a4CU6KcvFdLCuNEjE/4n35IvtNyINxQsrEjQZGcEf6nvc IizQ== 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 k6si15327204ejs.354.2019.10.16.00.37.52; Wed, 16 Oct 2019 00:38:16 -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 S2390159AbfJOW4C (ORCPT + 99 others); Tue, 15 Oct 2019 18:56:02 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:51766 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728043AbfJOW4B (ORCPT ); Tue, 15 Oct 2019 18:56:01 -0400 Received: from [213.220.153.21] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iKVjR-00084E-U9; Tue, 15 Oct 2019 22:55:57 +0000 Date: Wed, 16 Oct 2019 00:55:57 +0200 From: Christian Brauner To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , bpf , Martin KaFai Lau , Song Liu , Yonghong Song , Network Development , LKML Subject: Re: [PATCH 0/3] bpf: switch to new usercopy helpers Message-ID: <20191015225555.jprg5xmnbg45os3y@wittgenstein> References: <20191009160907.10981-1-christian.brauner@ubuntu.com> <20191010092647.cpxh7neqgabq36gt@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 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 have 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(), perf_event_open(), > > > > and clone3(). More importantly it will also help to ensure that users > > > > implementing versioning-by-size end up with the same core semantics. > > > > > > > > This point is especially crucial since we have at least one case where > > > > versioning-by-size is used but with slighly different semantics: > > > > sched_setattr(), perf_event_open(), and clone3() all do do similar > > > > checks to copy_struct_from_user() while rt_sigprocmask(2) always rejects > > > > differently-sized struct arguments. > > > > > > > > This little series switches over bpf codepaths that have hand-rolled > > > > 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-next > > > 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 onto > > 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 "= {};" > 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 but 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(). Christian