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=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 E8B92ECE59D for ; Wed, 16 Oct 2019 03:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA48A20663 for ; Wed, 16 Oct 2019 03:31:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391015AbfJPDbU (ORCPT ); Tue, 15 Oct 2019 23:31:20 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:55449 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730211AbfJPDbU (ORCPT ); Tue, 15 Oct 2019 23:31:20 -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 1iKa1t-0008BG-Fb; Wed, 16 Oct 2019 03:31:17 +0000 Date: Wed, 16 Oct 2019 05:31:16 +0200 From: Christian Brauner To: Alexei Starovoitov Cc: Alexei Starovoitov , bpf , Daniel Borkmann , Martin KaFai Lau , LKML , Network Development , Song Liu , Yonghong Song Subject: Re: [PATCH v2 0/3] bpf: switch to new usercopy helpers Message-ID: <20191016033115.ljwiae2cfltbdoyo@wittgenstein> References: <20191009160907.10981-1-christian.brauner@ubuntu.com> <20191016004138.24845-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Oct 15, 2019 at 07:14:42PM -0700, Alexei Starovoitov wrote: > On Tue, Oct 15, 2019 at 5:41 PM 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. > > Was it tested? > Either your conversion is incorrect or that generic helper is broken. > ./test_progs -n 2 > and > ./test_btf > are catching the bug: > BTF prog info raw test[8] (line_info (No subprog. zero tailing > line_info): do_test_info_raw:6205:FAIL prog_fd:-1 > expected_prog_load_failure:0 errno:7 > nonzero tailing record in line_infoprocessed 0 insns (limit 1000000) > max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 Ugh, I misrememberd what the helper I helped design returns. The fix is: diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 5db9887a8f4c..0920593eacd0 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -78,11 +78,8 @@ int bpf_check_uarg_tail_zero(void __user *uaddr, return 0; err = check_zeroed_user(uaddr + expected_size, rest); - if (err < 0) - return err; - - if (err) - return -E2BIG; + if (err <= 0) + return err ?: -E2BIG; return 0; } aka check_zeroed_user() returns 0 if non-zero bytes are present, 1 if no non-zero bytes were present, and -errno on error. I'll send a fixed version. The tests pass for me with this. Christian