Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6917617ybp; Wed, 16 Oct 2019 00:36:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqy61JE+dmpo2uuvl0gfbp/9XF+QFDk/G8Q8ocKJkIyGdy0yBiznTpiP/Pq07qnwpVSt//gr X-Received: by 2002:aa7:d905:: with SMTP id a5mr37589266edr.88.1571211404258; Wed, 16 Oct 2019 00:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211404; cv=none; d=google.com; s=arc-20160816; b=P/6PUDTXK5bIpNpfy4/4N603CJrJ/YVhZNK/QV+QtEML7Q7NMJxp3bK+3YrvXmEVlh 7yiGijZFEzONRgyKyJyZkkOYI5tRzZ007sAPjz80P2X95naJV5bNRHf0LHXHw8sJw1xg H4cWPUbT3CA+ytwr/CjFqs7hyugkfeJUtroPul+Ne913wpwGytpuQMc+pUXxXgAzq+/1 UVBa6W80ekw1Ix+4w0IUnEHSnDYBe5C8XlMj34CrVcpANWm+PA7pnH1T+NmVe7Oj1Q6S hrXOeGo3mBN2svPDpAs0tYGUcs13jtJucJsB5qtimun3/orcXMTzf+Z/0jJtT9mziHl9 Y+4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Hcb/bZQTaR5GnCi6JvfQ7lb1sQENu+NNpWafTLnRSQE=; b=yUVm5RhO0Sb/CTuHKZ56QqraZJV1syuem/HDujxeyAnES16D5eEpxDdRPlX1B5CUZL ctDATmt2w1T40bwWHyrMG1MtnHAKVzrV/6RuF0OMtNIQ7L61ccu3RylfRLD30URN1AQY C7Zi9xLz4i5HdOMqY1ZIwUz2f6FCwyin2fRXwpSvGkc5YbymPGvf6661lVJsz5gFohK+ xAE7r/oDbWqkpCTV82N1Mmztw6Mg2VpWsUxq7ZEj7oRQxXpHFv/x+iRxMoChuojQ1wEg y00OfxGx4buInBTYopkhxviDihoKKkQjYcC7cil0aeXWl6xOPFaHkioJ3PabubpGKrUf qD9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cuws7SfH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h15si14261320ejx.211.2019.10.16.00.36.20; Wed, 16 Oct 2019 00:36:44 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cuws7SfH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390175AbfJOXCl (ORCPT + 99 others); Tue, 15 Oct 2019 19:02:41 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33985 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730039AbfJOXCk (ORCPT ); Tue, 15 Oct 2019 19:02:40 -0400 Received: by mail-lj1-f196.google.com with SMTP id j19so21985536lja.1; Tue, 15 Oct 2019 16:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hcb/bZQTaR5GnCi6JvfQ7lb1sQENu+NNpWafTLnRSQE=; b=cuws7SfHUs6NGC2DyQ0NTemOvuVWfyGdTaV8cBd2c9Gkke7u3z2XoQzytH8/oL63vN KE1M8bZgCdsDHArOkWAsrhrMwEgkQKzOjJqfj3FUBXAxgnOiguVtajMrDDTVVYdtki6V NSEtAVdfwML+cLm0WWyhwGwZGBoxiSuefLWh/yvP/Y1/sR340i5OrrikccJII0QUl+CE EUqtRCKWMDiyubvy1o7kQHzhU1BFo8jQwqKmZyJU77ASBUyY4DyRCjNUl+lKjrS+IAli wxOlkAx+qmzph12NY2OEctKJWjn7UZmrH0ID8ZszyEySEAJK0JPAlFwVTsL5IfZlzTAb 3uIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Hcb/bZQTaR5GnCi6JvfQ7lb1sQENu+NNpWafTLnRSQE=; b=qj5s2qu78M0LHKy/RDEtgyB+nOd7HK2E1FpDlUsZOeLlC7CuSUDV/xf0IiFMwbeLpe csDOUm6XiQHNSPyyccSfX8ADDM/XwuCq02fBMPaoPsq0riRjYBV8fcMkf14RMvKPQZtz GGfnS1xhTveHzqluvruwk3QSy9kabjjCk7PpORdtX8qC1357nvuhRMJsD0IP0sXiyK+3 f9T62F8M9goRi/9xsXUvuqFh8XqqIse04ferq6Q22soTdeq33wee11zlSJ1tWdD3PUnb 03EdFOmSME3C6vDVX++OeUqlCGirpd0Tkev3mquI8ehMpZNaf+IFidlzd6IiYKd+EJvN AeHw== X-Gm-Message-State: APjAAAVykpHmt4ly2fbaG4zlvUAQf+AhHvSjN3VwMqBJTIB7FyMYNXFE KTlCOJhr97oMPfqA2WgEnTH4esSwdPJMiLuvPHI= X-Received: by 2002:a2e:9b12:: with SMTP id u18mr24575859lji.142.1571180558099; Tue, 15 Oct 2019 16:02:38 -0700 (PDT) MIME-Version: 1.0 References: <20191009160907.10981-1-christian.brauner@ubuntu.com> <20191010092647.cpxh7neqgabq36gt@wittgenstein> <20191015225555.jprg5xmnbg45os3y@wittgenstein> In-Reply-To: <20191015225555.jprg5xmnbg45os3y@wittgenstein> From: Alexei Starovoitov Date: Tue, 15 Oct 2019 16:02:25 -0700 Message-ID: Subject: Re: [PATCH 0/3] bpf: switch to new usercopy helpers To: Christian Brauner Cc: Alexei Starovoitov , Daniel Borkmann , bpf , Martin KaFai Lau , Song Liu , Yonghong Song , Network Development , LKML Content-Type: text/plain; charset="UTF-8" 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 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 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(). 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 ?